2121
2222import org .elasticsearch .action .DocWriteResponse ;
2323import org .elasticsearch .action .admin .cluster .health .ClusterHealthResponse ;
24+ import org .elasticsearch .action .admin .cluster .node .hotthreads .NodeHotThreads ;
2425import org .elasticsearch .action .delete .DeleteResponse ;
2526import org .elasticsearch .action .index .IndexResponse ;
2627import org .elasticsearch .cluster .ClusterState ;
2728import org .elasticsearch .cluster .node .DiscoveryNode ;
2829import org .elasticsearch .cluster .routing .allocation .command .MoveAllocationCommand ;
2930import org .elasticsearch .common .Priority ;
3031import org .elasticsearch .common .settings .Settings ;
32+ import org .elasticsearch .common .unit .TimeValue ;
3133import org .elasticsearch .index .query .QueryBuilders ;
3234import org .elasticsearch .test .ESIntegTestCase ;
3335import org .elasticsearch .test .hamcrest .ElasticsearchAssertions ;
3436
3537import java .util .concurrent .atomic .AtomicBoolean ;
3638import java .util .concurrent .atomic .AtomicInteger ;
39+ import java .util .stream .Collectors ;
3740
38- import static org .hamcrest .Matchers .equalTo ;
3941
4042@ ESIntegTestCase .ClusterScope (scope = ESIntegTestCase .Scope .TEST )
4143public class IndexPrimaryRelocationIT extends ESIntegTestCase {
@@ -54,7 +56,7 @@ public void testPrimaryRelocationWhileIndexing() throws Exception {
5456 Thread indexingThread = new Thread () {
5557 @ Override
5658 public void run () {
57- while (finished .get () == false ) {
59+ while (finished .get () == false && numAutoGenDocs . get () < 10_000 ) {
5860 IndexResponse indexResponse = client ().prepareIndex ("test" , "type" , "id" ).setSource ("field" , "value" ).get ();
5961 assertEquals (DocWriteResponse .Result .CREATED , indexResponse .getResult ());
6062 DeleteResponse deleteResponse = client ().prepareDelete ("test" , "type" , "id" ).get ();
@@ -80,8 +82,18 @@ public void run() {
8082 .add (new MoveAllocationCommand ("test" , 0 , relocationSource .getId (), relocationTarget .getId ()))
8183 .execute ().actionGet ();
8284 ClusterHealthResponse clusterHealthResponse = client ().admin ().cluster ().prepareHealth ()
85+ .setTimeout (TimeValue .timeValueSeconds (60 ))
8386 .setWaitForEvents (Priority .LANGUID ).setWaitForNoRelocatingShards (true ).execute ().actionGet ();
84- assertThat (clusterHealthResponse .isTimedOut (), equalTo (false ));
87+ if (clusterHealthResponse .isTimedOut ()) {
88+ final String hotThreads = client ().admin ().cluster ().prepareNodesHotThreads ().setIgnoreIdleThreads (false ).get ().getNodes ()
89+ .stream ().map (NodeHotThreads ::getHotThreads ).collect (Collectors .joining ("\n " ));
90+ final ClusterState clusterState = client ().admin ().cluster ().prepareState ().get ().getState ();
91+ logger .info ("timed out for waiting for relocation iteration [{}] \n cluster state {} \n hot threads {}" ,
92+ i , clusterState , hotThreads );
93+ finished .set (true );
94+ indexingThread .join ();
95+ throw new AssertionError ("timed out waiting for relocation iteration [" + i + "] " );
96+ }
8597 logger .info ("--> [iteration {}] relocation complete" , i );
8698 relocationSource = relocationTarget ;
8799 // indexing process aborted early, no need for more relocations as test has already failed
0 commit comments