You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by an...@apache.org on 2018/09/10 23:14:35 UTC

lucene-solr:master: SOLR-12762: Fix javadoc for SolrCloudTestCase.clusterShape() method and add a method that validates only against Active slices while testing

Repository: lucene-solr
Updated Branches:
  refs/heads/master 623cdf29a -> a1b6db26d


SOLR-12762: Fix javadoc for SolrCloudTestCase.clusterShape() method and add a method that validates only against Active slices while testing


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

Branch: refs/heads/master
Commit: a1b6db26db5e03a31492549a181c285f9b35c9a2
Parents: 623cdf2
Author: Anshum Gupta <an...@apache.org>
Authored: Mon Sep 10 14:20:07 2018 -0700
Committer: Anshum Gupta <an...@apache.org>
Committed: Mon Sep 10 15:18:32 2018 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  6 ++-
 .../apache/solr/cloud/SolrCloudTestCase.java    | 40 +++++++++++++++-----
 2 files changed, 35 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a1b6db26/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0d71204..f9e5b56 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -84,7 +84,11 @@ Apache ZooKeeper 3.4.11
 Jetty 9.4.11.v20180605
 
 
-(No Changes)
+Other Changes
+----------------------
+
+* SOLR-12762: Fix javadoc for SolrCloudTestCase.clusterShape() method and add a method that validates only against
+  Active slices (Anshum Gupta)
 
 
 ==================  7.5.0 ==================

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a1b6db26/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 1b5f67b..bd041f0 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
@@ -283,7 +283,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
 
   /**
    * Return a {@link CollectionStatePredicate} that returns true if a collection has the expected
-   * number of active shards and active replicas
+   * number of shards and active replicas
    */
   public static CollectionStatePredicate clusterShape(int expectedShards, int expectedReplicas) {
     return (liveNodes, collectionState) -> {
@@ -291,20 +291,40 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
         return false;
       if (collectionState.getSlices().size() != expectedShards)
         return false;
-      for (Slice slice : collectionState) {
-        int activeReplicas = 0;
-        for (Replica replica : slice) {
-          if (replica.isActive(liveNodes))
-            activeReplicas++;
-        }
-        if (activeReplicas != expectedReplicas)
-          return false;
-      }
+      if (compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState)) return false;
       return true;
     };
   }
 
   /**
+   * Return a {@link CollectionStatePredicate} that returns true if a collection has the expected
+   * number of active shards and active replicas
+   */
+  public static CollectionStatePredicate activeClusterShape(int expectedShards, int expectedReplicas) {
+    return (liveNodes, collectionState) -> {
+      if (collectionState == null)
+        return false;
+      if (collectionState.getActiveSlices().size() != expectedShards)
+        return false;
+      if (compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState)) return false;
+      return true;
+    };
+  }
+
+  private static boolean compareActiveReplicaCountsForShards(int expectedReplicas, Set<String> liveNodes, DocCollection collectionState) {
+    for (Slice slice : collectionState) {
+      int activeReplicas = 0;
+      for (Replica replica : slice) {
+        if (replica.isActive(liveNodes))
+          activeReplicas++;
+      }
+      if (activeReplicas != expectedReplicas)
+        return true;
+    }
+    return false;
+  }
+
+  /**
    * Get a (reproducibly) random shard from a {@link DocCollection}
    */
   protected static Slice getRandomShard(DocCollection collection) {