This is an automated email from the ASF dual-hosted git repository.
psalagnac pushed a commit to branch branch_10_0
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_10_0 by this push:
new 5a2c364c10e Use latches instead of sleeping for one second in
SplitShardTest. (#3954)
5a2c364c10e is described below
commit 5a2c364c10e1724dd6779f2b5ef24811f105c70c
Author: Pierre Salagnac <[email protected]>
AuthorDate: Fri Dec 19 10:01:00 2025 +0100
Use latches instead of sleeping for one second in SplitShardTest. (#3954)
---
.../test/org/apache/solr/cloud/SplitShardTest.java | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
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 9018a32e294..0b539bd39d0 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
@@ -23,11 +23,13 @@ import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -261,10 +263,13 @@ public class SplitShardTest extends SolrCloudTestCase {
new ConcurrentHashMap<>(); // what the index should contain
final AtomicBoolean doIndex = new AtomicBoolean(true);
final AtomicInteger docsIndexed = new AtomicInteger();
+ List<CountDownLatch> threadLatches = Collections.synchronizedList(new
ArrayList<>());
Thread[] indexThreads = new Thread[nThreads];
try {
for (int i = 0; i < nThreads; i++) {
+ int threadIndex = i;
+ threadLatches.add(new CountDownLatch(10));
indexThreads[i] =
new Thread(
() -> {
@@ -290,6 +295,7 @@ public class SplitShardTest extends SolrCloudTestCase {
fail(e.getMessage());
break;
}
+ threadLatches.get(threadIndex).countDown();
}
});
}
@@ -298,8 +304,12 @@ public class SplitShardTest extends SolrCloudTestCase {
thread.start();
}
- Thread.sleep(100); // wait for a few docs to be indexed before invoking
split
+ // wait for a few docs (10 requests per threads) to be indexed before
invoking split
+ for (int i = 0; i < nThreads; i++) {
+ assertTrue(threadLatches.get(i).await(30, TimeUnit.SECONDS));
+ }
int docCount = model.size();
+ assertTrue("no docs indexed", docCount > 0);
CollectionAdminRequest.SplitShard splitShard =
CollectionAdminRequest.splitShard(collectionName).setShardName("shard1");
@@ -313,8 +323,14 @@ public class SplitShardTest extends SolrCloudTestCase {
// make sure that docs were indexed during the split
assertTrue(model.size() > docCount);
- Thread.sleep(100); // wait for a few more docs to be indexed after split
-
+ // wait for a few more docs (10 more requests per thread) to be indexed
after split
+ // Reset the latch of each thread, and them wait for all of them
+ for (int i = 0; i < nThreads; i++) {
+ threadLatches.set(i, new CountDownLatch(10));
+ }
+ for (int i = 0; i < nThreads; i++) {
+ assertTrue(threadLatches.get(i).await(30, TimeUnit.SECONDS));
+ }
} finally {
// shut down the indexers
doIndex.set(false);