|
@@ -25,6 +25,9 @@ import org.elasticsearch.action.LatchedActionListener;
|
|
|
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
+import org.elasticsearch.common.Booleans;
|
|
|
+import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
|
|
|
+import org.elasticsearch.protocol.xpack.license.DeleteLicenseResponse;
|
|
|
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
|
|
|
import org.elasticsearch.protocol.xpack.license.GetLicenseResponse;
|
|
|
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
|
|
@@ -47,7 +50,7 @@ import static org.hamcrest.Matchers.startsWith;
|
|
|
*/
|
|
|
public class LicensingDocumentationIT extends ESRestHighLevelClientTestCase {
|
|
|
|
|
|
- public void testPutLicense() throws Exception {
|
|
|
+ public void testLicense() throws Exception {
|
|
|
assumeTrue("License is only valid when tested against snapshot/test builds", Build.CURRENT.isSnapshot());
|
|
|
RestHighLevelClient client = highLevelClient();
|
|
|
String license = "{\"license\": {\"uid\":\"893361dc-9749-4997-93cb-802e3d7fa4a8\",\"type\":\"gold\"," +
|
|
@@ -86,7 +89,7 @@ public class LicensingDocumentationIT extends ESRestHighLevelClientTestCase {
|
|
|
// tag::put-license-execute-listener
|
|
|
ActionListener<PutLicenseResponse> listener = new ActionListener<PutLicenseResponse>() {
|
|
|
@Override
|
|
|
- public void onResponse(PutLicenseResponse indexResponse) {
|
|
|
+ public void onResponse(PutLicenseResponse putLicenseResponse) {
|
|
|
// <1>
|
|
|
}
|
|
|
|
|
@@ -108,6 +111,51 @@ public class LicensingDocumentationIT extends ESRestHighLevelClientTestCase {
|
|
|
|
|
|
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
|
|
}
|
|
|
+
|
|
|
+ // we cannot actually delete the license, otherwise the remaining tests won't work
|
|
|
+ if (Booleans.isTrue("true")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ {
|
|
|
+ //tag::delete-license-execute
|
|
|
+ DeleteLicenseRequest request = new DeleteLicenseRequest();
|
|
|
+
|
|
|
+ DeleteLicenseResponse response = client.license().deleteLicense(request, RequestOptions.DEFAULT);
|
|
|
+ //end::delete-license-execute
|
|
|
+
|
|
|
+ //tag::delete-license-response
|
|
|
+ boolean acknowledged = response.isAcknowledged(); // <1>
|
|
|
+ //end::delete-license-response
|
|
|
+
|
|
|
+ assertTrue(acknowledged);
|
|
|
+ }
|
|
|
+ {
|
|
|
+ DeleteLicenseRequest request = new DeleteLicenseRequest();
|
|
|
+ // tag::delete-license-execute-listener
|
|
|
+ ActionListener<DeleteLicenseResponse> listener = new ActionListener<DeleteLicenseResponse>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(DeleteLicenseResponse deleteLicenseResponse) {
|
|
|
+ // <1>
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Exception e) {
|
|
|
+ // <2>
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // end::delete-license-execute-listener
|
|
|
+
|
|
|
+ // Replace the empty listener by a blocking listener in test
|
|
|
+ final CountDownLatch latch = new CountDownLatch(1);
|
|
|
+ listener = new LatchedActionListener<>(listener, latch);
|
|
|
+
|
|
|
+ // tag::delete-license-execute-async
|
|
|
+ client.license().deleteLicenseAsync(
|
|
|
+ request, RequestOptions.DEFAULT, listener); // <1>
|
|
|
+ // end::delete-license-execute-async
|
|
|
+
|
|
|
+ assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void testGetLicense() throws Exception {
|