diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimSolrCloudTestCase.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimSolrCloudTestCase.java index 49a7bbddaf3..6cb3f1a1577 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimSolrCloudTestCase.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimSolrCloudTestCase.java @@ -21,14 +21,17 @@ import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.function.Predicate; import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.client.solrj.cloud.autoscaling.AutoScalingConfig; import org.apache.solr.cloud.CloudTestUtils; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.util.TimeSource; +import org.apache.solr.util.TimeOut; import org.junit.AfterClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,6 +66,18 @@ public class SimSolrCloudTestCase extends SolrTestCaseJ4 { cluster = null; } + protected static void assertAutoscalingUpdateComplete() throws Exception { + (new TimeOut(30, TimeUnit.SECONDS, cluster.getTimeSource())) + .waitFor("OverseerTriggerThread never caught up to the latest znodeVersion", () -> { + try { + AutoScalingConfig autoscalingConfig = cluster.getDistribStateManager().getAutoScalingConfig(); + return autoscalingConfig.getZkVersion() == cluster.getOverseerTriggerThread().getProcessedZnodeVersion(); + } catch (Exception e) { + throw new RuntimeException("FAILED", e); + } + }); + } + @Override public void tearDown() throws Exception { super.tearDown(); diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimComputePlanAction.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimComputePlanAction.java index f82c5fe9894..19f9b8d95d6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimComputePlanAction.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimComputePlanAction.java @@ -100,6 +100,7 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase { rsp = cluster.request(req); response = rsp.getResponse(); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); cluster.getTimeSource().sleep(TimeUnit.SECONDS.toMillis(ScheduledTriggers.DEFAULT_COOLDOWN_PERIOD_SECONDS)); } @@ -138,6 +139,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase { NamedList response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeLost", "conf",1, 2); create.process(solrClient); @@ -201,6 +204,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase { NamedList response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeWithMultipleReplicasLost", "conf",2, 3); create.setMaxShardsPerNode(2); @@ -285,6 +290,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase { response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeAdded", "conf",1, 4).setMaxShardsPerNode(-1); create.process(solrClient); @@ -304,6 +311,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase { response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + // start a node so that the 'violation' created by the previous policy update is fixed String newNode = cluster.simAddNode(); assertTrue("Trigger was not fired even after 5 seconds", triggerFiredLatch.await(5, TimeUnit.SECONDS)); diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExecutePlanAction.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExecutePlanAction.java index e42510cd234..a0c18a9e574 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExecutePlanAction.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExecutePlanAction.java @@ -173,6 +173,8 @@ public class TestSimExecutePlanAction extends SimSolrCloudTestCase { NamedList response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + String collectionName = "testIntegration"; CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf", 1, 2); diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExtremeIndexing.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExtremeIndexing.java index 3c996a199fc..56cfdf6e6c0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExtremeIndexing.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimExtremeIndexing.java @@ -120,6 +120,8 @@ public class TestSimExtremeIndexing extends SimSolrCloudTestCase { NamedList response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + long batchSize = BATCH_SIZE; for (long i = 0; i < NUM_BATCHES; i++) { addDocs(collectionName, i * batchSize, batchSize); diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimLargeCluster.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimLargeCluster.java index 7834c70d65b..fed7b1430e5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimLargeCluster.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimLargeCluster.java @@ -174,6 +174,8 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase { response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + cluster.getTimeSource().sleep(5000); // pick a few random nodes @@ -269,6 +271,8 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase { NamedList response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); + // create a collection with more than 1 replica per node String collectionName = "testNodeAdded"; CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, @@ -472,6 +476,7 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase { response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); // create a collection with 1 replica per node String collectionName = "testNodeLost"; @@ -671,6 +676,7 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase { response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); + assertAutoscalingUpdateComplete(); boolean await = triggerFinishedLatch.await(waitForSeconds * 45000 / SPEED, TimeUnit.MILLISECONDS); assertTrue("The trigger did not fire at all", await); diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimTriggerIntegration.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimTriggerIntegration.java index 711b333485e..3056d338843 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimTriggerIntegration.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimTriggerIntegration.java @@ -1424,16 +1424,4 @@ public class TestSimTriggerIntegration extends SimSolrCloudTestCase { return event; } - private static void assertAutoscalingUpdateComplete() throws Exception { - (new TimeOut(30, TimeUnit.SECONDS, cluster.getTimeSource())) - .waitFor("OverseerTriggerThread never caught up to the latest znodeVersion", () -> { - try { - AutoScalingConfig autoscalingConfig = cluster.getDistribStateManager().getAutoScalingConfig(); - return autoscalingConfig.getZkVersion() == cluster.getOverseerTriggerThread().getProcessedZnodeVersion(); - } catch (Exception e) { - throw new RuntimeException("FAILED", e); - } - }); - } - }