diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 963f1bab629..6decce3694a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -320,6 +320,8 @@ Other Changes * SOLR-12680: Fix ClassCastException and AIOOBE in TestSolrConfigHandlerConcurrent. (shalin) +* SOLR-12675: Make LeaderVoteWaitTimeoutTest more resilient against side effects of test methods. (shalin) + ================== 7.4.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java index 35844872149..a4a7bc019cf 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java @@ -37,6 +37,7 @@ import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.ZkCoreNodeProps; import org.apache.solr.common.util.NamedList; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; @@ -45,6 +46,7 @@ import org.slf4j.LoggerFactory; public class LeaderVoteWaitTimeoutTest extends SolrCloudTestCase { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private static final int NODE_COUNT = 4; private static Map proxies; private static Map jettys; @@ -55,7 +57,7 @@ public class LeaderVoteWaitTimeoutTest extends SolrCloudTestCase { System.setProperty("solr.ulog.numRecordsToKeep", "1000"); System.setProperty("leaderVoteWait", "2000"); - configureCluster(4) + configureCluster(NODE_COUNT) .addConfig("conf", configset("cloud-minimal")) .configure(); @@ -86,6 +88,13 @@ public class LeaderVoteWaitTimeoutTest extends SolrCloudTestCase { System.clearProperty("leaderVoteWait"); } + @Before + public void setupTest() throws Exception { + SolrCloudTestCase.ensureRunningJettys(NODE_COUNT, 5); + cluster.deleteAllCollections(); + cluster.getSolrClient().setDefaultCollection(null); + } + @Test //28-June-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 21-May-2018 public void basicTest() throws Exception { diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java index 53499364e8a..c42d1e86366 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java @@ -64,6 +64,7 @@ import static org.apache.solr.common.cloud.ZkStateReader.SOLR_AUTOSCALING_CONF_P @LogLevel("org.apache.solr.cloud.autoscaling=DEBUG;org.apache.solr.client.solrj.cloud.autoscaling=DEBUG") public class TriggerIntegrationTest extends SolrCloudTestCase { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private static final int NODE_COUNT = 2; private static volatile CountDownLatch actionConstructorCalled; private static volatile CountDownLatch actionInitCalled; @@ -84,7 +85,7 @@ public class TriggerIntegrationTest extends SolrCloudTestCase { @BeforeClass public static void setupCluster() throws Exception { - configureCluster(2) + configureCluster(NODE_COUNT) .addConfig("conf", configset("cloud-minimal")) .configure(); // disable .scheduled_maintenance @@ -115,19 +116,7 @@ public class TriggerIntegrationTest extends SolrCloudTestCase { @Before public void setupTest() throws Exception { - // ensure that exactly 2 jetty nodes are running - int numJetties = cluster.getJettySolrRunners().size(); - log.info("Found {} jetty instances running", numJetties); - for (int i = 2; i < numJetties; i++) { - int r = random().nextInt(cluster.getJettySolrRunners().size()); - log.info("Shutdown extra jetty instance at port {}", cluster.getJettySolrRunner(r).getLocalPort()); - cluster.stopJettySolrRunner(r); - } - for (int i = cluster.getJettySolrRunners().size(); i < 2; i++) { - // start jetty instances - cluster.startJettySolrRunner(); - } - cluster.waitForAllNodes(5); + SolrCloudTestCase.ensureRunningJettys(NODE_COUNT, 5); NamedList overSeerStatus = cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus()); String overseerLeader = (String) overSeerStatus.get("leader"); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java index d0cc4c58b0c..1b5f67bbd51 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java @@ -371,4 +371,33 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 { return null; } + /** + * Ensure that the given number of solr instances are running. If less instances are found then new instances are + * started. If extra instances are found then they are stopped. + * @param nodeCount the number of Solr instances that should be running at the end of this method + * @throws Exception on error + */ + public static void ensureRunningJettys(int nodeCount, int timeoutSeconds) throws Exception { + // ensure that exactly nodeCount jetty nodes are running + List jettys = cluster.getJettySolrRunners(); + List copyOfJettys = new ArrayList<>(jettys); + int numJetties = copyOfJettys.size(); + for (int i = nodeCount; i < numJetties; i++) { + cluster.stopJettySolrRunner(copyOfJettys.get(i)); + } + for (int i = copyOfJettys.size(); i < nodeCount; i++) { + // start jetty instances + cluster.startJettySolrRunner(); + } + // refresh the count from the source + jettys = cluster.getJettySolrRunners(); + numJetties = jettys.size(); + for (int i = 0; i < numJetties; i++) { + if (!jettys.get(i).isRunning()) { + cluster.startJettySolrRunner(jettys.get(i)); + } + } + cluster.waitForAllNodes(timeoutSeconds); + } + }