/** Test case for issue #86: https://github.com/elasticsearch/elasticsearch-cloud-aws/issues/86 */ @Test public void testNonExistingRepo_86() { Client client = client(); logger.info( "--> creating s3 repository with bucket[{}] and path [{}]", internalCluster().getInstance(Settings.class).get("repositories.s3.bucket"), basePath); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("s3") .setSettings(Settings.settingsBuilder().put("base_path", basePath)) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> restore non existing snapshot"); try { client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "no-existing-snapshot") .setWaitForCompletion(true) .execute() .actionGet(); fail("Shouldn't be here"); } catch (SnapshotMissingException ex) { // Expected } }
/** For issue #86: https://github.com/elasticsearch/elasticsearch-cloud-aws/issues/86 */ @Test public void testGetDeleteNonExistingSnapshot_86() { ClusterAdminClient client = client().admin().cluster(); logger.info("--> creating s3 repository without any path"); PutRepositoryResponse putRepositoryResponse = client .preparePutRepository("test-repo") .setType("s3") .setSettings(Settings.settingsBuilder().put("base_path", basePath)) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); try { client.prepareGetSnapshots("test-repo").addSnapshots("no-existing-snapshot").get(); fail("Shouldn't be here"); } catch (SnapshotMissingException ex) { // Expected } try { client.prepareDeleteSnapshot("test-repo", "no-existing-snapshot").get(); fail("Shouldn't be here"); } catch (SnapshotMissingException ex) { // Expected } }
@Test public void testRepositoryWithCustomCredentials() { Client client = client(); Settings bucketSettings = internalCluster() .getInstance(Settings.class) .getByPrefix("repositories.s3.private-bucket."); logger.info( "--> creating s3 repository with bucket[{}] and path [{}]", bucketSettings.get("bucket"), basePath); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("s3") .setSettings( Settings.settingsBuilder() .put("base_path", basePath) .put("region", bucketSettings.get("region")) .put("access_key", bucketSettings.get("access_key")) .put("secret_key", bucketSettings.get("secret_key")) .put("bucket", bucketSettings.get("bucket"))) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); assertRepositoryIsOperational(client, "test-repo"); }
@Test @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch-cloud-aws/issues/211") public void testRepositoryInRemoteRegion() { Client client = client(); Settings settings = internalCluster().getInstance(Settings.class); Settings bucketSettings = settings.getByPrefix("repositories.s3.remote-bucket."); logger.info( "--> creating s3 repository with bucket[{}] and path [{}]", bucketSettings.get("bucket"), basePath); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("s3") .setSettings( Settings.settingsBuilder() .put("base_path", basePath) .put("bucket", bucketSettings.get("bucket")) .put("region", bucketSettings.get("region"))) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); assertRepositoryIsOperational(client, "test-repo"); }
/** * Test case for issue #23: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/23 */ @Test public void testNonExistingRepo_23() { Client client = client(); logger.info("--> creating azure repository with path [{}]", getRepositoryPath()); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("azure") .setSettings( Settings.settingsBuilder() .put(Repository.CONTAINER, getContainerName()) .put(Repository.BASE_PATH, getRepositoryPath()) .put(Repository.CHUNK_SIZE, randomIntBetween(1000, 10000))) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> restore non existing snapshot"); try { client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "no-existing-snapshot") .setWaitForCompletion(true) .execute() .actionGet(); fail("Shouldn't be here"); } catch (SnapshotMissingException ex) { // Expected } }
/** For issue #28: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/28 */ @Test public void testGetDeleteNonExistingSnapshot_28() throws StorageException, URISyntaxException { ClusterAdminClient client = client().admin().cluster(); logger.info("--> creating azure repository without any path"); PutRepositoryResponse putRepositoryResponse = client .preparePutRepository("test-repo") .setType("azure") .setSettings(Settings.settingsBuilder().put(Repository.CONTAINER, getContainerName())) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); try { client.prepareGetSnapshots("test-repo").addSnapshots("nonexistingsnapshotname").get(); fail("Shouldn't be here"); } catch (SnapshotMissingException ex) { // Expected } try { client.prepareDeleteSnapshot("test-repo", "nonexistingsnapshotname").get(); fail("Shouldn't be here"); } catch (SnapshotMissingException ex) { // Expected } }
@Test(expected = RepositoryVerificationException.class) @Ignore public void testWrongPath() { Client client = client(); logger.info("--> creating hdfs repository with path [{}]", path); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("hdfs") .setSettings( Settings.settingsBuilder() .put("uri", "file://./") .put("path", path + "a@b$c#11:22") .put("chunk_size", randomIntBetween(100, 1000) + "k") .put("compress", randomBoolean())) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); }
@Test public void testSimpleWorkflow() { Client client = client(); logger.info("--> creating hdfs repository with path [{}]", path); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("hdfs") .setSettings( Settings.settingsBuilder() .put("uri", "file://./") .put("path", path) .put("conf", "additional-cfg.xml, conf-2.xml") .put("chunk_size", randomIntBetween(100, 1000) + "k") .put("compress", randomBoolean())) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); logger.info("--> indexing some data"); for (int i = 0; i < 100; i++) { index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i); index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i); index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i); } refresh(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client .admin() .cluster() .prepareCreateSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-*", "-test-idx-3") .get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat( createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); assertThat( client .admin() .cluster() .prepareGetSnapshots("test-repo") .setSnapshots("test-snap") .get() .getSnapshots() .get(0) .state(), equalTo(SnapshotState.SUCCESS)); logger.info("--> delete some data"); for (int i = 0; i < 50; i++) { client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get(); } for (int i = 50; i < 100; i++) { client.prepareDelete("test-idx-2", "doc", Integer.toString(i)).get(); } for (int i = 0; i < 100; i += 2) { client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get(); } refresh(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); logger.info("--> close indices"); client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get(); logger.info("--> restore all indices from the snapshot"); RestoreSnapshotResponse restoreSnapshotResponse = client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .execute() .actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); // Test restore after index deletion logger.info("--> delete indices"); wipeIndices("test-idx-1", "test-idx-2"); logger.info("--> restore one index after deletion"); restoreSnapshotResponse = client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-*", "-test-idx-2") .execute() .actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); ClusterState clusterState = client.admin().cluster().prepareState().get().getState(); assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true)); assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false)); }
@Test @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch-cloud-aws/issues/211") public void testSimpleWorkflow() { Client client = client(); logger.info( "--> creating s3 repository with bucket[{}] and path [{}]", internalCluster().getInstance(Settings.class).get("repositories.s3.bucket"), basePath); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("s3") .setSettings( Settings.settingsBuilder() .put("base_path", basePath) .put("chunk_size", randomIntBetween(1000, 10000))) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); logger.info("--> indexing some data"); for (int i = 0; i < 100; i++) { index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i); index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i); index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i); } refresh(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client .admin() .cluster() .prepareCreateSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-*", "-test-idx-3") .get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat( createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); assertThat( client .admin() .cluster() .prepareGetSnapshots("test-repo") .setSnapshots("test-snap") .get() .getSnapshots() .get(0) .state(), equalTo(SnapshotState.SUCCESS)); logger.info("--> delete some data"); for (int i = 0; i < 50; i++) { client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get(); } for (int i = 50; i < 100; i++) { client.prepareDelete("test-idx-2", "doc", Integer.toString(i)).get(); } for (int i = 0; i < 100; i += 2) { client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get(); } refresh(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); logger.info("--> close indices"); client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get(); logger.info("--> restore all indices from the snapshot"); RestoreSnapshotResponse restoreSnapshotResponse = client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .execute() .actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); // Test restore after index deletion logger.info("--> delete indices"); cluster().wipeIndices("test-idx-1", "test-idx-2"); logger.info("--> restore one index after deletion"); restoreSnapshotResponse = client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-*", "-test-idx-2") .execute() .actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); ClusterState clusterState = client.admin().cluster().prepareState().get().getState(); assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true)); assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false)); }
@Test @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch-cloud-aws/issues/211") public void testEncryption() { Client client = client(); logger.info( "--> creating s3 repository with bucket[{}] and path [{}]", internalCluster().getInstance(Settings.class).get("repositories.s3.bucket"), basePath); PutRepositoryResponse putRepositoryResponse = client .admin() .cluster() .preparePutRepository("test-repo") .setType("s3") .setSettings( Settings.settingsBuilder() .put("base_path", basePath) .put("chunk_size", randomIntBetween(1000, 10000)) .put("server_side_encryption", true)) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); logger.info("--> indexing some data"); for (int i = 0; i < 100; i++) { index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i); index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i); index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i); } refresh(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client .admin() .cluster() .prepareCreateSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-*", "-test-idx-3") .get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat( createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); assertThat( client .admin() .cluster() .prepareGetSnapshots("test-repo") .setSnapshots("test-snap") .get() .getSnapshots() .get(0) .state(), equalTo(SnapshotState.SUCCESS)); Settings settings = internalCluster().getInstance(Settings.class); Settings bucket = settings.getByPrefix("repositories.s3."); AmazonS3 s3Client = internalCluster() .getInstance(AwsS3Service.class) .client( null, null, bucket.get("region", settings.get("repositories.s3.region")), bucket.get("access_key", settings.get("cloud.aws.access_key")), bucket.get("secret_key", settings.get("cloud.aws.secret_key"))); String bucketName = bucket.get("bucket"); logger.info("--> verify encryption for bucket [{}], prefix [{}]", bucketName, basePath); List<S3ObjectSummary> summaries = s3Client.listObjects(bucketName, basePath).getObjectSummaries(); for (S3ObjectSummary summary : summaries) { assertThat( s3Client.getObjectMetadata(bucketName, summary.getKey()).getSSEAlgorithm(), equalTo("AES256")); } logger.info("--> delete some data"); for (int i = 0; i < 50; i++) { client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get(); } for (int i = 50; i < 100; i++) { client.prepareDelete("test-idx-2", "doc", Integer.toString(i)).get(); } for (int i = 0; i < 100; i += 2) { client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get(); } refresh(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); logger.info("--> close indices"); client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get(); logger.info("--> restore all indices from the snapshot"); RestoreSnapshotResponse restoreSnapshotResponse = client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .execute() .actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); // Test restore after index deletion logger.info("--> delete indices"); cluster().wipeIndices("test-idx-1", "test-idx-2"); logger.info("--> restore one index after deletion"); restoreSnapshotResponse = client .admin() .cluster() .prepareRestoreSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-*", "-test-idx-2") .execute() .actionGet(); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); ClusterState clusterState = client.admin().cluster().prepareState().get().getState(); assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true)); assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false)); }
/** For issue #26: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/26 */ @Test public void testListBlobs_26() throws StorageException, URISyntaxException { createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); logger.info("--> indexing some data"); for (int i = 0; i < 100; i++) { index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i); index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i); index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i); } refresh(); ClusterAdminClient client = client().admin().cluster(); logger.info("--> creating azure repository without any path"); PutRepositoryResponse putRepositoryResponse = client .preparePutRepository("test-repo") .setType("azure") .setSettings(Settings.settingsBuilder().put(Repository.CONTAINER, getContainerName())) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); // Get all snapshots - should be empty assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(0)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client .prepareCreateSnapshot("test-repo", "test-snap-26") .setWaitForCompletion(true) .setIndices("test-idx-*") .get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); // Get all snapshots - should have one assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(1)); // Clean the snapshot client.prepareDeleteSnapshot("test-repo", "test-snap-26").get(); client.prepareDeleteRepository("test-repo").get(); logger.info("--> creating azure repository path [{}]", getRepositoryPath()); putRepositoryResponse = client .preparePutRepository("test-repo") .setType("azure") .setSettings( Settings.settingsBuilder() .put(Repository.CONTAINER, getContainerName()) .put(Repository.BASE_PATH, getRepositoryPath())) .get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); // Get all snapshots - should be empty assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(0)); logger.info("--> snapshot"); createSnapshotResponse = client .prepareCreateSnapshot("test-repo", "test-snap-26") .setWaitForCompletion(true) .setIndices("test-idx-*") .get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); // Get all snapshots - should have one assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(1)); }
@Test public void testMultipleRepositories() { Client client = client(); logger.info("--> creating azure repository with path [{}]", getRepositoryPath()); PutRepositoryResponse putRepositoryResponse1 = client .admin() .cluster() .preparePutRepository("test-repo1") .setType("azure") .setSettings( Settings.settingsBuilder() .put(Repository.CONTAINER, getContainerName().concat("-1")) .put(Repository.BASE_PATH, getRepositoryPath()) .put(Repository.CHUNK_SIZE, randomIntBetween(1000, 10000))) .get(); assertThat(putRepositoryResponse1.isAcknowledged(), equalTo(true)); PutRepositoryResponse putRepositoryResponse2 = client .admin() .cluster() .preparePutRepository("test-repo2") .setType("azure") .setSettings( Settings.settingsBuilder() .put(Repository.CONTAINER, getContainerName().concat("-2")) .put(Repository.BASE_PATH, getRepositoryPath()) .put(Repository.CHUNK_SIZE, randomIntBetween(1000, 10000))) .get(); assertThat(putRepositoryResponse2.isAcknowledged(), equalTo(true)); createIndex("test-idx-1", "test-idx-2"); ensureGreen(); logger.info("--> indexing some data"); for (int i = 0; i < 100; i++) { index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i); index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i); } refresh(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); logger.info("--> snapshot 1"); CreateSnapshotResponse createSnapshotResponse1 = client .admin() .cluster() .prepareCreateSnapshot("test-repo1", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-1") .get(); assertThat(createSnapshotResponse1.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat( createSnapshotResponse1.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse1.getSnapshotInfo().totalShards())); logger.info("--> snapshot 2"); CreateSnapshotResponse createSnapshotResponse2 = client .admin() .cluster() .prepareCreateSnapshot("test-repo2", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-2") .get(); assertThat(createSnapshotResponse2.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat( createSnapshotResponse2.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse2.getSnapshotInfo().totalShards())); assertThat( client .admin() .cluster() .prepareGetSnapshots("test-repo1") .setSnapshots("test-snap") .get() .getSnapshots() .get(0) .state(), equalTo(SnapshotState.SUCCESS)); assertThat( client .admin() .cluster() .prepareGetSnapshots("test-repo2") .setSnapshots("test-snap") .get() .getSnapshots() .get(0) .state(), equalTo(SnapshotState.SUCCESS)); // Test restore after index deletion logger.info("--> delete indices"); cluster().wipeIndices("test-idx-1", "test-idx-2"); logger.info("--> restore one index after deletion from snapshot 1"); RestoreSnapshotResponse restoreSnapshotResponse1 = client .admin() .cluster() .prepareRestoreSnapshot("test-repo1", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-1") .execute() .actionGet(); assertThat(restoreSnapshotResponse1.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); ClusterState clusterState = client.admin().cluster().prepareState().get().getState(); assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true)); assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false)); logger.info("--> restore other index after deletion from snapshot 2"); RestoreSnapshotResponse restoreSnapshotResponse2 = client .admin() .cluster() .prepareRestoreSnapshot("test-repo2", "test-snap") .setWaitForCompletion(true) .setIndices("test-idx-2") .execute() .actionGet(); assertThat(restoreSnapshotResponse2.getRestoreInfo().totalShards(), greaterThan(0)); ensureGreen(); assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); clusterState = client.admin().cluster().prepareState().get().getState(); assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true)); assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(true)); }