Skip to content

Commit 9faa3c6

Browse files
committed
[TEST] ensure exceptions won't cause test to hang
1 parent 2e2bb25 commit 9faa3c6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.index;
2121

2222
import org.elasticsearch.ElasticsearchException;
23+
import org.elasticsearch.ExceptionsHelper;
2324
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
2425
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
2526
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
@@ -49,6 +50,7 @@
4950
import java.io.IOException;
5051
import java.nio.file.Path;
5152
import java.util.List;
53+
import java.util.concurrent.CopyOnWriteArrayList;
5254
import java.util.concurrent.CountDownLatch;
5355
import java.util.concurrent.ExecutionException;
5456
import java.util.concurrent.Future;
@@ -317,7 +319,7 @@ public void testPrimaryRelocation() throws Exception {
317319
}
318320

319321
@Test
320-
public void testPrimaryRelocationWithConcurrentIndexing() throws Exception {
322+
public void testPrimaryRelocationWithConcurrentIndexing() throws Throwable {
321323
Settings nodeSettings = nodeSettings();
322324

323325
String node1 = internalCluster().startNode(nodeSettings);
@@ -346,15 +348,19 @@ public void testPrimaryRelocationWithConcurrentIndexing() throws Exception {
346348
final int numPhase2Docs = scaledRandomIntBetween(25, 200);
347349
final CountDownLatch phase1finished = new CountDownLatch(1);
348350
final CountDownLatch phase2finished = new CountDownLatch(1);
349-
351+
final CopyOnWriteArrayList<Throwable> exceptions = new CopyOnWriteArrayList<>();
350352
Thread thread = new Thread() {
351353
@Override
352354
public void run() {
353355
started.countDown();
354356
while (counter.get() < (numPhase1Docs + numPhase2Docs)) {
355-
final IndexResponse indexResponse = client().prepareIndex(IDX, "doc",
356-
Integer.toString(counter.incrementAndGet())).setSource("foo", "bar").get();
357-
assertTrue(indexResponse.isCreated());
357+
try {
358+
final IndexResponse indexResponse = client().prepareIndex(IDX, "doc",
359+
Integer.toString(counter.incrementAndGet())).setSource("foo", "bar").get();
360+
assertTrue(indexResponse.isCreated());
361+
} catch (Throwable t) {
362+
exceptions.add(t);
363+
}
358364
final int docCount = counter.get();
359365
if (docCount == numPhase1Docs) {
360366
phase1finished.countDown();
@@ -374,6 +380,7 @@ public void run() {
374380
// wait for more documents to be indexed post-recovery, also waits for
375381
// indexing thread to stop
376382
phase2finished.await();
383+
ExceptionsHelper.rethrowAndSuppress(exceptions);
377384
ensureGreen(IDX);
378385
thread.join();
379386
logger.info("--> performing query");

0 commit comments

Comments
 (0)