SOLR-11201: Fix bad assumptions made in testMetricTrigger

This commit is contained in:
Shalin Shekhar Mangar 2018-02-26 22:22:02 +05:30
parent a2eb7f3880
commit e08eac421a
1 changed files with 17 additions and 16 deletions

View File

@ -1509,20 +1509,16 @@ public class TriggerIntegrationTest extends SolrCloudTestCase {
@Test
public void testMetricTrigger() throws Exception {
// at least 3 nodes
for (int i = cluster.getJettySolrRunners().size(); i < 3; i++) {
cluster.startJettySolrRunner();
}
cluster.waitForAllNodes(5);
String collectionName = "testMetricTrigger";
CloudSolrClient solrClient = cluster.getSolrClient();
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName,
"conf", 2, 1);
"conf", 2, 2).setMaxShardsPerNode(2);
create.process(solrClient);
solrClient.setDefaultCollection(collectionName);
waitForState("Timed out waiting for collection:" + collectionName + " to become active", collectionName, clusterShape(2, 1));
waitForState("Timed out waiting for collection:" + collectionName + " to become active", collectionName, clusterShape(2, 2));
DocCollection docCollection = solrClient.getZkStateReader().getClusterState().getCollection(collectionName);
String shardId = "shard1";
@ -1567,9 +1563,17 @@ public class TriggerIntegrationTest extends SolrCloudTestCase {
response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success");
for (int i = 0; i < 500; i++) {
solrClient.add(new SolrInputDocument("id", String.valueOf(i), "x_s", "x" + i));
// start more nodes so that we have at least 4
for (int i = cluster.getJettySolrRunners().size(); i < 4; i++) {
cluster.startJettySolrRunner();
}
cluster.waitForAllNodes(10);
List<SolrInputDocument> docs = new ArrayList<>(500);
for (int i = 0; i < 500; i++) {
docs.add(new SolrInputDocument("id", String.valueOf(i), "x_s", "x" + i));
}
solrClient.add(docs);
solrClient.commit();
boolean await = triggerFiredLatch.await(20, TimeUnit.SECONDS);
@ -1583,18 +1587,17 @@ public class TriggerIntegrationTest extends SolrCloudTestCase {
assertTrue(TimeUnit.SECONDS.convert(waitForSeconds, TimeUnit.NANOSECONDS) - WAIT_FOR_DELTA_NANOS <= now - ev.event.getEventTime());
assertEquals(collectionName, ev.event.getProperties().get("collection"));
String oldReplicaName = replica.getName();
docCollection = solrClient.getZkStateReader().getClusterState().getCollection(collectionName);
assertEquals(2, docCollection.getReplicas().size());
assertNull(docCollection.getReplica(oldReplicaName));
// find a new replica and create its metric name
docCollection = solrClient.getZkStateReader().getClusterState().getCollection(collectionName);
replica = docCollection.getSlice(shardId).getReplicas().iterator().next();
coreName = replica.getCoreName();
replicaName = Utils.parseMetricsReplicaName(collectionName, coreName);
registry = SolrCoreMetricManager.createRegistryName(true, collectionName, shardId, replicaName, null);
tag = "metrics:" + registry + ":INDEX.sizeInBytes";
triggerFiredLatch = new CountDownLatch(1);
listenerEvents.clear();
setTriggerCommand = "{" +
"'set-trigger' : {" +
"'name' : 'metric_trigger'," +
@ -1616,8 +1619,6 @@ public class TriggerIntegrationTest extends SolrCloudTestCase {
response = solrClient.request(req);
assertEquals(response.get("result").toString(), "success");
triggerFiredLatch = new CountDownLatch(1);
listenerEvents.clear();
await = triggerFiredLatch.await(20, TimeUnit.SECONDS);
assertTrue("The trigger did not fire at all", await);
// wait for listener to capture the SUCCEEDED stage
@ -1629,6 +1630,6 @@ public class TriggerIntegrationTest extends SolrCloudTestCase {
assertTrue(TimeUnit.SECONDS.convert(waitForSeconds, TimeUnit.NANOSECONDS) - WAIT_FOR_DELTA_NANOS <= now - ev.event.getEventTime());
assertEquals(collectionName, ev.event.getProperties().get("collection"));
docCollection = solrClient.getZkStateReader().getClusterState().getCollection(collectionName);
assertEquals(3, docCollection.getReplicas().size());
assertEquals(5, docCollection.getReplicas().size());
}
}