Skip to content

Commit bbbff85

Browse files
authored
SOLR-17581: Less ZK watches in tests. (#3036)
Introduce new test variant of waitForState(), that does not wait on live node changes when we're only interested in the collection state. This is a test change only.
1 parent 79216e9 commit bbbff85

35 files changed

+228
-221
lines changed

solr/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ Other Changes
194194
* SOLR-17611: SolrJ's User-Agent header now uses the version of SolrJ. There's a corresponding
195195
HttpSolrCall.getUserAgentSolrVersion to parse it. (David Smiley)
196196

197+
* SOLR-17581: Introduce new test variant of waitForState(), that does not wait on live node changes when we're only
198+
interested in the collection state. (Pierre Salagnac)
199+
197200
================== 9.8.0 ==================
198201
New Features
199202
---------------------

solr/core/src/test/org/apache/solr/cloud/CollectionStateZnodeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.solr.cloud;
1818

19+
import java.util.Objects;
1920
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
2021
import org.apache.solr.common.cloud.DocCollection;
2122
import org.apache.zookeeper.data.Stat;
@@ -64,7 +65,7 @@ public void testZkNodeLocation() throws Exception {
6465

6566
// remove collection
6667
CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
67-
waitForState("Collection not deleted", collectionName, (n, coll) -> coll == null);
68+
waitForState("Collection not deleted", collectionName, Objects::isNull);
6869

6970
assertFalse(
7071
"collection state should not exist",

solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void testCreateWithDefaultConfigSet() throws Exception {
132132
waitForState(
133133
"Expected " + collectionName + " to disappear from cluster state",
134134
collectionName,
135-
(n, c) -> c == null);
135+
Objects::isNull);
136136
}
137137

138138
@Test
@@ -260,7 +260,7 @@ public void testCreateAndDeleteCollection() throws Exception {
260260
waitForState(
261261
"Expected " + collectionName + " to disappear from cluster state",
262262
collectionName,
263-
(n, c) -> c == null);
263+
Objects::isNull);
264264

265265
// Test Creating a new collection.
266266
collectionName = "solrj_test2";
@@ -274,7 +274,7 @@ public void testCreateAndDeleteCollection() throws Exception {
274274
waitForState(
275275
"Expected " + collectionName + " to appear in cluster state",
276276
collectionName,
277-
(n, c) -> c != null);
277+
Objects::nonNull);
278278
}
279279

280280
@Test
@@ -328,13 +328,10 @@ public void testCreateAndDeleteShard() throws Exception {
328328
assertEquals(0, response.getStatus());
329329
assertTrue(response.isSuccess());
330330

331-
cluster
332-
.getZkStateReader()
333-
.waitForState(
334-
collectionName,
335-
30,
336-
TimeUnit.SECONDS,
337-
(l, c) -> c != null && c.getSlice("shardC") != null);
331+
waitForState(
332+
"Wait for shard to be visible",
333+
collectionName,
334+
c -> c != null && c.getSlice("shardC") != null);
338335
coresStatus = response.getCollectionCoresStatus();
339336
assertEquals(3, coresStatus.size());
340337
int replicaTlog = 0;
@@ -423,9 +420,7 @@ public void testSplitShard() throws Exception {
423420
assertTrue(response.isSuccess());
424421

425422
waitForState(
426-
"Expected 5 slices to be active",
427-
collectionName,
428-
(n, c) -> c.getActiveSlices().size() == 5);
423+
"Expected 5 slices to be active", collectionName, c -> c.getActiveSlices().size() == 5);
429424
}
430425

431426
@Test
@@ -493,7 +488,7 @@ public void testAddAndDeleteReplica() throws Exception {
493488
waitForState(
494489
"Expected replica " + newReplica.getName() + " to vanish from cluster state",
495490
collectionName,
496-
(n, c) -> c.getSlice("shard1").getReplica(newReplica.getName()) == null);
491+
c -> c.getSlice("shard1").getReplica(newReplica.getName()) == null);
497492
}
498493

499494
private Replica grabNewReplica(CollectionAdminResponse response, DocCollection docCollection) {
@@ -1277,7 +1272,7 @@ public void testAddAndDeleteReplicaProp() throws IOException, SolrServerExceptio
12771272
waitForState(
12781273
"Expecting property 'preferredleader' to appear on replica " + replica.getName(),
12791274
collection,
1280-
(n, c) -> "true".equals(c.getReplica(replica.getName()).getProperty("preferredleader")));
1275+
c -> "true".equals(c.getReplica(replica.getName()).getProperty("preferredleader")));
12811276

12821277
response =
12831278
CollectionAdminRequest.deleteReplicaProperty(
@@ -1288,7 +1283,7 @@ public void testAddAndDeleteReplicaProp() throws IOException, SolrServerExceptio
12881283
waitForState(
12891284
"Expecting property 'preferredleader' to be removed from replica " + replica.getName(),
12901285
collection,
1291-
(n, c) -> c.getReplica(replica.getName()).getProperty("preferredleader") == null);
1286+
c -> c.getReplica(replica.getName()).getProperty("preferredleader") == null);
12921287
}
12931288

12941289
@Test
@@ -1308,7 +1303,7 @@ public void testBalanceShardUnique() throws IOException, SolrServerException {
13081303
waitForState(
13091304
"Expecting 'preferredleader' property to be balanced across all shards",
13101305
collection,
1311-
(n, c) -> {
1306+
c -> {
13121307
for (Slice slice : c) {
13131308
int count = 0;
13141309
for (Replica replica : slice) {
@@ -1335,7 +1330,7 @@ public void testModifyCollectionAttribute() throws IOException, SolrServerExcept
13351330
waitForState(
13361331
"Expecting attribute 'replicationFactor' to be 25",
13371332
collection,
1338-
(n, c) -> 25 == c.getReplicationFactor());
1333+
c -> 25 == c.getReplicationFactor());
13391334

13401335
expectThrows(
13411336
IllegalArgumentException.class,

solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void deleteInactiveReplicaTest() throws Exception {
8282
waitForState(
8383
"Expected replica " + replica.getName() + " on down node to be removed from cluster state",
8484
collectionName,
85-
(n, c) -> {
85+
c -> {
8686
Replica r = c.getReplica(replica.getName());
8787
return r == null || r.getState() != Replica.State.ACTIVE;
8888
});
@@ -95,9 +95,7 @@ public void deleteInactiveReplicaTest() throws Exception {
9595
waitForState(
9696
"Expected deleted replica " + replica.getName() + " to be removed from cluster state",
9797
collectionName,
98-
(n, c) -> {
99-
return c.getReplica(replica.getName()) == null;
100-
});
98+
c -> c.getReplica(replica.getName()) == null);
10199

102100
cluster.startJettySolrRunner(jetty);
103101
log.info("restarted jetty");

solr/core/src/test/org/apache/solr/cloud/DeleteLastCustomShardedReplicaTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public void test() throws Exception {
4646
waitForState(
4747
"Expected shard 'a' to have no replicas",
4848
collectionName,
49-
(n, c) -> {
50-
return c.getSlice("a") == null || c.getSlice("a").getReplicas().size() == 0;
51-
});
49+
c -> c.getSlice("a") == null || c.getSlice("a").getReplicas().isEmpty());
5250
}
5351
}

solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void deleteLiveReplicaTest() throws Exception {
129129
waitForState(
130130
"Expected replica " + replica.getName() + " to have been removed",
131131
collectionName,
132-
(n, c) -> {
132+
c -> {
133133
Slice testShard = c.getSlice(shard.getName());
134134
return testShard.getReplica(replica.getName()) == null;
135135
});
@@ -286,8 +286,7 @@ public void deleteReplicaFromClusterState() throws Exception {
286286
waitForState(
287287
"Timeout waiting for replica get deleted",
288288
collectionName,
289-
(liveNodes, collectionState) ->
290-
collectionState.getSlice("shard1").getReplicas().size() == 2);
289+
collectionState -> collectionState.getSlice("shard1").getReplicas().size() == 2);
291290

292291
TimeOut timeOut = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);
293292
timeOut.waitFor(
@@ -430,7 +429,7 @@ public void raceConditionOnDeleteAndRegisterReplica() throws Exception {
430429
waitForState(
431430
"Expected replica:" + replica1 + " get down",
432431
collectionName,
433-
(liveNodes, collectionState) ->
432+
collectionState ->
434433
collectionState.getSlice("shard1").getReplica(replica1.getName()).getState()
435434
== DOWN);
436435
}
@@ -465,7 +464,7 @@ public void raceConditionOnDeleteAndRegisterReplica() throws Exception {
465464
waitForState(
466465
"Expected new active leader",
467466
collectionName,
468-
(liveNodes, collectionState) -> {
467+
collectionState -> {
469468
Slice shard = collectionState.getSlice("shard1");
470469
Replica newLeader = shard.getLeader();
471470
return newLeader != null
@@ -549,20 +548,10 @@ public void deleteReplicaOnIndexing() throws Exception {
549548
thread.join();
550549
}
551550

552-
try {
553-
cluster
554-
.getZkStateReader()
555-
.waitForState(
556-
collectionName,
557-
20,
558-
TimeUnit.SECONDS,
559-
(liveNodes, collectionState) -> collectionState.getReplicas().size() == 1);
560-
} catch (TimeoutException e) {
561-
if (log.isInfoEnabled()) {
562-
log.info("Timeout wait for state {}", getCollectionState(collectionName));
563-
}
564-
throw e;
565-
}
551+
waitForState(
552+
"Waiting for single replica in state",
553+
collectionName,
554+
collectionState -> collectionState.getReplicas().size() == 1);
566555
}
567556

568557
/**

solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ public void test() throws Exception {
6767

6868
// Can delete an INACTIVE shard
6969
CollectionAdminRequest.deleteShard(collection, "shard1").process(cluster.getSolrClient());
70-
waitForState(
71-
"Expected 'shard1' to be removed", collection, (n, c) -> c.getSlice("shard1") == null);
70+
waitForState("Expected 'shard1' to be removed", collection, c -> c.getSlice("shard1") == null);
7271

7372
// Can delete a shard under construction
7473
setSliceState(collection, "shard2", Slice.State.CONSTRUCTION);
7574
CollectionAdminRequest.deleteShard(collection, "shard2").process(cluster.getSolrClient());
76-
waitForState(
77-
"Expected 'shard2' to be removed", collection, (n, c) -> c.getSlice("shard2") == null);
75+
waitForState("Expected 'shard2' to be removed", collection, c -> c.getSlice("shard2") == null);
7876
}
7977

8078
@Test
@@ -100,7 +98,7 @@ public void testDirectoryCleanupAfterDeleteShard() throws IOException, SolrServe
10098
// Delete shard 'a'
10199
CollectionAdminRequest.deleteShard(collection, "a").process(cluster.getSolrClient());
102100

103-
waitForState("Expected 'a' to be removed", collection, (n, c) -> c.getSlice("a") == null);
101+
waitForState("Expected 'a' to be removed", collection, c -> c.getSlice("a") == null);
104102

105103
assertEquals(2, getCollectionState(collection).getActiveSlices().size());
106104
assertFalse(
@@ -116,7 +114,7 @@ public void testDirectoryCleanupAfterDeleteShard() throws IOException, SolrServe
116114
.setDeleteInstanceDir(false)
117115
.process(cluster.getSolrClient());
118116

119-
waitForState("Expected 'b' to be removed", collection, (n, c) -> c.getSlice("b") == null);
117+
waitForState("Expected 'b' to be removed", collection, c -> c.getSlice("b") == null);
120118

121119
assertEquals(1, getCollectionState(collection).getActiveSlices().size());
122120
assertTrue(
@@ -130,6 +128,6 @@ private void setSliceState(String collectionName, String shardId, Slice.State st
130128
waitForState(
131129
"Expected shard " + shardId + " to be in state " + state,
132130
collectionName,
133-
(n, c) -> c.getSlice(shardId).getState() == state);
131+
c -> c.getSlice(shardId).getState() == state);
134132
}
135133
}

solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,10 @@ public void setupCluster(boolean security) throws Exception {
9797
setAuthIfNeeded(CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 2))
9898
.process(cluster.getSolrClient());
9999

100-
cluster
101-
.getZkStateReader()
102-
.waitForState(
103-
COLLECTION,
104-
DEFAULT_TIMEOUT,
105-
TimeUnit.SECONDS,
106-
(n, c) -> DocCollection.isFullyActive(n, c, 2, 2));
100+
waitForState(
101+
"Waiting for collection creation",
102+
COLLECTION,
103+
(n, c) -> DocCollection.isFullyActive(n, c, 2, 2));
107104
}
108105

109106
@Test

solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testSimpleSliceLeaderElection() throws Exception {
8484
waitForState(
8585
"Leader should not be " + jettyNodeName,
8686
collection,
87-
(n, c) ->
87+
c ->
8888
c.getLeader("shard1") != null
8989
&& !jettyNodeName.equals(c.getLeader("shard1").getNodeName()));
9090
}

solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void testLeaderFailsOver() throws Exception {
8888
waitForState(
8989
"Now waiting for new replica to become leader",
9090
collection,
91-
(liveNodes, collectionState) -> {
91+
collectionState -> {
9292
Slice slice = collectionState.getSlice("shard1");
9393

9494
if (slice.getReplicas().size() != 2) return false;
@@ -176,7 +176,7 @@ public void testOtherReplicasAreNotActive() throws Exception {
176176
waitForState(
177177
"Timeout waiting for replica get down",
178178
collection,
179-
(liveNodes, collectionState) ->
179+
collectionState ->
180180
getNonLeader(collectionState.getSlice("shard1")).getState() != Replica.State.ACTIVE);
181181
}
182182

0 commit comments

Comments
 (0)