Skip to content

Commit 10cee42

Browse files
committed
[Test] Fix MigrationDocumentationIT.testClusterHealth (#27774)
Closes #27754
1 parent daaa934 commit 10cee42

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.elasticsearch.action.ActionListener;
2323
import org.elasticsearch.action.delete.DeleteRequest;
2424
import org.elasticsearch.action.delete.DeleteResponse;
25+
import org.elasticsearch.action.get.GetRequest;
2526
import org.elasticsearch.action.index.IndexRequest;
26-
import org.elasticsearch.action.index.IndexRequestBuilder;
2727
import org.elasticsearch.action.index.IndexResponse;
2828
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
2929
import org.elasticsearch.client.Response;
@@ -45,6 +45,7 @@
4545
import java.util.Map;
4646

4747
import static java.util.Collections.emptyMap;
48+
import static java.util.Collections.singletonMap;
4849
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
4950
import 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
}

docs/java-rest/high-level/migration.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ The same operation executed with the low-level client could be:
299299

300300
["source","java",subs="attributes,callouts,macros"]
301301
--------------------------------------------------
302-
include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-create-inded]
302+
include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-create-index]
303303
--------------------------------------------------
304304
<1> Define the settings of the index
305305
<2> Define the body of the HTTP request using a `XContentBuilder` with JSON format
@@ -338,8 +338,8 @@ With the low-level client, the code can be changed to:
338338
--------------------------------------------------
339339
include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-cluster-health]
340340
--------------------------------------------------
341-
<1> Call the cluster's health REST endpoint using the default paramaters
342-
and gets back a `Response` object
341+
<1> Call the cluster's health REST endpoint and wait for the cluster health to become green,
342+
then get back a `Response` object.
343343
<2> Retrieve an `InputStream` object in order to read the response's content
344344
<3> Parse the response's content using Elasticsearch's helper class `XContentHelper`. This
345345
helper requires the content type of the response to be passed as an argument and returns

0 commit comments

Comments
 (0)