You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2020/09/01 07:30:19 UTC

[lucene-solr] 01/08: Temporary commit

This is an automated email from the ASF dual-hosted git repository.

datcm pushed a commit to branch datcm/bloomberg-abdicate-leadership
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit b495dc0a310941c2945793a5c8cd74a320a033c9
Author: Cao Manh Dat <da...@apache.org>
AuthorDate: Wed Aug 26 11:07:24 2020 +0700

    Temporary commit
---
 .../apache/solr/cloud/TestAbdicateLeadership.java  | 44 ++++++++++++++++------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/cloud/TestAbdicateLeadership.java b/solr/core/src/test/org/apache/solr/cloud/TestAbdicateLeadership.java
index 442bf28..4e4462c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestAbdicateLeadership.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestAbdicateLeadership.java
@@ -13,35 +13,57 @@ import org.apache.solr.common.cloud.DocCollection;
 import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.util.TimeSource;
 import org.apache.solr.util.TimeOut;
+import org.junit.After;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.rules.Timeout;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 public class TestAbdicateLeadership extends SolrCloudTestCase {
 
-    private static final String COLLECTION_NAME = "collection1";
-
     @BeforeClass
     public static void setupCluster() throws Exception {
-
         configureCluster(3)
-                .addConfig(COLLECTION_NAME, configset("cloud-minimal"))
+                .addConfig("conf1", configset("cloud-minimal"))
                 .configure();
 
-        CollectionAdminResponse resp = CollectionAdminRequest.createCollection(COLLECTION_NAME, COLLECTION_NAME, 1, 3) .process(cluster.getSolrClient());
-        assertEquals("Admin request failed; ", 0, resp.getStatus());
-        cluster.waitForActiveCollection(COLLECTION_NAME, 1, 3);
+    }
+
+    public void testMultipleCollectionsWithStressIndexing() throws IOException, SolrServerException {
+        List<String> collections = new ArrayList<>();
+        // by Dirichlet's theorem there will always a node that host more than 1 leader
+        for (int i = 0; i < cluster.getJettySolrRunners().size() + 1; i++) {
+            String collection = "collection"+i+"_stress";
+            CollectionAdminRequest.createCollection(collection, "conf1", 1, 3)
+                    .process(cluster.getSolrClient());
+            cluster.waitForActiveCollection(collection, 1, 3);
+            collections.add(collection);
+        }
+    }
+
+    @After
+    public void deleteCollections() throws IOException, SolrServerException {
+        List<String> collections = CollectionAdminRequest.listCollections(cluster.getSolrClient());
+        for (String collection : collections) {
+            CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient());
+        }
     }
 
     @Test
-    public void test() throws IOException, SolrServerException, TimeoutException, InterruptedException {
+    public void testSimple() throws Exception {
+        String collection = "collection1_testsimple";
+        CollectionAdminResponse resp = CollectionAdminRequest.createCollection(collection, "conf1", 1, 3) .process(cluster.getSolrClient());
+        assertEquals("Admin request failed; ", 0, resp.getStatus());
+        cluster.waitForActiveCollection(collection, 1, 3);
         DocCollection dc = cluster.getSolrClient().getZkStateReader()
-                .getClusterState().getCollection(COLLECTION_NAME);
+                .getClusterState().getCollection(collection);
         Replica leaderReplica = dc.getSlice("shard1").getLeader();
         JettySolrRunner runner = cluster.getReplicaJetty(leaderReplica);
         AtomicBoolean closed = new AtomicBoolean(false);
@@ -49,7 +71,7 @@ public class TestAbdicateLeadership extends SolrCloudTestCase {
             int i = 0;
             while (!closed.get()) {
                 try {
-                    cluster.getSolrClient().add(COLLECTION_NAME, new SolrInputDocument("id", String.valueOf(i++)));
+                    cluster.getSolrClient().add(collection, new SolrInputDocument("id", String.valueOf(i++)));
                     Thread.sleep(100);
                 } catch (InterruptedException e) {
                     Thread.currentThread().interrupt();
@@ -63,7 +85,7 @@ public class TestAbdicateLeadership extends SolrCloudTestCase {
         TimeOut timeOut = new TimeOut(10, TimeUnit.SECONDS, TimeSource.CURRENT_TIME);
         timeOut.waitFor("Timeout waiting for a new leader", () -> {
             ClusterState state = cluster.getSolrClient().getZkStateReader().getClusterState();
-            Replica newLeader = state.getCollection(COLLECTION_NAME).getSlice("shard1").getLeader();
+            Replica newLeader = state.getCollection(collection).getSlice("shard1").getLeader();
             return newLeader != null && !newLeader.getNodeName().equals(runner.getNodeName());
         });
         closed.set(true);