2020package org .elasticsearch .index ;
2121
2222import org .elasticsearch .ElasticsearchException ;
23+ import org .elasticsearch .ExceptionsHelper ;
2324import org .elasticsearch .action .admin .cluster .snapshots .create .CreateSnapshotResponse ;
2425import org .elasticsearch .action .admin .cluster .snapshots .restore .RestoreSnapshotResponse ;
2526import org .elasticsearch .action .admin .cluster .state .ClusterStateResponse ;
4950import java .io .IOException ;
5051import java .nio .file .Path ;
5152import java .util .List ;
53+ import java .util .concurrent .CopyOnWriteArrayList ;
5254import java .util .concurrent .CountDownLatch ;
5355import java .util .concurrent .ExecutionException ;
5456import 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