SQOOP-3408 Introduce a Gradle build parameter to set the default forkEvery value for the tests

(Szabolcs Vasas via Fero Szabo)
diff --git a/COMPILING.txt b/COMPILING.txt
index 0383707..b399ba8 100644
--- a/COMPILING.txt
+++ b/COMPILING.txt
@@ -149,6 +149,18 @@
 * +allTest+: Runs all Sqoop tests.
 
 
+The https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:forkEvery[forkEvery]
+parameter of most of the Gradle test tasks is set to +0+ which means that all of the tests run in a single JVM.
+The only exception is the +kerberizedTest+ task which requires a new JVM for every test class.
+The benefit of this setup is that the test tasks finish much faster since the JVM creation is a slow operation however
+the Sqoop test framework seems to consume/leak too much memory which can lead to an +OutOfMemoryError+ during the build.
+To prevent the JVM running out of memory you can use the +-DforkEvery.default+ property to set the forkEvery
+parameter for all the test tasks except +kerberizedTest+:
+
+----
+./gradlew -DforkEvery.default=30 test
+----
+
 === Third party tests
 
 ==== Installing the necessary databases
diff --git a/build.gradle b/build.gradle
index 954935d..efe980d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -87,6 +87,7 @@
 }
 
 def sqoopThirdPartyLib = System.getProperty("sqoop.thirdparty.lib.dir")
+def forkEveryDefault = Integer.valueOf(System.getProperty("forkEvery.default", "0"))
 
 dependencies {
     if (sqoopThirdPartyLib != null) runtime fileTree(dir: sqoopThirdPartyLib, include: '*.jar')
@@ -171,20 +172,6 @@
     }
 }
 
-task kerberizedTest (type: Test){
-    description 'Run Kerberized Test'
-    // A Gradle test task with forkEvery 1 and includeCategories performs poorly because it starts a new JVM even for the filtered tests.
-    // To work around this performance problem we need to add every kerberized test in a separate include field here.
-    include '**/TestKerberosAuthenticator*'
-    include '**/HBaseKerberizedConnectivityTest*'
-    include '**/TestHiveMiniCluster*'
-    include '**/TestHiveServer2TextImport*'
-    useJUnit {
-        includeCategories 'org.apache.sqoop.testcategories.KerberizedTest'
-    }
-    forkEvery 1
-}
-
 task thirdPartyTest (type: Test) {
     description 'Run Third-party Tests - you need to specify -Dsqoop.thirdparty.lib.dir where the Third party driver ' +
             'jars reside (relative to the project directory)'
@@ -210,7 +197,6 @@
         excludeCategories 'org.apache.sqoop.testcategories.sqooptest.ManualTest'
     }
 }
-test.finalizedBy(kerberizedTest)
 
 task s3Test(type: Test) {
     description 'Run S3 tests'
@@ -229,7 +215,6 @@
         excludeCategories 'org.apache.sqoop.testcategories.sqooptest.ManualTest'
     }
 }
-allTest.finalizedBy(kerberizedTest)
 
 def testBuildDir = "$buildDir/test/"
 def testBuildDirData ="$testBuildDir/data/"
@@ -265,8 +250,27 @@
     jacoco{
         excludes = ["**/SqoopVersion*"]
     }
+
+    forkEvery forkEveryDefault
 }
 
+task kerberizedTest (type: Test){
+    description 'Run Kerberized Test'
+    // A Gradle test task with forkEvery 1 and includeCategories performs poorly because it starts a new JVM even for the filtered tests.
+    // To work around this performance problem we need to add every kerberized test in a separate include field here.
+    include '**/TestKerberosAuthenticator*'
+    include '**/HBaseKerberizedConnectivityTest*'
+    include '**/TestHiveMiniCluster*'
+    include '**/TestHiveServer2TextImport*'
+    useJUnit {
+        includeCategories 'org.apache.sqoop.testcategories.KerberizedTest'
+    }
+    forkEvery 1
+}
+
+test.finalizedBy(kerberizedTest)
+allTest.finalizedBy(kerberizedTest)
+
 tasks.withType(Checkstyle) {
     reports {
         xml.enabled false