[DOCS] Adapt indices exists docs after recent listener changes

This commit is contained in:
javanna 2018-02-02 11:46:05 +01:00 committed by Luca Cavanna
parent 897ef458f3
commit 174e243f83
2 changed files with 48 additions and 39 deletions

View File

@ -19,7 +19,6 @@
package org.elasticsearch.client.documentation;
import org.apache.http.Header;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.LatchedActionListener;
@ -99,9 +98,8 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
request.indicesOptions(indicesOptions); // <5>
// end::indices-exists-request-optionals
Header[] headers = new Header[0];
// tag::indices-exists-response
boolean exists = client.indices().exists(request, headers);
boolean exists = client.indices().exists(request);
// end::indices-exists-response
assertTrue(exists);
}
@ -118,24 +116,27 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
{
GetIndexRequest request = new GetIndexRequest();
request.indices("twitter");
Header[] headers = new Header[0];
// tag::indices-exists-execute-listener
ActionListener<Boolean> listener = new ActionListener<Boolean>() {
@Override
public void onResponse(Boolean exists) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::indices-exists-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::indices-exists-async
client.indices().existsAsync(
request,
new ActionListener<Boolean>() {
@Override
public void onResponse(Boolean exists) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
},
headers
);
client.indices().existsAsync(request, listener); // <1>
// end::indices-exists-async
}
}
@ -188,7 +189,6 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void testDeleteIndexAsync() throws Exception {
final RestHighLevelClient client = highLevelClient();
@ -216,7 +216,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::delete-index-execute-async
client.indices().deleteAsync(request, listener); // <1>
@ -365,7 +365,6 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void testCreateIndexAsync() throws Exception {
final RestHighLevelClient client = highLevelClient();
@ -388,7 +387,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::create-index-execute-async
client.indices().createAsync(request, listener); // <1>
@ -494,7 +493,6 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void testPutMappingAsync() throws Exception {
final RestHighLevelClient client = highLevelClient();
@ -522,7 +520,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::put-mapping-execute-async
client.indices().putMappingAsync(request, listener); // <1>
@ -532,7 +530,6 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void testOpenIndex() throws Exception {
RestHighLevelClient client = highLevelClient();
@ -590,7 +587,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::open-index-execute-async
client.indices().openAsync(request, listener); // <1>
@ -613,7 +610,6 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void testCloseIndex() throws Exception {
RestHighLevelClient client = highLevelClient();
@ -665,7 +661,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::close-index-execute-async
client.indices().closeAsync(request, listener); // <1>
@ -675,7 +671,6 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void testExistsAlias() throws Exception {
RestHighLevelClient client = highLevelClient();
@ -728,7 +723,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::exists-alias-execute-async
client.indices().existsAliasAsync(request, listener); // <1>
@ -808,7 +803,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::update-aliases-execute-async
client.indices().updateAliasesAsync(request, listener); // <1>
@ -880,7 +875,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::shrink-index-execute-async
client.indices().shrinkAsync(request, listener); // <1>
@ -950,7 +945,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener(listener, latch);
listener = new LatchedActionListener<>(listener, latch);
// tag::split-index-execute-async
client.indices().splitAsync(request,listener); // <1>

View File

@ -35,16 +35,30 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-res
[[java-rest-high-indices-async]]
==== Asynchronous Execution
As is the case with many other APIs, the Indices Exists API has an asynchronous variant in the
Java High Level REST Client.
The asynchronous variant returns void and accept an extra `ActionListener` as an argument.
The provided listener will be notified upon request completion or failure.
The asynchronous execution of an indices exists request requires both the
`GetIndexRequest` instance and an `ActionListener` instance to be passed
to the asynchronous method:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-async]
--------------------------------------------------
<1> Called when the execution is successfully completed. The response is provided as an argument
<1> The `GetIndexRequest` to execute and the `ActionListener` to use when
the execution completes
The asynchronous method does not block and returns immediately. Once it is
completed the `ActionListener` is called back using the `onResponse` method
if the execution successfully completed or using the `onFailure` method if
it failed.
A typical listener for the Indices Exists looks like:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-execute-listener]
--------------------------------------------------
<1> Called when the execution is successfully completed. The response is
provided as an argument
<2> Called in case of failure. The raised exception is provided as an argument
[[java-rest-high-indices-exists-response]]