[Test] Fix MigrationDocumentationIT.testClusterHealth (#27774)

Closes #27754
This commit is contained in:
Tanguy Leroux 2017-12-13 16:47:01 +01:00 committed by GitHub
parent b69923f112
commit 28f6512319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View File

@ -26,6 +26,7 @@ import org.apache.http.nio.entity.NStringEntity;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
@ -43,6 +44,7 @@ import java.io.InputStream;
import java.util.Map;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
@ -67,7 +69,7 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
public void testCreateIndex() throws IOException {
RestHighLevelClient client = highLevelClient();
{
//tag::migration-create-inded
//tag::migration-create-index
Settings indexSettings = Settings.builder() // <1>
.put(SETTING_NUMBER_OF_SHARDS, 1)
.put(SETTING_NUMBER_OF_REPLICAS, 0)
@ -95,7 +97,7 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
// <7>
}
//end::migration-create-inded
//end::migration-create-index
assertEquals(200, response.getStatusLine().getStatusCode());
}
}
@ -104,7 +106,8 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
RestHighLevelClient client = highLevelClient();
{
//tag::migration-cluster-health
Response response = client.getLowLevelClient().performRequest("GET", "/_cluster/health"); // <1>
Map<String, String> parameters = singletonMap("wait_for_status", "green");
Response response = client.getLowLevelClient().performRequest("GET", "/_cluster/health", parameters); // <1>
ClusterHealthStatus healthStatus;
try (InputStream is = response.getEntity().getContent()) { // <2>
@ -120,7 +123,7 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
}
}
public void testRequests() throws IOException {
public void testRequests() throws Exception {
RestHighLevelClient client = highLevelClient();
{
//tag::migration-request-ctor
@ -133,13 +136,6 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
//end::migration-request-ctor-execution
assertEquals(RestStatus.CREATED, response.status());
}
{
//tag::migration-request-sync-execution
DeleteRequest request = new DeleteRequest("index", "doc", "id");
DeleteResponse response = client.delete(request); // <1>
//end::migration-request-sync-execution
assertEquals(RestStatus.OK, response.status());
}
{
//tag::migration-request-async-execution
DeleteRequest request = new DeleteRequest("index", "doc", "id"); // <1>
@ -155,6 +151,14 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
}
});
//end::migration-request-async-execution
assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "doc", "id"))));
}
{
//tag::migration-request-sync-execution
DeleteRequest request = new DeleteRequest("index", "doc", "id");
DeleteResponse response = client.delete(request); // <1>
//end::migration-request-sync-execution
assertEquals(RestStatus.NOT_FOUND, response.status());
}
}
}

View File

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