2222import org .elasticsearch .action .ActionListener ;
2323import org .elasticsearch .action .delete .DeleteRequest ;
2424import org .elasticsearch .action .delete .DeleteResponse ;
25+ import org .elasticsearch .action .get .GetRequest ;
2526import org .elasticsearch .action .index .IndexRequest ;
26- import org .elasticsearch .action .index .IndexRequestBuilder ;
2727import org .elasticsearch .action .index .IndexResponse ;
2828import org .elasticsearch .client .ESRestHighLevelClientTestCase ;
2929import org .elasticsearch .client .Response ;
4545import java .util .Map ;
4646
4747import static java .util .Collections .emptyMap ;
48+ import static java .util .Collections .singletonMap ;
4849import static org .elasticsearch .cluster .metadata .IndexMetaData .SETTING_NUMBER_OF_REPLICAS ;
4950import static org .elasticsearch .cluster .metadata .IndexMetaData .SETTING_NUMBER_OF_SHARDS ;
5051
@@ -69,7 +70,7 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
6970 public void testCreateIndex () throws IOException {
7071 RestClient restClient = client ();
7172 {
72- //tag::migration-create-inded
73+ //tag::migration-create-index
7374 Settings indexSettings = Settings .builder () // <1>
7475 .put (SETTING_NUMBER_OF_SHARDS , 1 )
7576 .put (SETTING_NUMBER_OF_REPLICAS , 0 )
@@ -97,7 +98,7 @@ public void testCreateIndex() throws IOException {
9798 if (response .getStatusLine ().getStatusCode () != HttpStatus .SC_OK ) {
9899 // <7>
99100 }
100- //end::migration-create-inded
101+ //end::migration-create-index
101102 assertEquals (200 , response .getStatusLine ().getStatusCode ());
102103 }
103104 }
@@ -106,7 +107,8 @@ public void testClusterHealth() throws IOException {
106107 RestClient restClient = client ();
107108 {
108109 //tag::migration-cluster-health
109- Response response = restClient .performRequest ("GET" , "/_cluster/health" ); // <1>
110+ Map <String , String > parameters = singletonMap ("wait_for_status" , "green" );
111+ Response response = restClient .performRequest ("GET" , "/_cluster/health" , parameters ); // <1>
110112
111113 ClusterHealthStatus healthStatus ;
112114 try (InputStream is = response .getEntity ().getContent ()) { // <2>
@@ -122,7 +124,7 @@ public void testClusterHealth() throws IOException {
122124 }
123125 }
124126
125- public void testRequests () throws IOException {
127+ public void testRequests () throws Exception {
126128 RestHighLevelClient client = highLevelClient ();
127129 {
128130 //tag::migration-request-ctor
@@ -135,13 +137,6 @@ public void testRequests() throws IOException {
135137 //end::migration-request-ctor-execution
136138 assertEquals (RestStatus .CREATED , response .status ());
137139 }
138- {
139- //tag::migration-request-sync-execution
140- DeleteRequest request = new DeleteRequest ("index" , "doc" , "id" );
141- DeleteResponse response = client .delete (request ); // <1>
142- //end::migration-request-sync-execution
143- assertEquals (RestStatus .OK , response .status ());
144- }
145140 {
146141 //tag::migration-request-async-execution
147142 DeleteRequest request = new DeleteRequest ("index" , "doc" , "id" ); // <1>
@@ -157,6 +152,14 @@ public void onFailure(Exception e) {
157152 }
158153 });
159154 //end::migration-request-async-execution
155+ assertBusy (() -> assertFalse (client .exists (new GetRequest ("index" , "doc" , "id" ))));
156+ }
157+ {
158+ //tag::migration-request-sync-execution
159+ DeleteRequest request = new DeleteRequest ("index" , "doc" , "id" );
160+ DeleteResponse response = client .delete (request ); // <1>
161+ //end::migration-request-sync-execution
162+ assertEquals (RestStatus .NOT_FOUND , response .status ());
160163 }
161164 }
162165}
0 commit comments