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/11 02:07:20 UTC
lucene-solr:branch_7x: 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/branch_7x 61447db8d -> 784357a02
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/784357a0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/784357a0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/784357a0
Branch: refs/heads/branch_7x
Commit: 784357a02adfa6fef722843963985dc3b42569ac
Parents: 61447db
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 16:33:56 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/784357a0/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a945520..bf03f6e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -29,7 +29,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/784357a0/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) {