Jenkins tests to use testclasslist where possible (like CircleCI) (CASSANDRA-15651)
diff --git a/build-scripts/cassandra-jvm-dtest.sh b/build-scripts/cassandra-jvm-dtest.sh
deleted file mode 100755
index 0b41323..0000000
--- a/build-scripts/cassandra-jvm-dtest.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env bash
-
-set -o xtrace
-set -o errexit
-set -o pipefail
-set -o nounset
-
-# lists all tests for the specific test type
-_list_tests() {
-  local readonly classlistprefix="$1"
-
-  find "test/$classlistprefix" -name '*Test.java' | sed "s;^test/$classlistprefix/;;g"
-}
-
-_list_tests_no_upgrade() {
- _list_tests "distributed" | grep -v "upgrade"
-}
-
-_main() {
-  local java_version
-  java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F. '{print $1}')
-  if [ "$java_version" -ge 11 ]; then
-    export CASSANDRA_USE_JDK11=true
-  fi
-
-  local test_timeout
-  test_timeout=$(grep 'name="test.distributed.timeout"' build.xml | awk -F'"' '{print $4}')
-
-  ant testclasslist -Dtest.timeout="$test_timeout" -Dtest.classlistfile=<( _list_tests_no_upgrade ) -Dtest.classlistprefix=distributed || echo "ant testclasslist failed"
-}
-
-_main "$@"
diff --git a/build-scripts/cassandra-test.sh b/build-scripts/cassandra-test.sh
new file mode 100755
index 0000000..be8e5be
--- /dev/null
+++ b/build-scripts/cassandra-test.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+
+set -o xtrace
+set -o errexit
+set -o pipefail
+set -o nounset
+
+# lists all tests for the specific test type
+_list_tests() {
+  local readonly classlistprefix="$1"
+  find "test/$classlistprefix" -name '*Test.java' | sed "s;^test/$classlistprefix/;;g"
+}
+
+_list_distributed_tests_no_upgrade() {
+  _list_tests "distributed" | grep -v "upgrade"
+}
+
+_timeout_for() {
+  grep "name=\"$1\"" build.xml | awk -F'"' '{print $4}'
+}
+
+_main() {
+  local target="${1:-}"
+  local java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F. '{print $1}')
+  if [ "$java_version" -ge 11 ]; then
+    export CASSANDRA_USE_JDK11=true
+  fi
+
+  ant clean jar
+
+  case $target in
+    "stress-test" | "fqltool-test")
+      ant $target || echo "failed $target"
+      ;;
+    "test")
+      ant testclasslist -Dtest.classlistfile=<( _list_tests "unit" ) || echo "failed $target"
+      ;;
+    "test-cdc")
+      ant testclasslist-cdc -Dtest.classlistfile=<( _list_tests "unit" ) || echo "failed $target"
+      ;;
+    "test-compression")
+      ant testclasslist-compression -Dtest.classlistfile=<( _list_tests "unit" ) || echo "failed $target"
+      ;;
+    "test-burn")
+      ant testclasslist -Dtest.classlistprefix=burn -Dtest.timeout=$(_timeout_for "test.burn.timeout") -Dtest.classlistfile=<( _list_tests "burn" ) || echo "failed $target"
+      ;;
+    "long-test")
+      ant testclasslist -Dtest.classlistprefix=long -Dtest.timeout=$(_timeout_for "test.long.timeout") -Dtest.classlistfile=<( _list_tests "long" ) || echo "failed $target"
+      ;;
+    "jvm-dtest")
+      ant testclasslist -Dtest.classlistprefix=distributed -Dtest.timeout=$(_timeout_for "test.distributed.timeout") -Dtest.classlistfile=<( _list_distributed_tests_no_upgrade ) || echo "failed $target"
+      ;;
+    *)
+      echo "unregconised \"$target\""
+      exit 1
+      ;;
+  esac
+}
+
+_main "$@"
diff --git a/build-scripts/cassandra-unittest.sh b/build-scripts/cassandra-unittest.sh
deleted file mode 100755
index 0c91c26..0000000
--- a/build-scripts/cassandra-unittest.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash -x
-
-################################
-#
-# Prep
-#
-################################
-
-# Pass in target to run, default to `ant test`
-TEST_TARGET="${1:-test}"
-
-################################
-#
-# Main
-#
-################################
-
-# Loop to prevent failure due to maven-ant-tasks not downloading a jar..
-for x in $(seq 1 3); do
-    ant clean jar
-    RETURN="$?"
-    if [ "${RETURN}" -eq "0" ]; then
-        # Run target and exit cleanly for usable "Unstable" status
-        ant "${TEST_TARGET}"
-        exit 0
-    fi
-done
-
-################################
-#
-# Clean
-#
-################################
-
-# If we failed `ant jar` loop
-exit "${RETURN}"
diff --git a/jenkins-dsl/cassandra_job_dsl_seed.groovy b/jenkins-dsl/cassandra_job_dsl_seed.groovy
index 699748e..5ea5846 100644
--- a/jenkins-dsl/cassandra_job_dsl_seed.groovy
+++ b/jenkins-dsl/cassandra_job_dsl_seed.groovy
@@ -41,7 +41,7 @@
     cassandraBranches = "${CASSANDRA_BRANCHES}".split(",")
 }
 // Ant test targets
-def testTargets = ['test', 'test-burn', 'test-cdc', 'test-compression', 'stress-test', 'fqltool-test', 'long-test']
+def testTargets = ['test', 'test-burn', 'test-cdc', 'test-compression', 'stress-test', 'fqltool-test', 'long-test', 'jvm-dtest']
 if(binding.hasVariable("CASSANDRA_ANT_TEST_TARGETS")) {
     testTargets = "${CASSANDRA_ANT_TEST_TARGETS}".split(",")
 }
@@ -367,23 +367,12 @@
                     node / scm / branches / 'hudson.plugins.git.BranchSpec' / name(branchName)
                 }
                 steps {
-                    shell("./cassandra-builds/build-scripts/cassandra-unittest.sh ${targetName}")
+                    shell("./cassandra-builds/build-scripts/cassandra-test.sh ${targetName}")
                 }
             }
         }
     }
 
-     job("${jobNamePrefix}-test-jvm-dtest-forking") {
-        disabled(false)
-        using('Cassandra-template-test')
-        configure { node ->
-            node / scm / branches / 'hudson.plugins.git.BranchSpec' / name(branchName)
-        }
-        steps {
-            shell("./cassandra-builds/build-scripts/cassandra-jvm-dtest.sh")
-        }
-    }
-
     /**
      * Main branch dtest variation jobs
      */
@@ -423,6 +412,7 @@
                 node / scm / branches / 'hudson.plugins.git.BranchSpec' / name(branchName)
             }
             steps {
+                shell("git clean -xdff")
                 shell('./pylib/cassandra-cqlsh-tests.sh $WORKSPACE')
             }
         }
@@ -561,7 +551,7 @@
         steps {
             buildDescription('', buildDescStr)
             shell("git clean -xdff ; git clone -b ${buildsBranch} ${buildsRepo}")
-            shell("./cassandra-builds/build-scripts/cassandra-unittest.sh ${targetName}")
+            shell("./cassandra-builds/build-scripts/cassandra-test.sh ${targetName}")
         }
         publishers {
             archiveArtifacts {
@@ -701,7 +691,6 @@
     steps {
         buildDescription('', buildDescStr)
         shell("git clean -xdff")
-        shell('git clone -b ${DTEST_BRANCH} ${DTEST_REPO}')
         shell('./pylib/cassandra-cqlsh-tests.sh $WORKSPACE')
     }
     publishers {