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

This commit is contained in:
Anshum Gupta 2018-09-10 14:20:07 -07:00
parent 623cdf29ad
commit a1b6db26db
2 changed files with 35 additions and 11 deletions

View File

@ -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 ==================

View File

@ -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,19 +291,39 @@ 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}
*/