瀏覽代碼

Adds a preserveIndicesUponCompletion method to ESRestTestCase
that can be overridden by subclasses if the test must not
delete indices it created after exiting.

Ali Beyad 9 年之前
父節點
當前提交
98230d035a

+ 1 - 2
buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

@@ -46,7 +46,7 @@ class ClusterFormationTasks {
     /**
      * Adds dependent tasks to the given task to start and stop a cluster with the given configuration.
      *
-     * Returns a NodeInfo object for the first node in the cluster.
+     * Returns a list of NodeInfo objects for each node in the cluster.
      */
     static List<NodeInfo> setup(Project project, Task task, ClusterConfiguration config) {
         if (task.getEnabled() == false) {
@@ -102,7 +102,6 @@ class ClusterFormationTasks {
         Task wait = configureWaitTask("${task.name}#wait", project, nodes, startTasks)
         task.dependsOn(wait)
 
-        // delay the resolution of the uri by wrapping in a closure, so it is not used until read for tests
         return nodes
     }
 

+ 0 - 2
qa/rolling-upgrade/build.gradle

@@ -35,7 +35,6 @@ task oldClusterTest(type: RestIntegTestTask) {
     clusterName = 'rolling-upgrade'
   }
   systemProperty 'tests.rest.suite', 'old_cluster'
-  systemProperty 'tests.rest.preserve_indices', 'true'
 }
 
 task mixedClusterTest(type: RestIntegTestTask) {
@@ -47,7 +46,6 @@ task mixedClusterTest(type: RestIntegTestTask) {
     dataDir = "${-> oldClusterTest.nodes[1].dataDir}"
   }
   systemProperty 'tests.rest.suite', 'mixed_cluster'
-  systemProperty 'tests.rest.preserve_indices', 'true'
   finalizedBy 'oldClusterTest#node0.stop'
 }
 

+ 5 - 0
qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java

@@ -31,6 +31,11 @@ import java.io.IOException;
 @TimeoutSuite(millis = 40 * TimeUnits.MINUTE) // some of the windows test VMs are slow as hell
 public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
 
+    @Override
+    protected boolean preserveIndicesUponCompletion() {
+        return true;
+    }
+
     public UpgradeClusterClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) {
         super(testCandidate);
     }

+ 13 - 2
test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

@@ -114,6 +114,7 @@ public class ESRestTestCase extends ESTestCase {
         }
     }
 
+
     /**
      * Clean up after the test case.
      */
@@ -138,9 +139,19 @@ public class ESRestTestCase extends ESTestCase {
         return adminClient;
     }
 
+    /**
+     * Returns whether to preserve the indices created during this test on completion of this test.
+     * Defaults to {@code false}. Override this method if indices should be preserved after the test,
+     * with the assumption that some other process or test will clean up the indices afterward.
+     * This is useful if the data directory and indices need to be preserved between test runs
+     * (for example, when testing rolling upgrades).
+     */
+    protected boolean preserveIndicesUponCompletion() {
+        return false;
+    }
+
     private void wipeCluster() throws IOException {
-        final boolean preserveIndices = Boolean.parseBoolean(System.getProperty("tests.rest.preserve_indices"));
-        if (preserveIndices == false) {
+        if (preserveIndicesUponCompletion() == false) {
             // wipe indices
             try {
                 adminClient().performRequest("DELETE", "*");