1010
1111import org .apache .logging .log4j .Level ;
1212import org .apache .lucene .util .Constants ;
13- import org .elasticsearch .action .ActionListener ;
13+ import org .elasticsearch .action .ActionFuture ;
1414import org .elasticsearch .action .admin .cluster .node .hotthreads .NodeHotThreads ;
1515import org .elasticsearch .action .admin .cluster .node .hotthreads .NodesHotThreadsRequest ;
1616import org .elasticsearch .action .admin .cluster .node .hotthreads .NodesHotThreadsResponse ;
2626import org .hamcrest .Matcher ;
2727
2828import java .util .Map ;
29- import java .util .concurrent .CountDownLatch ;
30- import java .util .concurrent .atomic .AtomicBoolean ;
29+ import java .util .concurrent .ExecutionException ;
3130
3231import static org .elasticsearch .index .query .QueryBuilders .boolQuery ;
3332import static org .elasticsearch .index .query .QueryBuilders .matchAllQuery ;
3433import static org .elasticsearch .index .query .QueryBuilders .termQuery ;
3534import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertHitCount ;
35+ import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertResponse ;
3636import static org .hamcrest .CoreMatchers .equalTo ;
37- import static org .hamcrest .CoreMatchers .is ;
3837import static org .hamcrest .CoreMatchers .notNullValue ;
3938import static org .hamcrest .Matchers .allOf ;
4039import static org .hamcrest .Matchers .containsString ;
4443
4544public class HotThreadsIT extends ESIntegTestCase {
4645
47- public void testHotThreadsDontFail () throws InterruptedException {
46+ public void testHotThreadsDontFail () throws InterruptedException , ExecutionException {
4847 // This test just checks if nothing crashes or gets stuck etc.
4948 createIndex ("test" );
5049 final int iters = scaledRandomIntBetween (2 , 20 );
51- final AtomicBoolean hasErrors = new AtomicBoolean (false );
5250 for (int i = 0 ; i < iters ; i ++) {
5351 final NodesHotThreadsRequest request = new NodesHotThreadsRequest (
5452 Strings .EMPTY_ARRAY ,
@@ -67,36 +65,7 @@ public void testHotThreadsDontFail() throws InterruptedException {
6765 randomBoolean ()
6866 )
6967 );
70- final CountDownLatch latch = new CountDownLatch (1 );
71- client ().execute (TransportNodesHotThreadsAction .TYPE , request , new ActionListener <>() {
72- @ Override
73- public void onResponse (NodesHotThreadsResponse nodeHotThreads ) {
74- boolean success = false ;
75- try {
76- assertThat (nodeHotThreads , notNullValue ());
77- Map <String , NodeHotThreads > nodesMap = nodeHotThreads .getNodesMap ();
78- assertThat (nodeHotThreads .failures (), empty ());
79- assertThat (nodesMap .size (), equalTo (cluster ().size ()));
80- for (NodeHotThreads ht : nodeHotThreads .getNodes ()) {
81- assertNotNull (ht .getHotThreads ());
82- }
83- success = true ;
84- } finally {
85- if (success == false ) {
86- hasErrors .set (true );
87- }
88- latch .countDown ();
89- }
90- }
91-
92- @ Override
93- public void onFailure (Exception e ) {
94- logger .error ("FAILED" , e );
95- hasErrors .set (true );
96- latch .countDown ();
97- fail ();
98- }
99- });
68+ final ActionFuture <NodesHotThreadsResponse > hotThreadsFuture = client ().execute (TransportNodesHotThreadsAction .TYPE , request );
10069
10170 indexRandom (
10271 true ,
@@ -105,7 +74,7 @@ public void onFailure(Exception e) {
10574 prepareIndex ("test" ).setId ("3" ).setSource ("field1" , "value3" )
10675 );
10776 ensureSearchable ();
108- while (latch . getCount () > 0 ) {
77+ while (hotThreadsFuture . isDone () == false ) {
10978 assertHitCount (
11079 prepareSearch ().setQuery (matchAllQuery ())
11180 .setPostFilter (
@@ -115,8 +84,15 @@ public void onFailure(Exception e) {
11584 3L
11685 );
11786 }
118- safeAwait (latch );
119- assertThat (hasErrors .get (), is (false ));
87+ assertResponse (hotThreadsFuture , nodeHotThreads -> {
88+ assertThat (nodeHotThreads , notNullValue ());
89+ Map <String , NodeHotThreads > nodesMap = nodeHotThreads .getNodesMap ();
90+ assertThat (nodeHotThreads .failures (), empty ());
91+ assertThat (nodesMap .size (), equalTo (cluster ().size ()));
92+ for (NodeHotThreads ht : nodeHotThreads .getNodes ()) {
93+ assertNotNull (ht .getHotThreads ());
94+ }
95+ });
12096 }
12197 }
12298
0 commit comments