lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject lucene-solr:branch_7x: SOLR-11469: Sanity check assertions about coreNodeNames are identical in 2 collections
Date Wed, 25 Oct 2017 02:12:15 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x b0a9dea47 -> 0994d3d31


SOLR-11469: Sanity check assertions about coreNodeNames are identical in 2 collections


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

Branch: refs/heads/branch_7x
Commit: 0994d3d31081edab4a7db9f20dfcd0315d4aa299
Parents: b0a9dea
Author: Cao Manh Dat <datcm@apache.org>
Authored: Wed Oct 25 09:11:32 2017 +0700
Committer: Cao Manh Dat <datcm@apache.org>
Committed: Wed Oct 25 09:12:03 2017 +0700

----------------------------------------------------------------------
 .../cloud/LeaderElectionContextKeyTest.java     | 46 ++++++++------------
 1 file changed, 19 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0994d3d3/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java
index a98cf50..dd265aa 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java
@@ -26,7 +26,7 @@ import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
 import org.apache.solr.client.solrj.request.CoreAdminRequest;
-import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.SolrZkClient;
 import org.apache.solr.common.cloud.ZkStateReader;
@@ -72,14 +72,26 @@ public class LeaderElectionContextKeyTest extends SolrCloudTestCase {
   public void test() throws KeeperException, InterruptedException, IOException, SolrServerException
{
     ZkStateReader stateReader = cluster.getSolrClient().getZkStateReader();
     stateReader.forceUpdateCollection(TEST_COLLECTION_1);
-    List<Replica> replicasOfCollection1 = stateReader.getClusterState().getCollection(TEST_COLLECTION_1).getReplicas();
-    List<Replica> replicasOfCollection2 = stateReader.getClusterState().getCollection(TEST_COLLECTION_2).getReplicas();
-    Replica replica = findLeaderReplicaWithDuplicatedName(replicasOfCollection1, replicasOfCollection2);
-    String shard = getShard(stateReader.getClusterState().getCollection(TEST_COLLECTION_1),
replica);
+    ClusterState clusterState = stateReader.getClusterState();
+    // The test assume that TEST_COLLECTION_1 and TEST_COLLECTION_2 will have identical layout
+    // ( same replica's name on every shard )
+    for (int i = 1; i <= 2; i++) {
+      String coll1ShardiLeader = clusterState.getCollection(TEST_COLLECTION_1).getLeader("shard"+i).getName();
+      String coll2ShardiLeader = clusterState.getCollection(TEST_COLLECTION_2).getLeader("shard"+i).getName();
+      String assertMss = String.format("Expect %s and %s each have a replica with same name
on shard %s",
+          coll1ShardiLeader, coll2ShardiLeader, "shard"+i);
+      assertEquals(
+          assertMss,
+          coll1ShardiLeader,
+          coll2ShardiLeader
+      );
+    }
+
+    String shard = "shard" + String.valueOf(random().nextInt(2) + 1);
+    Replica replica = clusterState.getCollection(TEST_COLLECTION_1).getLeader(shard);
     assertNotNull(replica);
 
-    SolrClient shardLeaderClient = new HttpSolrClient.Builder(replica.get("base_url").toString()).build();
-    try {
+    try (SolrClient shardLeaderClient = new HttpSolrClient.Builder(replica.get("base_url").toString()).build())
{
       assertEquals(1L, getElectionNodes(TEST_COLLECTION_1, shard, stateReader.getZkClient()).size());
       List<String> collection2Shard1Nodes = getElectionNodes(TEST_COLLECTION_2, "shard1",
stateReader.getZkClient());
       List<String> collection2Shard2Nodes = getElectionNodes(TEST_COLLECTION_2, "shard2",
stateReader.getZkClient());
@@ -99,27 +111,7 @@ public class LeaderElectionContextKeyTest extends SolrCloudTestCase {
       // There are no leader election was kicked off on testCollection2
       assertThat(collection2Shard1Nodes, CoreMatchers.is(getElectionNodes(TEST_COLLECTION_2,
"shard1", stateReader.getZkClient())));
       assertThat(collection2Shard2Nodes, CoreMatchers.is(getElectionNodes(TEST_COLLECTION_2,
"shard2", stateReader.getZkClient())));
-    } finally {
-      shardLeaderClient.close();
-    }
-  }
-
-  private String getShard(DocCollection docCollection, Replica replica) {
-    return docCollection.getShardId(replica.getNodeName(), replica.getCoreName());
-  }
-
-  private Replica findLeaderReplicaWithDuplicatedName(List<Replica> replicas1, List<Replica>
replicas2) {
-    for (Replica replica1 : replicas1) {
-      if (!replica1.containsKey("leader")) continue;
-      for (Replica replica2 : replicas2) {
-        if (replica1.getName().equals(replica2.getName())
-            && replica1.get("base_url").equals(replica2.get("base_url"))
-            && replica2.containsKey("leader")) {
-          return replica1;
-        }
-      }
     }
-    return null;
   }
 
   private List<String> getElectionNodes(String collection, String shard, SolrZkClient
client) throws KeeperException, InterruptedException {


Mime
View raw message