lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [45/50] [abbrv] lucene-solr:jira/http2: SOLR-12675: Make LeaderVoteWaitTimeoutTest more resilient against side effects of test methods.
Date Tue, 21 Aug 2018 01:31:12 GMT
SOLR-12675: Make LeaderVoteWaitTimeoutTest more resilient against side effects of test methods.

Extracted a new method to ensure a given number of jettys are always running in the test setup.
Also, delete all collections created by other test methods.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/079a81f1
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/079a81f1
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/079a81f1

Branch: refs/heads/jira/http2
Commit: 079a81f14f4caa7f3920c306037b6c25c59037b0
Parents: 3c9050c
Author: Shalin Shekhar Mangar <shalin@apache.org>
Authored: Mon Aug 20 14:45:50 2018 +0530
Committer: Shalin Shekhar Mangar <shalin@apache.org>
Committed: Mon Aug 20 14:45:50 2018 +0530

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 ++
 .../solr/cloud/LeaderVoteWaitTimeoutTest.java   | 11 +++++++-
 .../autoscaling/TriggerIntegrationTest.java     | 17 ++----------
 .../apache/solr/cloud/SolrCloudTestCase.java    | 29 ++++++++++++++++++++
 4 files changed, 44 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/079a81f1/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 963f1ba..6decce3 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.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/079a81f1/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java
----------------------------------------------------------------------
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 3584487..a4a7bc0 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<JettySolrRunner, SocketProxy> proxies;
   private static Map<URI, JettySolrRunner> 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 {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/079a81f1/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java
----------------------------------------------------------------------
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 5349936..c42d1e8 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<Object> overSeerStatus = cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus());
     String overseerLeader = (String) overSeerStatus.get("leader");

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/079a81f1/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
----------------------------------------------------------------------
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 d0cc4c5..1b5f67b 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<JettySolrRunner> jettys = cluster.getJettySolrRunners();
+    List<JettySolrRunner> 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);
+  }
+
 }


Mime
View raw message