24
24
import java .io .IOException ;
25
25
import java .util .ArrayList ;
26
26
import java .util .List ;
27
+ import java .util .concurrent .CountDownLatch ;
27
28
import java .util .concurrent .TimeUnit ;
28
29
import java .util .stream .Collectors ;
29
30
@@ -71,7 +72,7 @@ public void testCreateAndDeletePit() throws IOException {
71
72
assertTrue (deletePitResponse .getDeletePitResults ().get (0 ).getPitId ().equals (createPitResponse .getId ()));
72
73
}
73
74
74
- public void testDeleteAllAndListAllPits () throws IOException {
75
+ public void testDeleteAllAndListAllPits () throws IOException , InterruptedException {
75
76
CreatePitRequest pitRequest = new CreatePitRequest (new TimeValue (1 , TimeUnit .DAYS ), true , "index" );
76
77
CreatePitResponse pitResponse = execute (pitRequest , highLevelClient ()::createPit , highLevelClient ()::createPitAsync );
77
78
CreatePitResponse pitResponse1 = execute (pitRequest , highLevelClient ()::createPit , highLevelClient ()::createPitAsync );
@@ -90,16 +91,19 @@ public void testDeleteAllAndListAllPits() throws IOException {
90
91
List <String > pits = getAllPitResponse .getPitInfos ().stream ().map (r -> r .getPitId ()).collect (Collectors .toList ());
91
92
assertTrue (pits .contains (pitResponse .getId ()));
92
93
assertTrue (pits .contains (pitResponse1 .getId ()));
94
+ CountDownLatch countDownLatch = new CountDownLatch (1 );
93
95
ActionListener <DeletePitResponse > deletePitListener = new ActionListener <>() {
94
96
@ Override
95
97
public void onResponse (DeletePitResponse response ) {
98
+ countDownLatch .countDown ();
96
99
for (DeletePitInfo deletePitInfo : response .getDeletePitResults ()) {
97
100
assertTrue (deletePitInfo .isSuccessful ());
98
101
}
99
102
}
100
103
101
104
@ Override
102
105
public void onFailure (Exception e ) {
106
+ countDownLatch .countDown ();
103
107
if (!(e instanceof OpenSearchStatusException )) {
104
108
throw new AssertionError ("Delete all failed" );
105
109
}
@@ -123,6 +127,7 @@ public void onFailure(Exception e) {
123
127
};
124
128
highLevelClient ().getAllPitsAsync (RequestOptions .DEFAULT , getPitsListener );
125
129
highLevelClient ().deleteAllPitsAsync (RequestOptions .DEFAULT , deletePitListener );
130
+ countDownLatch .await (10 , TimeUnit .SECONDS );
126
131
// validate no pits case
127
132
getAllPitResponse = highLevelClient ().getAllPits (RequestOptions .DEFAULT );
128
133
assertTrue (getAllPitResponse .getPitInfos ().size () == 0 );
0 commit comments