/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'jvm-test-suite'

testing {
    suites {
        integrationTest(JvmTestSuite) {
            testType = TestSuiteType.INTEGRATION_TEST
            useJUnitJupiter()

            dependencies {
                implementation project()

                implementation.bundle libs.bundles.junit
                implementation.bundle libs.bundles.mockito
                implementation.bundle libs.bundles.hamcrest
                implementation.bundle libs.bundles.log4j
                implementation libs.jetbrains.annotations
            }

            sources {
                java {
                    srcDirs = ['src/integrationTest/java']
                }
            }

            targets {
                configureEach {
                    testTask.configure {
                        shouldRunAfter(test)
                        jvmArgs "-XX:+HeapDumpOnOutOfMemoryError", "-XX:MaxDirectMemorySize=256m", "-XX:MaxMetaspaceSize=2g",
                                "-Dio.netty.leakDetectionLevel=paranoid"
                        maxHeapSize = '4g'

                        // Define default test timeouts to avoid everhanging tests.
                        systemProperty 'junit.jupiter.execution.timeout.testable.method.default', '10m'
                        systemProperty 'junit.jupiter.execution.timeout.lifecycle.method.default', '60s'

                        // Enable auto-detection of JUnit 5 extensions to automatically apply DumpThreadsOnTimeout extension.
                        systemProperty 'junit.jupiter.extensions.autodetection.enabled', true

                        systemProperty 'jraft.available_processors', 4
                    }
                }
            }
        }
    }
}

check {
    dependsOn integrationTest
}

pmdIntegrationTest {
    enabled = false
}

spotbugsIntegrationTest {
    enabled(false)
}
