From a2199c72d40c8aaf55dd9ca20816c2aa1ee805ea Mon Sep 17 00:00:00 2001 From: Chris Hostetter Date: Mon, 10 Dec 2018 19:06:42 -0700 Subject: [PATCH] SOLR-13050: add workaround for issue to SystemLogListenerTest make sure the node we kill isn't the .system collection leader --- .../autoscaling/SystemLogListenerTest.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/SystemLogListenerTest.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/SystemLogListenerTest.java index 040a26f34f9..6a84a6fe646 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/SystemLogListenerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/SystemLogListenerTest.java @@ -38,6 +38,7 @@ import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.cloud.SolrCloudTestCase; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; +import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.params.CollectionAdminParams; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; @@ -148,25 +149,16 @@ public class SystemLogListenerTest extends SolrCloudTestCase { response = solrClient.request(req); assertEquals(response.get("result").toString(), "success"); - // stop non-overseer node - NamedList overSeerStatus = cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus()); - String overseerLeader = (String) overSeerStatus.get("leader"); - int nonOverseerLeaderIndex = 0; - for (int i = 0; i < cluster.getJettySolrRunners().size(); i++) { - JettySolrRunner jetty = cluster.getJettySolrRunner(i); - if (!jetty.getNodeName().equals(overseerLeader)) { - nonOverseerLeaderIndex = i; - } - } - log.info("Stopping node " + cluster.getJettySolrRunner(nonOverseerLeaderIndex).getNodeName()); - JettySolrRunner j = cluster.stopJettySolrRunner(nonOverseerLeaderIndex); - cluster.waitForJettyToStop(j); + // Stop a node (that's safe to stop for the purposes of this test) + final JettySolrRunner stoppedJetty = pickNodeToStop(); + log.info("Stopping node " + stoppedJetty.getNodeName()); + cluster.stopJettySolrRunner(stoppedJetty); + cluster.waitForJettyToStop(stoppedJetty); + assertTrue("Trigger was not fired ", triggerFiredLatch.await(60, TimeUnit.SECONDS)); assertTrue(fired.get()); Map context = actionContextPropsRef.get(); assertNotNull(context); - - TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); @@ -199,7 +191,8 @@ public class SystemLogListenerTest extends SolrCloudTestCase { QueryResponse resp = cluster.getSolrClient().query(CollectionAdminParams.SYSTEM_COLL, query); SolrDocumentList docs = resp.getResults(); assertNotNull(docs); - assertEquals("wrong number of events added to .system", 9, docs.size()); + assertEquals("wrong number of events added to .system: " + docs.toString(), + 9, docs.size()); docs.forEach(doc -> assertCommonFields(doc)); // STARTED @@ -273,4 +266,25 @@ public class SystemLogListenerTest extends SolrCloudTestCase { assertNotNull(doc.getFieldValue("event_str")); assertEquals("NODELOST", doc.getFieldValue("event.type_s")); } + + /** + * Helper method for picking a node that can safely be stoped + * @see SOLR-13050 + */ + private JettySolrRunner pickNodeToStop() throws Exception { + // first get the nodeName of the overser. + // stopping the overseer is not something we want to hassle with in this test + final String overseerNodeName = (String) cluster.getSolrClient().request + (CollectionAdminRequest.getOverseerStatus()).get("leader"); + + // now find a node that is *NOT* the overseer or the leader of a .system collection shard + for (Replica r : getCollectionState(CollectionAdminParams.SYSTEM_COLL).getReplicas()) { + if ( ! (r.getBool("leader", false) || r.getNodeName().equals(overseerNodeName) ) ) { + return cluster.getReplicaJetty(r); + } + } + fail("Couldn't find non-leader, non-overseer, replica of .system collection to kill"); + return null; + } + }