| import org.apache.geode.gradle.TestPropertiesWriter |
| import org.apache.geode.gradle.RepeatTest |
| import org.apache.geode.gradle.plugins.DependencyConstraints |
| import org.apache.geode.gradle.RunInSubdirectoryTestFramework |
| |
| /* |
| * 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. |
| */ |
| |
| // This configuration might be safely removed once the CategoryWithParameterizedRunnerFactory |
| // and associated classes are themselves removed, per GEODE-5606 |
| configurations { |
| apt |
| } |
| |
| compileTestJava { |
| options.annotationProcessorPath = files(configurations['apt']) |
| } |
| |
| test { |
| doFirst { |
| TestPropertiesWriter.writeTestProperties(buildDir, name) |
| } |
| if (project.hasProperty('testMaxParallelForks')) { |
| maxParallelForks = Integer.parseUnsignedInt(project.testMaxParallelForks) |
| } else { |
| maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 |
| } |
| } |
| |
| apply plugin: 'nebula.facet' |
| facets { |
| integrationTest { |
| includeInCheckLifecycle = false |
| } |
| distributedTest { |
| includeInCheckLifecycle = false |
| } |
| performanceTest { |
| includeInCheckLifecycle = false |
| } |
| acceptanceTest { |
| includeInCheckLifecycle = false |
| } |
| uiTest { |
| includeInCheckLifecycle = false |
| } |
| upgradeTest { |
| includeInCheckLifecycle = false |
| } |
| } |
| |
| dependencies { |
| // Do not add dependencies here that are not part of a custom configuration. |
| // Dependencies should be explicit in the relevant build.gradle files to keep our modules |
| // as decoupled as possible. |
| |
| // This 'apt' configuration to be removed by GEODE-5606. |
| apt files("${rootProject.projectDir}/buildSrc/build/libs/buildSrc.jar") |
| apt('junit:junit:' + DependencyConstraints.get('junit.version')) { |
| transitive = false |
| } |
| |
| testRuntime('cglib:cglib:' + DependencyConstraints.get('cglib.version')) { |
| exclude module: 'org.apache.ant' |
| } |
| } |
| |
| configure([integrationTest, distributedTest, performanceTest, acceptanceTest, uiTest, |
| upgradeTest]) { |
| forkEvery 1 |
| |
| doFirst { |
| TestPropertiesWriter.writeTestProperties(buildDir, name) |
| } |
| outputs.upToDateWhen { false } |
| } |
| |
| configure([integrationTest, distributedTest, performanceTest]) { |
| useJUnit { |
| if (project.hasProperty("testCategory")) { |
| includeCategories += project.testCategory |
| } |
| } |
| } |
| |
| if (project.hasProperty("forceTest")) { |
| // All test facets already force rerun. Only :test can be upToDate. |
| test { |
| outputs.upToDateWhen { false } |
| } |
| } |
| |
| task repeatDistributedTest(type: RepeatTest) { |
| dependsOn { distributedTest.taskDependencies } |
| classpath = project.sourceSets.distributedTest.runtimeClasspath |
| testClassesDirs = project.sourceSets.distributedTest.output.classesDirs |
| } |
| |
| task repeatIntegrationTest(type: RepeatTest) { |
| dependsOn { integrationTest.taskDependencies } |
| classpath = project.sourceSets.integrationTest.runtimeClasspath |
| testClassesDirs = project.sourceSets.integrationTest.output.classesDirs |
| } |
| |
| task repeatAcceptanceTest(type: RepeatTest) { |
| dependsOn { acceptanceTest.taskDependencies } |
| classpath = project.sourceSets.acceptanceTest.runtimeClasspath |
| testClassesDirs = project.sourceSets.acceptanceTest.output.classesDirs |
| } |
| |
| task repeatUpgradeTest(type: RepeatTest) { |
| dependsOn { upgradeTest.taskDependencies } |
| classpath = project.sourceSets.upgradeTest.runtimeClasspath |
| testClassesDirs = project.sourceSets.upgradeTest.output.classesDirs |
| } |
| |
| task repeatUnitTest(type: RepeatTest) { |
| dependsOn { test.taskDependencies } |
| // default classpath works for this one. |
| } |
| |
| configure([integrationTest, distributedTest, performanceTest, acceptanceTest, uiTest, upgradeTest]) { |
| if (project.hasProperty('excludeTest')) { |
| exclude project.getProperty('excludeTest').split(',') |
| } |
| } |
| |
| configure([acceptanceTest, distributedTest, integrationTest, uiTest, upgradeTest, repeatAcceptanceTest, repeatDistributedTest, repeatIntegrationTest, repeatUnitTest, repeatUpgradeTest]) { |
| doFirst { |
| // Wrap the task's test framework in a wrapper that runs each test worker JVM in a unique |
| // subdirectory. |
| def subdirFramework = new RunInSubdirectoryTestFramework(testFramework) |
| // This call works for now, but the Test class declares useTestFramework() as protected, so |
| // this could become troublesome in a future version of Gradle/Groovy. |
| useTestFramework subdirFramework |
| } |
| } |
| |
| configure([repeatDistributedTest, repeatIntegrationTest, repeatUpgradeTest, repeatUnitTest, repeatAcceptanceTest]) { |
| times = Integer.parseInt(repeat) |
| useJUnit {} |
| outputs.upToDateWhen { false } |
| |
| if (project.hasProperty("failOnNoMatchingTests")) { |
| filter { |
| setFailOnNoMatchingTests(Boolean.valueOf(project.failOnNoMatchingTests)) |
| } |
| } |
| } |
| |
| // apply common test configuration |
| gradle.taskGraph.whenReady({ graph -> |
| tasks.withType(Test).each { test -> |
| check.dependsOn test |
| test.configure { |
| onlyIf { !Boolean.getBoolean('skip.tests') } |
| |
| def resultsDir = TestPropertiesWriter.testResultsDir(buildDir, test.name) |
| test.workingDir = resultsDir |
| |
| reports.html.destination = file "$buildDir/reports/$name" |
| testLogging { |
| exceptionFormat = 'full' |
| } |
| |
| maxHeapSize '768m' |
| jvmArgs = ['-XX:+HeapDumpOnOutOfMemoryError', '-ea'] |
| if (project.hasProperty('testJVMVer') && testJVMVer.toInteger() >= 9) { |
| jvmArgs += ["--add-opens", "java.xml/jdk.xml.internal=ALL-UNNAMED"] |
| jvmArgs += ["--add-opens", "java.base/jdk.internal.module=ALL-UNNAMED"] |
| jvmArgs += ["--add-opens", "java.base/java.lang.module=ALL-UNNAMED"] |
| } |
| if (project.hasProperty('testJVM') && !testJVM.trim().isEmpty()) { |
| executable = "${testJVM}/bin/java" |
| } |
| |
| def basePort = 'dunit.debug.basePort' |
| if (project.hasProperty(basePort)) { |
| systemProperty basePort, project.getProperties()[basePort] |
| } |
| |
| def suspendVM = 'dunit.debug.suspendVM' |
| if (project.hasProperty(suspendVM)) { |
| systemProperty suspendVM, project.getProperties()[suspendVM] |
| } |
| |
| systemProperty 'gemfire.DEFAULT_MAX_OPLOG_SIZE', '10' |
| systemProperty 'gemfire.disallowMcastDefaults', 'true' |
| systemProperty 'jline.terminal', 'jline.UnsupportedTerminal' |
| def logLevel = System.getProperty('log-level') |
| if (logLevel != null) { |
| systemProperty 'log-level', logLevel |
| } |
| def log4jLocation = System.getProperty('log4j.configurationFile') |
| if (log4jLocation != null) { |
| systemProperty 'log4j.configurationFile', log4jLocation |
| } |
| |
| // The distributed tests seem to need to use /tmp directly, |
| // so exclude them from using the supplied temp directory. |
| if (!test.name.contains("distributed")) { |
| systemProperty 'java.io.tmpdir', System.getProperty('java.io.tmpdir') |
| } |
| |
| def eol = System.getProperty('line.separator') |
| def progress = new File(resultsDir, "$test.name-progress.txt") |
| beforeTest { desc -> |
| def now = new Date().format('yyyy-MM-dd HH:mm:ss.SSS Z') |
| progress << "$now Starting test $desc.className $desc.name$eol" |
| } |
| afterTest { desc, result -> |
| def now = new Date().format('yyyy-MM-dd HH:mm:ss.SSS Z') |
| progress << "$now Completed test $desc.className $desc.name with result: ${result.resultType}$eol" |
| } |
| |
| doFirst { |
| resultsDir.deleteDir() |
| resultsDir.mkdirs() |
| } |
| } |
| } |
| }) |
| |
| acceptanceTest { |
| // Acceptance tests may reach out and run a gfsh command from the assembled gfsh. |
| // If the test JVM version is specified, we must have the correct JAVA_HOME set for gfsh to use. |
| // See also environment configuration for parallel testing in docker.gradle |
| if (project.hasProperty('testJVM') && !testJVM.trim().isEmpty()) { |
| environment "JAVA_HOME", "${project.testJVM}" |
| } |
| } |
| |
| |
| // Make precheckin task run all validation tests for checking in code. |
| task precheckin(dependsOn: [build, acceptanceTest, integrationTest, distributedTest, upgradeTest]) { |
| description 'Run this task before checking in code to validate changes. It runs tests beyond unitTest' |
| } |
| |
| tasks.withType(Test).plus([build, check]).each { |
| it.finalizedBy rootProject.tasks.combineReports |
| rootProject.tasks.combineReports.mustRunAfter it |
| } |
| |
| project.tasks.named('assemble').configure { |
| // This is a semi-lazy hook so that our test sources are compiled most of the time. |
| dependsOn( |
| [ |
| project.tasks.named('compileTestJava'), |
| project.tasks.named('compileIntegrationTestJava'), |
| project.tasks.named('compileDistributedTestJava'), |
| project.tasks.named('compileAcceptanceTestJava'), |
| project.tasks.named('compileUiTestJava'), |
| project.tasks.named('compilePerformanceTestJava'), |
| project.tasks.named('compileUpgradeTestJava'), |
| ] |
| ) |
| } |