SOLR-13072: Use the same wait in other simulated tests where the same race condition may occur.

This commit is contained in:
Andrzej Bialecki 2019-01-08 19:12:38 +01:00
parent a37e2c609c
commit 7db4121b45
6 changed files with 34 additions and 12 deletions

View File

@ -21,14 +21,17 @@ import java.lang.invoke.MethodHandles;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.cloud.autoscaling.AutoScalingConfig;
import org.apache.solr.cloud.CloudTestUtils; import org.apache.solr.cloud.CloudTestUtils;
import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.util.TimeSource; import org.apache.solr.common.util.TimeSource;
import org.apache.solr.util.TimeOut;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -63,6 +66,18 @@ public class SimSolrCloudTestCase extends SolrTestCaseJ4 {
cluster = null; 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 @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();

View File

@ -100,6 +100,7 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase {
rsp = cluster.request(req); rsp = cluster.request(req);
response = rsp.getResponse(); response = rsp.getResponse();
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
cluster.getTimeSource().sleep(TimeUnit.SECONDS.toMillis(ScheduledTriggers.DEFAULT_COOLDOWN_PERIOD_SECONDS)); cluster.getTimeSource().sleep(TimeUnit.SECONDS.toMillis(ScheduledTriggers.DEFAULT_COOLDOWN_PERIOD_SECONDS));
} }
@ -138,6 +139,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase {
NamedList<Object> response = solrClient.request(req); NamedList<Object> response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeLost", CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeLost",
"conf",1, 2); "conf",1, 2);
create.process(solrClient); create.process(solrClient);
@ -201,6 +204,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase {
NamedList<Object> response = solrClient.request(req); NamedList<Object> response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeWithMultipleReplicasLost", CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeWithMultipleReplicasLost",
"conf",2, 3); "conf",2, 3);
create.setMaxShardsPerNode(2); create.setMaxShardsPerNode(2);
@ -285,6 +290,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase {
response = solrClient.request(req); response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeAdded", CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("testNodeAdded",
"conf",1, 4).setMaxShardsPerNode(-1); "conf",1, 4).setMaxShardsPerNode(-1);
create.process(solrClient); create.process(solrClient);
@ -304,6 +311,8 @@ public class TestSimComputePlanAction extends SimSolrCloudTestCase {
response = solrClient.request(req); response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
// start a node so that the 'violation' created by the previous policy update is fixed // start a node so that the 'violation' created by the previous policy update is fixed
String newNode = cluster.simAddNode(); String newNode = cluster.simAddNode();
assertTrue("Trigger was not fired even after 5 seconds", triggerFiredLatch.await(5, TimeUnit.SECONDS)); assertTrue("Trigger was not fired even after 5 seconds", triggerFiredLatch.await(5, TimeUnit.SECONDS));

View File

@ -173,6 +173,8 @@ public class TestSimExecutePlanAction extends SimSolrCloudTestCase {
NamedList<Object> response = solrClient.request(req); NamedList<Object> response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
String collectionName = "testIntegration"; String collectionName = "testIntegration";
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName,
"conf", 1, 2); "conf", 1, 2);

View File

@ -120,6 +120,8 @@ public class TestSimExtremeIndexing extends SimSolrCloudTestCase {
NamedList<Object> response = solrClient.request(req); NamedList<Object> response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
long batchSize = BATCH_SIZE; long batchSize = BATCH_SIZE;
for (long i = 0; i < NUM_BATCHES; i++) { for (long i = 0; i < NUM_BATCHES; i++) {
addDocs(collectionName, i * batchSize, batchSize); addDocs(collectionName, i * batchSize, batchSize);

View File

@ -174,6 +174,8 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase {
response = solrClient.request(req); response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
cluster.getTimeSource().sleep(5000); cluster.getTimeSource().sleep(5000);
// pick a few random nodes // pick a few random nodes
@ -269,6 +271,8 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase {
NamedList<Object> response = solrClient.request(req); NamedList<Object> response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
// create a collection with more than 1 replica per node // create a collection with more than 1 replica per node
String collectionName = "testNodeAdded"; String collectionName = "testNodeAdded";
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName,
@ -472,6 +476,7 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase {
response = solrClient.request(req); response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
// create a collection with 1 replica per node // create a collection with 1 replica per node
String collectionName = "testNodeLost"; String collectionName = "testNodeLost";
@ -671,6 +676,7 @@ public class TestSimLargeCluster extends SimSolrCloudTestCase {
response = solrClient.request(req); response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success"); assertEquals(response.get("result").toString(), "success");
assertAutoscalingUpdateComplete();
boolean await = triggerFinishedLatch.await(waitForSeconds * 45000 / SPEED, TimeUnit.MILLISECONDS); boolean await = triggerFinishedLatch.await(waitForSeconds * 45000 / SPEED, TimeUnit.MILLISECONDS);
assertTrue("The trigger did not fire at all", await); assertTrue("The trigger did not fire at all", await);

View File

@ -1424,16 +1424,4 @@ public class TestSimTriggerIntegration extends SimSolrCloudTestCase {
return event; 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);
}
});
}
} }