Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Tests: MiniSolrCloudCluster.waitForActiveCollection considers slice state (#4936)

David Smiley425a2dbd6c4d
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
index 7aba36a9188..1338cf6c94b 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
@@ -895,16 +895,23 @@ public class MiniSolrCloudCluster implements SolrBackend {
}
}
+ /**
+ * Matches when the collection has exactly {@code expectedShards} {@link
+ * org.apache.solr.common.cloud.Slice.State#ACTIVE} slices, and exactly {@code expectedReplicas}
+ * active replicas across them. Slices in any other state (e.g. a split parent, or a slice under
+ * construction during a restore) and their replicas are not counted.
+ */
public static CollectionStatePredicate expectedShardsAndActiveReplicas(
int expectedShards, int expectedReplicas) {
return (liveNodes, collectionState) -> {
if (collectionState == null) return false;
- if (collectionState.getSlices().size() != expectedShards) {
+ Collection<Slice> activeSlices = collectionState.getActiveSlices();
+ if (activeSlices.size() != expectedShards) {
return false;
}
int activeReplicas = 0;
- for (Slice slice : collectionState) {
+ for (Slice slice : activeSlices) {
for (Replica replica : slice) {
if (replica.isActive(liveNodes)) {
activeReplicas++;
@@ -915,11 +922,24 @@ public class MiniSolrCloudCluster implements SolrBackend {
};
}
+ /**
+ * Matches when every slice is either {@link org.apache.solr.common.cloud.Slice.State#ACTIVE} or
+ * {@link org.apache.solr.common.cloud.Slice.State#INACTIVE} (none are mid-split or mid-restore),
+ * and every replica of the active slices is active.
+ */
public static CollectionStatePredicate expectedActive() {
return (liveNodes, collectionState) -> {
if (collectionState == null) return false;
for (Slice slice : collectionState) {
+ switch (slice.getState()) {
+ case INACTIVE:
+ continue;
+ case ACTIVE:
+ break;
+ default:
+ return false;
+ }
for (Replica replica : slice) {
if (!replica.isActive(liveNodes)) {
return false;
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 dbca1f97ef4..ecd14bef337 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
@@ -318,18 +318,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
*/
public static CollectionStatePredicate activeClusterShape(
int expectedShards, int expectedReplicas) {
- return (liveNodes, collectionState) -> {
- if (collectionState == null) return false;
- if (log.isInfoEnabled()) {
- log.info(
- "active slice count: {} expected: {}",
- collectionState.getActiveSlices().size(),
- expectedShards);
- }
- if (collectionState.getActiveSlices().size() != expectedShards) return false;
- return compareActiveReplicaCountsForShards(
- expectedReplicas, liveNodes, collectionState.getActiveSlices());
- };
+ return MiniSolrCloudCluster.expectedShardsAndActiveReplicas(expectedShards, expectedReplicas);
}
public static LiveNodesPredicate containsLiveNode(String node) {