|
29 | 29 | import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
|
30 | 30 | import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
|
31 | 31 | import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
|
| 32 | +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; |
| 33 | +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; |
| 34 | +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; |
| 35 | +import org.elasticsearch.action.support.IndicesOptions; |
32 | 36 | import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
|
33 | 37 | import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse;
|
34 | 38 | import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
|
41 | 45 | import org.elasticsearch.common.unit.TimeValue;
|
42 | 46 | import org.elasticsearch.common.xcontent.XContentType;
|
43 | 47 | import org.elasticsearch.repositories.fs.FsRepository;
|
| 48 | +import org.elasticsearch.rest.RestStatus; |
44 | 49 |
|
45 | 50 | import java.io.IOException;
|
46 | 51 | import java.util.HashMap;
|
@@ -367,6 +372,90 @@ public void onFailure(Exception e) {
|
367 | 372 | }
|
368 | 373 | }
|
369 | 374 |
|
| 375 | + public void testSnapshotCreate() throws IOException { |
| 376 | + RestHighLevelClient client = highLevelClient(); |
| 377 | + |
| 378 | + CreateIndexRequest createIndexRequest = new CreateIndexRequest("test-index0"); |
| 379 | + client.indices().create(createIndexRequest, RequestOptions.DEFAULT); |
| 380 | + createIndexRequest = new CreateIndexRequest("test-index1"); |
| 381 | + client.indices().create(createIndexRequest, RequestOptions.DEFAULT); |
| 382 | + |
| 383 | + createTestRepositories(); |
| 384 | + |
| 385 | + // tag::create-snapshot-request |
| 386 | + CreateSnapshotRequest request = new CreateSnapshotRequest(); |
| 387 | + // end::create-snapshot-request |
| 388 | + |
| 389 | + // tag::create-snapshot-request-repositoryName |
| 390 | + request.repository(repositoryName); // <1> |
| 391 | + // end::create-snapshot-request-repositoryName |
| 392 | + // tag::create-snapshot-request-snapshotName |
| 393 | + request.snapshot(snapshotName); // <1> |
| 394 | + // end::create-snapshot-request-snapshotName |
| 395 | + // tag::create-snapshot-request-indices |
| 396 | + request.indices("test-index0", "test-index1"); // <1> |
| 397 | + // end::create-snapshot-request-indices |
| 398 | + // tag::create-snapshot-request-indicesOptions |
| 399 | + request.indicesOptions(IndicesOptions.fromOptions(false, false, true, true)); // <1> |
| 400 | + // end::create-snapshot-request-indicesOptions |
| 401 | + // tag::create-snapshot-request-partial |
| 402 | + request.partial(false); // <1> |
| 403 | + // end::create-snapshot-request-partial |
| 404 | + // tag::create-snapshot-request-includeGlobalState |
| 405 | + request.includeGlobalState(true); // <1> |
| 406 | + // end::create-snapshot-request-includeGlobalState |
| 407 | + |
| 408 | + // tag::create-snapshot-request-masterTimeout |
| 409 | + request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> |
| 410 | + request.masterNodeTimeout("1m"); // <2> |
| 411 | + // end::create-snapshot-request-masterTimeout |
| 412 | + // tag::create-snapshot-request-waitForCompletion |
| 413 | + request.waitForCompletion(true); // <1> |
| 414 | + // end::create-snapshot-request-waitForCompletion |
| 415 | + |
| 416 | + // tag::create-snapshot-execute |
| 417 | + CreateSnapshotResponse response = client.snapshot().createSnapshot(request, RequestOptions.DEFAULT); |
| 418 | + // end::create-snapshot-execute |
| 419 | + |
| 420 | + // tag::create-snapshot-response |
| 421 | + RestStatus status = response.status(); // <1> |
| 422 | + // end::create-snapshot-response |
| 423 | + |
| 424 | + assertEquals(RestStatus.OK, status); |
| 425 | + } |
| 426 | + |
| 427 | + public void testSnapshotCreateAsync() throws InterruptedException { |
| 428 | + RestHighLevelClient client = highLevelClient(); |
| 429 | + { |
| 430 | + CreateSnapshotRequest request = new CreateSnapshotRequest(repositoryName, snapshotName); |
| 431 | + |
| 432 | + // tag::create-snapshot-execute-listener |
| 433 | + ActionListener<CreateSnapshotResponse> listener = |
| 434 | + new ActionListener<CreateSnapshotResponse>() { |
| 435 | + @Override |
| 436 | + public void onResponse(CreateSnapshotResponse createSnapshotResponse) { |
| 437 | + // <1> |
| 438 | + } |
| 439 | + |
| 440 | + @Override |
| 441 | + public void onFailure(Exception exception) { |
| 442 | + // <2> |
| 443 | + } |
| 444 | + }; |
| 445 | + // end::create-snapshot-execute-listener |
| 446 | + |
| 447 | + // Replace the empty listener by a blocking listener in test |
| 448 | + final CountDownLatch latch = new CountDownLatch(1); |
| 449 | + listener = new LatchedActionListener<>(listener, latch); |
| 450 | + |
| 451 | + // tag::create-snapshot-execute-async |
| 452 | + client.snapshot().createSnapshotAsync(request, RequestOptions.DEFAULT, listener); // <1> |
| 453 | + // end::create-snapshot-execute-async |
| 454 | + |
| 455 | + assertTrue(latch.await(30L, TimeUnit.SECONDS)); |
| 456 | + } |
| 457 | + } |
| 458 | + |
370 | 459 | public void testSnapshotDeleteSnapshot() throws IOException {
|
371 | 460 | RestHighLevelClient client = highLevelClient();
|
372 | 461 |
|
|
0 commit comments