You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/07/10 17:55:23 UTC
[lucene-solr] branch reference_impl updated: #55 Remove some
outdated waitFor's in tests.
This is an automated email from the ASF dual-hosted git repository.
markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/reference_impl by this push:
new 302451e #55 Remove some outdated waitFor's in tests.
302451e is described below
commit 302451e134d91e9feea39f1fd047bf9a36612612
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Fri Jul 10 12:55:03 2020 -0500
#55 Remove some outdated waitFor's in tests.
---
.../test/org/apache/solr/cloud/AddReplicaTest.java | 6 ++---
.../apache/solr/cloud/CreateRoutedAliasTest.java | 2 --
.../solr/cloud/LeaderElectionIntegrationTest.java | 5 +---
.../apache/solr/cloud/LeaderTragicEventTest.java | 15 ++----------
.../solr/cloud/LeaderVoteWaitTimeoutTest.java | 5 ++--
.../solr/cloud/MissingSegmentRecoveryTest.java | 3 +--
.../test/org/apache/solr/cloud/SplitShardTest.java | 11 +++------
.../apache/solr/cloud/TestCloudConsistency.java | 12 +---------
.../solr/cloud/TestCloudSearcherWarming.java | 14 ++++-------
.../org/apache/solr/cloud/TestPrepRecovery.java | 3 ---
.../solr/cloud/TestSkipOverseerOperations.java | 5 +---
.../solr/cloud/TestTlogReplayVsRecovery.java | 8 ++-----
.../org/apache/solr/cloud/TestTlogReplica.java | 10 ++++----
.../test/org/apache/solr/cloud/ZkFailoverTest.java | 3 ++-
.../collections/CollectionTooManyReplicasTest.java | 4 +---
.../CollectionsAPIDistClusterPerZkTest.java | 26 +++------------------
.../cloud/api/collections/SplitByPrefixTest.java | 17 ++++----------
.../test/org/apache/solr/core/TestDynamicURP.java | 1 -
.../client/solrj/impl/BaseCloudSolrClient.java | 27 ++++++++++++++++++----
19 files changed, 58 insertions(+), 119 deletions(-)
diff --git a/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java
index 0e85540..607f2b2 100644
--- a/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java
@@ -74,7 +74,6 @@ public class AddReplicaTest extends SolrCloudTestCase {
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collection, "conf1", 1, 1);
create.setMaxShardsPerNode(2);
cloudClient.request(create);
- cluster.waitForActiveCollection(collection, 1, 1);
CollectionAdminRequest.AddReplica addReplica = CollectionAdminRequest.addReplicaToShard(collection, "shard1")
.setNrtReplicas(1)
@@ -83,8 +82,6 @@ public class AddReplicaTest extends SolrCloudTestCase {
CollectionAdminResponse status = addReplica.process(cloudClient, collection + "_xyz1");
assertTrue(status.isSuccess());
- cluster.waitForActiveCollection(collection, 1, 4);
-
DocCollection docCollection = cloudClient.getZkStateReader().getClusterState().getCollectionOrNull(collection);
assertNotNull(docCollection);
assertEquals(4, docCollection.getReplicas().size());
@@ -128,7 +125,8 @@ public class AddReplicaTest extends SolrCloudTestCase {
.setCreateNodeSet(String.join(",", createNodeSet));
status = addReplica.process(cloudClient, collection + "_xyz1");
assertTrue(status.isSuccess());
- waitForState("Timedout wait for collection to be created", collection, clusterShape(1, 9));
+
+ cluster.waitForActiveCollection(collection, 1, 9);
docCollection = cloudClient.getZkStateReader().getClusterState().getCollectionOrNull(collection);
assertNotNull(docCollection);
// sanity check that everything is as before
diff --git a/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java b/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java
index bf80c58..68b3d7d 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java
@@ -232,8 +232,6 @@ public class CreateRoutedAliasTest extends SolrCloudTestCase {
cluster.waitForActiveCollection("collection1meta", 2, 2);
cluster.waitForActiveCollection("collection2meta", 1, 1);
- waitForState("Expected collection1 to be created with 2 shards and 1 replica", "collection1meta", clusterShape(2, 2));
- waitForState("Expected collection2 to be created with 1 shard and 1 replica", "collection2meta", clusterShape(1, 1));
ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
zkStateReader.createClusterStateWatchersAndUpdate();
diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
index a6a17ca..f621e07 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
@@ -86,10 +86,7 @@ public class LeaderElectionIntegrationTest extends SolrCloudTestCase {
for (JettySolrRunner runner : stoppedRunners) {
runner.start();
}
- waitForState("Expected to see nodes come back " + collection, collection,
- (n, c) -> {
- return n.size() == 6;
- });
+
CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient());
// testLeaderElectionAfterClientTimeout
diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
index 9c5ff4d..5d3a31a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
@@ -80,21 +80,12 @@ public class LeaderTragicEventTest extends SolrCloudTestCase {
CollectionAdminRequest
.createCollection(collection, "config", 1, 2)
.process(cluster.getSolrClient());
- cluster.waitForActiveCollection(collection, 1, 2);
+
try {
List<String> addedIds = new ArrayList<>();
Replica oldLeader = corruptLeader(collection, addedIds);
- waitForState("Timeout waiting for new replica become leader", collection, (liveNodes, collectionState) -> {
- Slice slice = collectionState.getSlice("shard1");
-
- if (slice.getReplicas().size() != 2) return false;
- if (slice.getLeader() == null) return false;
- if (slice.getLeader().getName().equals(oldLeader.getName())) return false;
-
- return true;
- });
- ClusterStateUtil.waitForAllActiveAndLiveReplicas(cluster.getSolrClient().getZkStateReader(), collection, 120000);
+ cluster.waitForActiveCollection(collection, 1, 2);
Slice shard = getCollectionState(collection).getSlice("shard1");
assertNotSame(shard.getLeader().getNodeName(), oldLeader.getNodeName());
assertEquals(getNonLeader(shard).getNodeName(), oldLeader.getNodeName());
@@ -184,8 +175,6 @@ public class LeaderTragicEventTest extends SolrCloudTestCase {
log.info("Stop jetty node : {} state:{}", otherReplicaJetty.getBaseUrl(), getCollectionState(collection));
}
otherReplicaJetty.stop();
- cluster.waitForJettyToStop(otherReplicaJetty);
- waitForState("Timeout waiting for replica get down", collection, (liveNodes, collectionState) -> getNonLeader(collectionState.getSlice("shard1")).getState() != Replica.State.ACTIVE);
}
Replica oldLeader = corruptLeader(collection, new ArrayList<>());
diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java
index 728acd4..8cececd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java
@@ -196,8 +196,7 @@ public class LeaderVoteWaitTimeoutTest extends SolrCloudTestCase {
.process(cluster.getSolrClient());
cluster.waitForActiveCollection(collectionName, 1, 3);
-
- waitForState("Timeout waiting for 1x3 collection", collectionName, clusterShape(1, 3));
+
Replica replica2 = getCollectionState(collectionName).getSlice("shard1")
.getReplicas(replica -> replica.getNodeName().equals(cluster.getJettySolrRunner(2).getNodeName())).get(0);
@@ -256,7 +255,7 @@ public class LeaderVoteWaitTimeoutTest extends SolrCloudTestCase {
cluster.getJettySolrRunner(0).start();
proxies.get(cluster.getJettySolrRunner(0)).reopen();
- waitForState("Timeout waiting for 1x3 collection", collectionName, clusterShape(1, 3));
+ cluster.waitForActiveCollection(collectionName, 1, 3);
assertDocsExistInAllReplicas(Arrays.asList(leader, replica1), collectionName, 1, 3);
try {
diff --git a/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.java b/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.java
index 47335f1..bb1e263 100644
--- a/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.java
@@ -59,7 +59,6 @@ public class MissingSegmentRecoveryTest extends SolrCloudTestCase {
CollectionAdminRequest.createCollection(collection, "conf", 1, 2)
.setMaxShardsPerNode(1)
.process(cluster.getSolrClient());
- waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
cluster.getSolrClient().setDefaultCollection(collection);
List<SolrInputDocument> docs = new ArrayList<>();
@@ -106,7 +105,7 @@ public class MissingSegmentRecoveryTest extends SolrCloudTestCase {
jetty.stop();
jetty.start();
- waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
+ cluster.waitForActiveCollection(collection, 1, 2);
QueryResponse resp = cluster.getSolrClient().query(collection, new SolrQuery("*:*"));
assertEquals(10, resp.getResults().getNumFound());
diff --git a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
index c66529e..a11e9cd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
@@ -87,9 +87,7 @@ public class SplitShardTest extends SolrCloudTestCase {
.setNumSubShards(5)
.setShardName("shard1");
splitShard.process(cluster.getSolrClient());
- waitForState("Timed out waiting for sub shards to be active. Number of active shards=" +
- cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(COLLECTION_NAME).getActiveSlices().size(),
- COLLECTION_NAME, activeClusterShape(6, 7));
+ cluster.waitForActiveCollection(COLLECTION_NAME, 6, 7);
try {
splitShard = CollectionAdminRequest.splitShard(COLLECTION_NAME).setShardName("shard2").setNumSubShards(10);
@@ -138,9 +136,7 @@ public class SplitShardTest extends SolrCloudTestCase {
.setSplitFuzz(0.5f)
.setShardName("shard1");
splitShard.process(cluster.getSolrClient());
- waitForState("Timed out waiting for sub shards to be active. Number of active shards=" +
- cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(collectionName).getActiveSlices().size(),
- collectionName, activeClusterShape(3, 4));
+ cluster.waitForActiveCollection(COLLECTION_NAME, 3, 4);
DocCollection coll = cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(collectionName);
Slice s1_0 = coll.getSlice("shard1_0");
Slice s1_1 = coll.getSlice("shard1_1");
@@ -245,8 +241,7 @@ public class SplitShardTest extends SolrCloudTestCase {
CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(collectionName)
.setShardName("shard1");
splitShard.process(client);
- waitForState("Timed out waiting for sub shards to be active.",
- collectionName, activeClusterShape(2, 3*repFactor)); // 2 repFactor for the new split shards, 1 repFactor for old replicas
+ cluster.waitForActiveCollection(COLLECTION_NAME, 2, 3*repFactor); // 2 repFactor for the new split shards, 1 repFactor for old replicas
// make sure that docs were able to be indexed during the split
assertTrue(model.size() > docCount);
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java
index 50ae130..2e84513 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java
@@ -117,7 +117,6 @@ public class TestCloudConsistency extends SolrCloudTestCase {
CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
.setNode(cluster.getJettySolrRunner(0).getNodeName())
.process(cluster.getSolrClient());
- waitForState("Timeout waiting for shard leader", collectionName, clusterShape(1, 1));
CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
.setNode(cluster.getJettySolrRunner(1).getNodeName())
@@ -127,8 +126,6 @@ public class TestCloudConsistency extends SolrCloudTestCase {
.process(cluster.getSolrClient());
cluster.waitForActiveCollection(collectionName, 1, 3);
-
- waitForState("Timeout waiting for 1x3 collection", collectionName, clusterShape(1, 3));
addDocs(collectionName, 3, 1);
@@ -159,16 +156,11 @@ public class TestCloudConsistency extends SolrCloudTestCase {
j2.stop();
cluster.waitForJettyToStop(j1);
cluster.waitForJettyToStop(j2);
-
- waitForState("", collection, (liveNodes, collectionState) ->
- collectionState.getSlice("shard1").getReplicas().stream()
- .filter(replica -> replica.getState() == Replica.State.DOWN).count() == 2);
addDocs(collection, 1, docId);
JettySolrRunner j3 = cluster.getJettySolrRunner(0);
j3.stop();
cluster.waitForJettyToStop(j3);
- waitForState("", collection, (liveNodes, collectionState) -> collectionState.getReplica(leader.getName()).getState() == Replica.State.DOWN);
cluster.getJettySolrRunner(1).start();
cluster.getJettySolrRunner(2).start();
@@ -203,7 +195,7 @@ public class TestCloudConsistency extends SolrCloudTestCase {
Replica newLeader = collectionState.getLeader("shard1");
return newLeader != null && newLeader.getName().equals(leader.getName());
});
- waitForState("Timeout waiting for active collection", collection, clusterShape(1, 3));
+ cluster.waitForActiveCollection(collection, 1, 3);
}
@@ -244,7 +236,6 @@ public class TestCloudConsistency extends SolrCloudTestCase {
}
waitForState("Timeout waiting for leader goes DOWN", collection, (liveNodes, collectionState)
-> collectionState.getReplica(leader.getName()).getState() == Replica.State.DOWN);
- Thread.sleep(1000);
// the meat of the test -- wait to see if a different replica become a leader
// the correct behavior is that this should time out, if it succeeds we have a problem...
@@ -269,7 +260,6 @@ public class TestCloudConsistency extends SolrCloudTestCase {
Replica newLeader = collectionState.getLeader("shard1");
return newLeader != null && newLeader.getName().equals(leader.getName());
});
- waitForState("Timeout waiting for active collection", collection, clusterShape(1, 3));
cluster.waitForActiveCollection(collection, 1, 3);
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java
index 74475f5..e3d02fd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java
@@ -124,8 +124,7 @@ public class TestCloudSearcherWarming extends SolrCloudTestCase {
// check waitForState only after we are sure the node has shutdown and have forced an update to liveNodes
// ie: workaround SOLR-13490
cluster.getSolrClient().getZkStateReader().updateLiveNodes();
- waitForState("jetty count:" + cluster.getJettySolrRunners().size(), collectionName, clusterShape(1, 0));
-
+ cluster.waitForActiveCollection(collectionName, 1, 0);
// restart
sleepTime.set(1000);
runner.start();
@@ -146,8 +145,6 @@ public class TestCloudSearcherWarming extends SolrCloudTestCase {
.setCreateNodeSet(cluster.getJettySolrRunner(0).getNodeName()).setMaxShardsPerNode(2);
create.process(solrClient);
- waitForState("The collection should have 1 shard and 1 replica", collectionName, clusterShape(1, 1));
-
solrClient.setDefaultCollection(collectionName);
String addListenerCommand = "{" +
@@ -182,7 +179,6 @@ public class TestCloudSearcherWarming extends SolrCloudTestCase {
.setNode(newNode.getNodeName())
.process(solrClient);
- waitForState("The collection should have 1 shard and 2 replica", collectionName, clusterShape(1, 2));
assertNull("No replica should have been active without registering a searcher, found: " + failingCoreNodeName.get(), failingCoreNodeName.get());
// stop the old node
@@ -192,7 +188,7 @@ public class TestCloudSearcherWarming extends SolrCloudTestCase {
cluster.waitForJettyToStop(oldNode);
// the newly created replica should become leader
- waitForState("The collection should have 1 shard and 1 replica", collectionName, clusterShape(1, 1));
+ cluster.waitForActiveCollection(collectionName, 1, 1);
// the above call is not enough because we want to assert that the down'ed replica is not active
// but clusterShape will also return true if replica is not live -- which we don't want
CollectionStatePredicate collectionStatePredicate = (liveNodes, collectionState) -> {
@@ -217,7 +213,7 @@ public class TestCloudSearcherWarming extends SolrCloudTestCase {
// now lets restart the old node
log.info("Starting old node 1");
cluster.startJettySolrRunner(oldNode);
- waitForState("", collectionName, clusterShape(1, 2));
+ cluster.waitForActiveCollection(collectionName, 1, 2);
// invoke statewatcher explicitly to avoid race condition where the assert happens before the state watcher is invoked by ZkStateReader
cluster.getSolrClient().getZkStateReader().registerCollectionStateWatcher(collectionName, stateWatcher);
assertNull("No replica should have been active without registering a searcher, found: " + failingCoreNodeName.get(), failingCoreNodeName.get());
@@ -225,7 +221,7 @@ public class TestCloudSearcherWarming extends SolrCloudTestCase {
oldNodeName.set(cluster.getJettySolrRunner(1).getNodeName());
assertSame(oldNode, cluster.stopJettySolrRunner(1)); // old node is now at 1
log.info("Stopping old node 2");
- waitForState("", collectionName, clusterShape(1, 1));
+ cluster.waitForActiveCollection(collectionName, 1, 1);
waitForState("", collectionName, collectionStatePredicate);
// reset
@@ -239,7 +235,7 @@ public class TestCloudSearcherWarming extends SolrCloudTestCase {
// now lets restart the old node again
log.info("Starting old node 2");
cluster.startJettySolrRunner(oldNode);
- waitForState("", collectionName, clusterShape(1, 2));
+ cluster.waitForActiveCollection(collectionName, 1, 2);
// invoke statewatcher explicitly to avoid race condition where the assert happens before the state watcher is invoked by ZkStateReader
cluster.getSolrClient().getZkStateReader().registerCollectionStateWatcher(collectionName, stateWatcher);
assertNull("No replica should have been active without registering a searcher, found: " + failingCoreNodeName.get(), failingCoreNodeName.get());
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPrepRecovery.java b/solr/core/src/test/org/apache/solr/cloud/TestPrepRecovery.java
index b1b2a1f..70e1acb 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestPrepRecovery.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestPrepRecovery.java
@@ -100,9 +100,6 @@ public class TestPrepRecovery extends SolrCloudTestCase {
CollectionAdminRequest.createCollection(collectionName, 1, 1)
.process(solrClient);
- waitForState("Expected collection: testLeaderNotResponding to be live with 1 shard and 1 replicas",
- collectionName, clusterShape(1, 1));
-
TestInjection.prepRecoveryOpPauseForever = "true:100";
try {
CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSkipOverseerOperations.java b/solr/core/src/test/org/apache/solr/cloud/TestSkipOverseerOperations.java
index f7e8eff..8bf314e 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestSkipOverseerOperations.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestSkipOverseerOperations.java
@@ -117,11 +117,8 @@ public class TestSkipOverseerOperations extends SolrCloudTestCase {
for (JettySolrRunner solrRunner : notOverseerNodes) {
solrRunner.start();
}
-
- cluster.waitForAllNodes(30);
- waitForState("Expected 2x1 for collection: " + collection, collection,
- clusterShape(2, 2));
+ cluster.waitForActiveCollection(collection, 2, 4);
CollectionAdminResponse resp2 = CollectionAdminRequest.getOverseerStatus().process(cluster.getSolrClient());
assertEquals(getNumLeaderOpeations(resp) + 2, getNumLeaderOpeations(resp2));
CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient());
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java
index 8b9f1cf..1c68306 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java
@@ -136,16 +136,13 @@ public class TestTlogReplayVsRecovery extends SolrCloudTestCase {
.setNode(NODE0.getNodeName())
.processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT));
- waitForState("Timeout waiting for shard leader", COLLECTION, clusterShape(1, 1));
+ cluster.waitForActiveCollection(COLLECTION, 1, 2);
assertEquals(RequestStatusState.COMPLETED,
CollectionAdminRequest.addReplicaToShard(COLLECTION, "shard1")
.setNode(NODE1.getNodeName())
.processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT));
-
- cluster.waitForActiveCollection(COLLECTION, 1, 2);
-
- waitForState("Timeout waiting for 1x2 collection", COLLECTION, clusterShape(1, 2));
+
final Replica leader = getCollectionState(COLLECTION).getSlice("shard1").getLeader();
assertEquals("Sanity check failed", NODE0.getNodeName(), leader.getNodeName());
@@ -202,7 +199,6 @@ public class TestTlogReplayVsRecovery extends SolrCloudTestCase {
Replica newLeader = collectionState.getLeader("shard1");
return newLeader != null && newLeader.getName().equals(leader.getName());
});
- waitForState("Timeout waiting for active collection", COLLECTION, clusterShape(1, 2));
cluster.waitForActiveCollection(COLLECTION, 1, 2);
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java
index ae0f595..1a7e5f5 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java
@@ -215,7 +215,7 @@ public class TestTlogReplica extends SolrCloudTestCase {
CollectionAdminResponse response = CollectionAdminRequest.reloadCollection(collectionName)
.process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
- waitForState("failed waiting for active colletion", collectionName, clusterShape(2, 8));
+ cluster.waitForActiveCollection(collectionName, 2, 8);
reloaded = true;
}
}
@@ -273,7 +273,7 @@ public class TestTlogReplica extends SolrCloudTestCase {
addReplicaToShard("shard2", Replica.Type.TLOG);
docCollection = assertNumberOfReplicas(0, 4, 0, true, false);
- waitForState("Expecting collection to have 2 shards and 2 replica each", collectionName, clusterShape(2, 4));
+ cluster.waitForActiveCollection(collectionName, 2, 4);
//Delete tlog replica from shard1
CollectionAdminRequest.deleteReplica(
@@ -331,7 +331,6 @@ public class TestTlogReplica extends SolrCloudTestCase {
CollectionAdminRequest.createCollection(collectionName, "conf", 1, numNrtReplicas, numReplicas, 0)
.setMaxShardsPerNode(100)
.process(cluster.getSolrClient());
- waitForState("Unexpected replica count", collectionName, activeReplicaCount(numNrtReplicas, numReplicas, 0));
DocCollection docCollection = assertNumberOfReplicas(numNrtReplicas, numReplicas, 0, false, true);
HttpClient httpClient = cluster.getSolrClient().getHttpClient();
int id = 0;
@@ -421,7 +420,8 @@ public class TestTlogReplica extends SolrCloudTestCase {
leaderJetty.start();
cluster.waitForNode(leaderJetty, 10000);
}
- waitForState("Expected collection to be 1x2", collectionName, clusterShape(1, 2));
+
+ cluster.waitForActiveCollection(collectionName, 1, 2);
// added replica should replicate from the leader
waitForNumDocsInAllReplicas(2, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS);
}
@@ -454,7 +454,7 @@ public class TestTlogReplica extends SolrCloudTestCase {
JettySolrRunner pullReplicaJetty = cluster.getReplicaJetty(docCollection.getSlice("shard1").getReplicas(EnumSet.of(Replica.Type.TLOG)).get(0));
pullReplicaJetty.stop();
cluster.waitForJettyToStop(pullReplicaJetty);
- waitForState("Replica not removed", collectionName, activeReplicaCount(0, 1, 0));
+
waitForLeaderChange(pullReplicaJetty, "shard1");
// // Also wait for the replica to be placed in state="down"
// waitForState("Didn't update state", collectionName, clusterStateReflectsActiveAndDownReplicas());
diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkFailoverTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkFailoverTest.java
index d4178f4..78f3593 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ZkFailoverTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkFailoverTest.java
@@ -62,7 +62,7 @@ public class ZkFailoverTest extends SolrCloudTestCase {
});
threads[i].start();
}
- Thread.sleep(5000);
+ Thread.sleep(TEST_NIGHTLY ? 5000 : 100);
zkTestServer = new ZkTestServer(zkTestServer.getZkDir(), zkTestServer.getPort());
zkTestServer.run(false);
for (Thread thread : threads) {
@@ -70,6 +70,7 @@ public class ZkFailoverTest extends SolrCloudTestCase {
}
waitForLiveNodes(2);
waitForState("Timeout waiting for " + coll, coll, clusterShape(2, 2));
+ cluster.waitForActiveCollection(coll, 2, 4);
QueryResponse rsp = new QueryRequest(new SolrQuery("*:*")).process(cluster.getSolrClient(), coll);
assertEquals(1, rsp.getResults().getNumFound());
zkTestServer.shutdown();
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionTooManyReplicasTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionTooManyReplicasTest.java
index fa33763..0f4061c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionTooManyReplicasTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionTooManyReplicasTest.java
@@ -161,9 +161,7 @@ public class CollectionTooManyReplicasTest extends SolrCloudTestCase {
// And finally, ensure that there are all the replicas we expect. We should have shards 1, 2 and 4 and each
// should have exactly two replicas
- waitForState("Expected shards shardstart, 1, 2 and 4, each with two active replicas", collectionName, (n, c) -> {
- return DocCollection.isFullyActive(n, c, 4, 2);
- });
+ cluster.waitForActiveCollection(collectionName, 4, 8);
Map<String, Slice> slices = getCollectionState(collectionName).getSlicesMap();
assertEquals("There should be exaclty four slices", slices.size(), 4);
assertNotNull("shardstart should exist", slices.get("shardstart"));
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIDistClusterPerZkTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIDistClusterPerZkTest.java
index d6e36d9..e7d39ef 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIDistClusterPerZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIDistClusterPerZkTest.java
@@ -294,8 +294,6 @@ public class CollectionsAPIDistClusterPerZkTest extends SolrCloudTestCase {
cluster.waitForActiveCollection(coll.name, coll.numShards, coll.numShards * coll.replicationFactor);
}
- waitForStable(cnt, createRequests);
-
for (int i = 0; i < cluster.getJettySolrRunners().size(); i++) {
checkInstanceDirs(cluster.getJettySolrRunner(i));
}
@@ -316,7 +314,7 @@ public class CollectionsAPIDistClusterPerZkTest extends SolrCloudTestCase {
break;
}
- Thread.sleep(500);
+ Thread.sleep(100);
}
if (timeOut.hasTimedOut()) {
@@ -326,24 +324,6 @@ public class CollectionsAPIDistClusterPerZkTest extends SolrCloudTestCase {
// checkNoTwoShardsUseTheSameIndexDir();
}
- private void waitForStable(int cnt, CollectionAdminRequest.Create[] createRequests) throws InterruptedException {
- for (int i = 0; i < cnt; i++) {
- String collectionName = "awhollynewcollection_" + i;
- final int j = i;
- waitForState("Expected to see collection " + collectionName, collectionName,
- (n, c) -> {
- CollectionAdminRequest.Create req = createRequests[j];
- return DocCollection.isFullyActive(n, c, req.getNumShards(), req.getReplicationFactor());
- });
-
- ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
- // make sure we have leaders for each shard
- for (int z = 1; z < createRequests[j].getNumShards(); z++) {
- zkStateReader.getLeaderRetry(collectionName, "shard" + z, 10000);
- } // make sure we again have leaders for each shard
- }
- }
-
@Test
@Ignore // nocommit have to fix reload again, ug, its a pain, I don't recall the exact incantation
public void testCollectionReload() throws Exception {
@@ -355,7 +335,7 @@ public class CollectionsAPIDistClusterPerZkTest extends SolrCloudTestCase {
collectStartTimes(collectionName, urlToTimeBefore);
assertTrue(urlToTimeBefore.size() > 0);
- Thread.sleep(200);
+ Thread.sleep(50);
CollectionAdminRequest.reloadCollection(collectionName).processAsync(cluster.getSolrClient());
@@ -379,7 +359,7 @@ public class CollectionsAPIDistClusterPerZkTest extends SolrCloudTestCase {
}
private boolean waitForReloads(String collectionName, Map<String,Long> urlToTimeBefore) throws SolrServerException, IOException {
- TimeOut timeout = new TimeOut(45, TimeUnit.SECONDS, TimeSource.NANO_TIME);
+ TimeOut timeout = new TimeOut(5, TimeUnit.SECONDS, TimeSource.NANO_TIME);
boolean allTimesAreCorrect = false;
while (! timeout.hasTimedOut()) {
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java
index 37f8071..4297b8b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java
@@ -175,9 +175,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
splitShard.setAsyncId("SPLIT1");
}
splitShard.process(client);
- waitForState("Timed out waiting for sub shards to be active.",
- COLLECTION_NAME, activeClusterShape(2, 3)); // expectedReplicas==3 because original replica still exists (just inactive)
-
+ cluster.waitForActiveCollection(COLLECTION_NAME, 2, 3); // expectedReplicas==3 because original replica still exists (just inactive)
List<Prefix> prefixes = findPrefixes(20, 0, 0x00ffffff);
List<Prefix> uniquePrefixes = removeDups(prefixes);
@@ -200,9 +198,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
splitShard.setAsyncId("SPLIT2");
}
splitShard.process(client);
- waitForState("Timed out waiting for sub shards to be active.",
- COLLECTION_NAME, activeClusterShape(3, 5));
-
+ cluster.waitForActiveCollection(COLLECTION_NAME, 3, 5);
// OK, now let's check that the correct split point was chosen
// We can use the router to find the shards for the middle prefixes and they should be different.
@@ -232,8 +228,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
splitShard.setAsyncId("SPLIT3");
}
splitShard.process(client);
- waitForState("Timed out waiting for sub shards to be active.",
- COLLECTION_NAME, activeClusterShape(4, 7));
+ cluster.waitForActiveCollection(COLLECTION_NAME, 4, 7);
collection = client.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME);
slices1 = collection.getRouter().getSearchSlicesSingle(uniquePrefixes.get(0).key, null, collection);
@@ -255,8 +250,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
splitShard.setAsyncId("SPLIT4");
}
splitShard.process(client);
- waitForState("Timed out waiting for sub shards to be active.",
- COLLECTION_NAME, activeClusterShape(5, 9));
+ cluster.waitForActiveCollection(COLLECTION_NAME, 5, 9);
collection = client.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME);
slices1 = collection.getRouter().getSearchSlicesSingle(uniquePrefixes.get(0).key, null, collection);
@@ -274,8 +268,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
splitShard.setAsyncId("SPLIT5");
}
splitShard.process(client);
- waitForState("Timed out waiting for sub shards to be active.",
- COLLECTION_NAME, activeClusterShape(6, 11));
+ cluster.waitForActiveCollection(COLLECTION_NAME, 6, 11);
collection = client.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME);
slices1 = collection.getRouter().getSearchSlicesSingle(uniquePrefixes.get(0).key, null, collection);
diff --git a/solr/core/src/test/org/apache/solr/core/TestDynamicURP.java b/solr/core/src/test/org/apache/solr/core/TestDynamicURP.java
index 6c42920..d95715f 100644
--- a/solr/core/src/test/org/apache/solr/core/TestDynamicURP.java
+++ b/solr/core/src/test/org/apache/solr/core/TestDynamicURP.java
@@ -68,7 +68,6 @@ public class TestDynamicURP extends SolrCloudTestCase {
CollectionAdminRequest.createCollection(COLLECTION, "conf", 3, 1).process(cluster.getSolrClient());
- waitForState("", COLLECTION, clusterShape(3, 3));
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BaseCloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BaseCloudSolrClient.java
index c72c00d..6692253 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BaseCloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BaseCloudSolrClient.java
@@ -1076,7 +1076,7 @@ public abstract class BaseCloudSolrClient extends SolrClient {
}
try {
- getZkStateReader().waitForState(params.get("name"), 10, TimeUnit.SECONDS, expectedShardsAndActiveReplicas(shardNames.size(), expectedReplicas * shardNames.size()));
+ getZkStateReader().waitForState(params.get("name"), 10, TimeUnit.SECONDS, expectedShardsAndActiveReplicas(shardNames.size(), expectedReplicas * shardNames.size(), false));
} catch (InterruptedException e) {
ParWork.propegateInterrupt(e);
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Interrupted waiting for active collection");
@@ -1445,11 +1445,22 @@ public abstract class BaseCloudSolrClient extends SolrClient {
}
public static CollectionStatePredicate expectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas) {
+ return expectedShardsAndActiveReplicas(expectedShards, expectedReplicas, true);
+ }
+
+ public static CollectionStatePredicate expectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas, boolean exact) {
return (liveNodes, collectionState) -> {
if (collectionState == null)
return false;
- if (collectionState.getSlices().size() < expectedShards) {
- return false;
+
+ if (!exact) {
+ if (collectionState.getSlices().size() < expectedShards) {
+ return false;
+ }
+ } else {
+ if (collectionState.getSlices().size() != expectedShards) {
+ return false;
+ }
}
if (expectedReplicas == 0) {
@@ -1468,8 +1479,14 @@ public abstract class BaseCloudSolrClient extends SolrClient {
}
}
}
- if (activeReplicas >= expectedReplicas) {
- return true;
+ if (!exact) {
+ if (activeReplicas >= expectedReplicas) {
+ return true;
+ }
+ } else {
+ if (activeReplicas == expectedReplicas) {
+ return true;
+ }
}
return false;