diff --git a/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java b/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java index 74fd434556e9c..a95fd25ec5f5e 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; public abstract class AbstractSnapshotIntegTestCase extends ESIntegTestCase { @@ -237,4 +238,11 @@ public void waitForBlockOnAnyDataNode(String repository, TimeValue timeout) thro public static void unblockNode(final String repository, final String node) { ((MockRepository)internalCluster().getInstance(RepositoriesService.class, node).repository(repository)).unblock(); } + + protected void createRepository(String repoName, String type, Path location) { + logger.info("--> creating repository"); + assertAcked(client().admin().cluster().preparePutRepository(repoName) + .setType(type) + .setSettings(Settings.builder().put("location", location))); + } } diff --git a/server/src/test/java/org/elasticsearch/snapshots/BlobStoreFormatIT.java b/server/src/test/java/org/elasticsearch/snapshots/BlobStoreFormatTests.java similarity index 98% rename from server/src/test/java/org/elasticsearch/snapshots/BlobStoreFormatIT.java rename to server/src/test/java/org/elasticsearch/snapshots/BlobStoreFormatTests.java index 63266a014d618..d8a1a1def8717 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/BlobStoreFormatIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/BlobStoreFormatTests.java @@ -39,6 +39,7 @@ import org.elasticsearch.repositories.blobstore.BlobStoreTestUtil; import org.elasticsearch.repositories.blobstore.ChecksumBlobStoreFormat; import org.elasticsearch.snapshots.mockstore.BlobContainerWrapper; +import org.elasticsearch.test.ESTestCase; import java.io.EOFException; import java.io.IOException; @@ -54,7 +55,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThan; -public class BlobStoreFormatIT extends AbstractSnapshotIntegTestCase { +public class BlobStoreFormatTests extends ESTestCase { public static final String BLOB_CODEC = "blob"; @@ -232,7 +233,7 @@ public void writeBlobAtomic(String blobName, InputStream inputStream, long blobS } protected BlobStore createTestBlobStore() throws IOException { - return new FsBlobStore(Settings.EMPTY, randomRepoPath(), false); + return new FsBlobStore(Settings.EMPTY, createTempDir(), false); } protected void randomCorruption(BlobContainer blobContainer, String blobName) throws IOException { @@ -259,5 +260,4 @@ private long checksum(byte[] buffer) throws IOException { } } } - } diff --git a/server/src/test/java/org/elasticsearch/snapshots/BlobStoreIncrementalityIT.java b/server/src/test/java/org/elasticsearch/snapshots/BlobStoreIncrementalityIT.java index e0eafe3d41703..25fc13b791c7b 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/BlobStoreIncrementalityIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/BlobStoreIncrementalityIT.java @@ -78,10 +78,7 @@ public void testIncrementalBehaviorOnPrimaryFailover() throws InterruptedExcepti final String snapshot1 = "snap-1"; final String repo = "test-repo"; - logger.info("--> creating repository"); - assertThat(client().admin().cluster().preparePutRepository(repo) - .setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).execute().actionGet().isAcknowledged(), - is(true)); + createRepository(repo, "fs", randomRepoPath()); logger.info("--> creating snapshot 1"); client().admin().cluster().prepareCreateSnapshot(repo, snapshot1).setIndices(indexName).setWaitForCompletion(true).get(); @@ -155,10 +152,7 @@ public void testForceMergeCausesFullSnapshot() throws Exception { final String snapshot1 = "snap-1"; final String repo = "test-repo"; - logger.info("--> creating repository"); - assertThat(client().admin().cluster().preparePutRepository(repo) - .setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).execute().actionGet().isAcknowledged(), - is(true)); + createRepository(repo, "fs", randomRepoPath()); logger.info("--> creating snapshot 1"); client().admin().cluster().prepareCreateSnapshot(repo, snapshot1).setIndices(indexName).setWaitForCompletion(true).get(); diff --git a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index 45ca1f0d545b5..65a783e727c2f 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -215,10 +215,7 @@ public void testExceptionWhenRestoringPersistentSettings() { setSettingValue.accept("new value"); assertSettingValue.accept("new value"); - logger.info("--> create repository"); - AcknowledgedResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).execute().actionGet(); - assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + createRepository("test-repo", "fs", randomRepoPath()); logger.info("--> start snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -266,10 +263,7 @@ public void testRestoreCustomMetadata() throws Exception { return builder.build(); }); - logger.info("--> create repository"); - AcknowledgedResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", tempDir)).execute().actionGet(); - assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + createRepository("test-repo", "fs", tempDir); logger.info("--> start snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") @@ -305,10 +299,7 @@ public void testRestoreCustomMetadata() throws Exception { logger.info("--> delete repository"); assertAcked(client.admin().cluster().prepareDeleteRepository("test-repo")); - logger.info("--> create repository"); - putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-2") - .setType("fs").setSettings(Settings.builder().put("location", tempDir)).execute().actionGet(); - assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + createRepository("test-repo-2", "fs", tempDir); logger.info("--> restore snapshot"); client.admin().cluster().prepareRestoreSnapshot("test-repo-2", "test-snap").setRestoreGlobalState(true).setIndices("-*") @@ -392,7 +383,6 @@ public void testSnapshotDuringNodeShutdown() throws Exception { refresh(); assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L)); - logger.info("--> create repository"); logger.info("--> creating repository"); AcknowledgedResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType("mock").setSettings( @@ -552,10 +542,7 @@ public void testRestoreIndexWithMissingShards() throws Exception { .put("number_of_replicas", 0)).setWaitForActiveShards(ActiveShardCount.NONE).get()); assertTrue(indexExists("test-idx-none")); - logger.info("--> creating repository"); - AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).execute().actionGet(); - assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + createRepository("test-repo", "fs", randomRepoPath()); logger.info("--> start snapshot with default settings without a closed index - should fail"); CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1") @@ -674,10 +661,8 @@ public void testRestoreIndexWithShardsMissingInLocalGateway() throws Exception { internalCluster().startNodes(2, nodeSettings); cluster().wipeIndices("_all"); - logger.info("--> create repository"); - AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).execute().actionGet(); - assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + createRepository("test-repo", "fs", randomRepoPath()); + int numberOfShards = 6; logger.info("--> create an index that will have some unallocated shards"); assertAcked(prepareCreate("test-idx", 2, Settings.builder().put("number_of_shards", numberOfShards) @@ -1102,12 +1087,8 @@ public void testSnapshotTotalAndIncrementalSizes() throws IOException { client.prepareIndex(indexName).setSource("test", "init").execute().actionGet(); } - logger.info("--> register a repository"); - final Path repoPath = randomRepoPath(); - assertAcked(client.admin().cluster().preparePutRepository(repositoryName) - .setType("fs") - .setSettings(Settings.builder().put("location", repoPath))); + createRepository(repositoryName, "fs", repoPath); logger.info("--> create a snapshot"); client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshot0) @@ -1551,5 +1532,4 @@ public EnumSet context() { return EnumSet.of(Metadata.XContentContext.GATEWAY, Metadata.XContentContext.SNAPSHOT); } } - } diff --git a/server/src/test/java/org/elasticsearch/snapshots/MetadataLoadingDuringSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/MetadataLoadingDuringSnapshotRestoreIT.java index 34761fc07ef9a..1a3fbec5830c8 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/MetadataLoadingDuringSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/MetadataLoadingDuringSnapshotRestoreIT.java @@ -27,7 +27,6 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.RepositoryMetadata; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.env.Environment; import org.elasticsearch.plugins.Plugin; @@ -71,9 +70,7 @@ public void testWhenMetadataAreLoaded() throws Exception { client().prepareIndex("others").setSource("rank", 4), client().prepareIndex("others").setSource("rank", 5)); - assertAcked(client().admin().cluster().preparePutRepository("repository") - .setType("coutingmock") - .setSettings(Settings.builder().put("location", randomRepoPath()))); + createRepository("repository", CountingMockRepositoryPlugin.TYPE, randomRepoPath()); // Creating a snapshot does not load any metadata CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("repository", "snap") @@ -204,10 +201,13 @@ public IndexMetadata getSnapshotIndexMetadata(SnapshotId snapshotId, IndexId ind /** A plugin that uses CountingMockRepository as implementation of the Repository **/ public static class CountingMockRepositoryPlugin extends MockRepository.Plugin { + + public static final String TYPE = "countingmock"; + @Override public Map getRepositories(Environment env, NamedXContentRegistry namedXContentRegistry, ClusterService clusterService) { - return Collections.singletonMap("coutingmock", + return Collections.singletonMap(TYPE, metadata -> new CountingMockRepository(metadata, env, namedXContentRegistry, clusterService)); } } diff --git a/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java b/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java index d475ead435850..085d8c30ebbe2 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java @@ -50,12 +50,7 @@ public void testRepositoryCreation() throws Exception { Path location = randomRepoPath(); - logger.info("--> creating repository"); - AcknowledgedResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-1") - .setType("fs").setSettings(Settings.builder() - .put("location", location) - ).get(); - assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + createRepository("test-repo-1", "fs", location); logger.info("--> verify the repository"); int numberOfFiles = FileSystemUtils.files(location).length; @@ -74,11 +69,7 @@ public void testRepositoryCreation() throws Exception { assertThat(repositoriesMetadata.repository("test-repo-1").type(), equalTo("fs")); logger.info("--> creating another repository"); - putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-2") - .setType("fs").setSettings(Settings.builder() - .put("location", randomRepoPath()) - ).get(); - assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + createRepository("test-repo-2", "fs", randomRepoPath()); logger.info("--> check that both repositories are in cluster state"); clusterStateResponse = client.admin().cluster().prepareState().clear().setMetadata(true).get(); diff --git a/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index 9a8d977a1cbfb..f092387c7d2dc 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -321,7 +321,7 @@ public void testSingleGetAfterRestore() throws Exception { String indexName = "testindex"; String repoName = "test-restore-snapshot-repo"; String snapshotName = "test-restore-snapshot"; - String absolutePath = randomRepoPath().toAbsolutePath().toString(); + Path absolutePath = randomRepoPath().toAbsolutePath(); logger.info("Path [{}]", absolutePath); String restoredIndexName = indexName + "-restored"; String expectedValue = "expected"; @@ -331,11 +331,7 @@ public void testSingleGetAfterRestore() throws Exception { String docId = Integer.toString(randomInt()); indexDoc(indexName, docId, "value", expectedValue); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository(repoName) - .setType("fs").setSettings(Settings.builder() - .put("location", absolutePath) - )); + createRepository(repoName, "fs", absolutePath); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName) @@ -480,9 +476,7 @@ public void testEmptySnapshot() throws Exception { public void testRestoreAliases() throws Exception { Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", randomRepoPath()))); + createRepository("test-repo", "fs", randomRepoPath()); logger.info("--> create test indices"); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); @@ -545,9 +539,7 @@ public void testRestoreAliases() throws Exception { public void testRestoreTemplates() throws Exception { Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", randomRepoPath()))); + createRepository("test-repo", "fs", randomRepoPath()); logger.info("--> creating test template"); assertThat(client.admin().indices() @@ -597,10 +589,7 @@ public void testRestoreTemplates() throws Exception { public void testIncludeGlobalState() throws Exception { Client client = client(); - logger.info("--> creating repository"); - Path location = randomRepoPath(); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", location))); + createRepository("test-repo", "fs", randomRepoPath()); boolean testTemplate = randomBoolean(); boolean testPipeline = randomBoolean(); @@ -914,9 +903,7 @@ public void testDataFileFailureDuringRestore() throws Exception { Path repositoryLocation = randomRepoPath(); Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", repositoryLocation))); + createRepository("test-repo", "fs", repositoryLocation); prepareCreate("test-idx").setSettings(Settings.builder().put("index.allocation.max_retries", Integer.MAX_VALUE)).get(); ensureGreen(); @@ -979,9 +966,8 @@ public void testDataFileCorruptionDuringRestore() throws Exception { Path repositoryLocation = randomRepoPath(); Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", repositoryLocation))); + + createRepository("test-repo", "fs", repositoryLocation); createIndex("test-idx"); ensureGreen(); @@ -1088,9 +1074,7 @@ private void unrestorableUseCase(final String indexName, final Runnable fixUpAction) throws Exception { // create a test repository final Path repositoryLocation = randomRepoPath(); - assertAcked(client().admin().cluster().preparePutRepository("test-repo") - .setType("fs") - .setSettings(Settings.builder().put("location", repositoryLocation))); + createRepository("test-repo", "fs", repositoryLocation); // create a test index assertAcked(prepareCreate(indexName, Settings.builder().put(createIndexSettings))); @@ -1157,9 +1141,7 @@ private void unrestorableUseCase(final String indexName, } // update the test repository in order to make it work - assertAcked(client().admin().cluster().preparePutRepository("test-repo") - .setType("fs") - .setSettings(Settings.builder().put("location", repositoryLocation))); + createRepository("test-repo", "fs", repositoryLocation); // execute action to eventually fix the situation fixUpAction.run(); @@ -1181,9 +1163,7 @@ private void unrestorableUseCase(final String indexName, public void testDeletionOfFailingToRecoverIndexShouldStopRestore() throws Exception { Path repositoryLocation = randomRepoPath(); Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", repositoryLocation))); + createRepository("test-repo", "fs", repositoryLocation); createIndex("test-idx"); ensureGreen(); @@ -1232,8 +1212,7 @@ public void testDeletionOfFailingToRecoverIndexShouldStopRestore() throws Except equalTo(restoreSnapshotResponse.getRestoreInfo().failedShards())); logger.info("--> restoring working repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", repositoryLocation))); + createRepository("test-repo", "fs", repositoryLocation); logger.info("--> trying to restore index again"); restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap") @@ -1247,10 +1226,7 @@ public void testDeletionOfFailingToRecoverIndexShouldStopRestore() throws Except public void testUnallocatedShards() throws Exception { Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder() - .put("location", randomRepoPath()))); + createRepository("test-repo", "fs", randomRepoPath()); logger.info("--> creating index that cannot be allocated"); prepareCreate("test-idx", 2, Settings.builder().put(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "tag", "nowhere") @@ -1672,10 +1648,7 @@ public void testSnapshotWithMissingShardLevelIndexFile() throws Exception { public void testSnapshotClosedIndex() throws Exception { Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder() - .put("location", randomRepoPath()))); + createRepository("test-repo", "fs", randomRepoPath()); createIndex("test-idx", "test-idx-closed"); ensureGreen(); @@ -1695,10 +1668,7 @@ public void testSnapshotClosedIndex() throws Exception { public void testRenameOnRestore() throws Exception { Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder() - .put("location", randomRepoPath()))); + createRepository("test-repo", "fs", randomRepoPath()); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); @@ -1869,8 +1839,7 @@ public void testMoveShardWhileSnapshotting() throws Exception { cluster().wipeIndices("test-idx"); logger.info("--> replace mock repository with real one at the same location"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", repositoryLocation))); + createRepository("test-repo", "fs", repositoryLocation); logger.info("--> restore index"); RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap") @@ -1955,8 +1924,7 @@ public void testDeleteRepositoryWhileSnapshotting() throws Exception { cluster().wipeIndices("test-idx"); logger.info("--> replace mock repository with real one at the same location"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(Settings.builder().put("location", repositoryLocation))); + createRepository("test-repo", "fs", repositoryLocation); logger.info("--> restore index"); RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap") @@ -2666,11 +2634,8 @@ public void testCloseIndexDuringRestore() throws Exception { public void testDeleteSnapshotWhileRestoringFails() throws Exception { Client client = client(); - logger.info("--> creating repository"); final String repoName = "test-repo"; - assertAcked(client.admin().cluster().preparePutRepository(repoName) - .setType("mock") - .setSettings(Settings.builder().put("location", randomRepoPath()))); + createRepository(repoName, "mock", randomRepoPath()); logger.info("--> creating index"); final String indexName = "test-idx"; @@ -2893,10 +2858,7 @@ public void testRestoreSnapshotWithCorruptedIndexMetadata() throws Exception { } flushAndRefresh(); - assertAcked(client().admin().cluster().preparePutRepository("test-repo") - .setType("fs") - .setSettings(Settings.builder() - .put("location", repo))); + createRepository("test-repo", "fs", repo); CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") .setWaitForCompletion(true) @@ -2970,11 +2932,7 @@ public void testSnapshotWithCorruptedShardIndexFile() throws Exception { indexRandom(true, documents); flushAndRefresh(); - logger.info("--> creating repository"); - assertAcked(client().admin().cluster().preparePutRepository("test-repo") - .setType("fs") - .setSettings(Settings.builder() - .put("location", repo))); + createRepository("test-repo", "fs", repo); final String snapshot1 = "test-snap-1"; logger.info("--> creating snapshot [{}]", snapshot1); @@ -3360,8 +3318,7 @@ public void testSnapshotSucceedsAfterSnapshotFailure() throws Exception { } logger.info("--> snapshot with no I/O failures"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo-2").setType("mock").setSettings( - Settings.builder().put("location", repoPath))); + createRepository("test-repo-2", "mock", repoPath); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo-2", "test-snap-2") .setWaitForCompletion(true) @@ -3500,7 +3457,7 @@ public void testGetSnapshotsFromIndexBlobOnly() throws Exception { .setVerbose(false) .get(); assertEquals(indicesPerSnapshot.size(), response.getSnapshots("test-repo").size()); - verifySnapshotInfo("test-repo", response, indicesPerSnapshot); + verifySnapshotInfo(response, indicesPerSnapshot); logger.info("--> verify wildcard returns snapshot info"); response = client().admin().cluster() @@ -3509,7 +3466,7 @@ public void testGetSnapshotsFromIndexBlobOnly() throws Exception { .setVerbose(false) .get(); assertEquals(indicesPerSnapshot.size(), response.getSnapshots("test-repo").size()); - verifySnapshotInfo("test-repo", response, indicesPerSnapshot); + verifySnapshotInfo(response, indicesPerSnapshot); logger.info("--> verify individual requests return snapshot info"); for (int i = 0; i < numSnapshots; i++) { @@ -3519,7 +3476,7 @@ public void testGetSnapshotsFromIndexBlobOnly() throws Exception { .setVerbose(false) .get(); assertEquals(1, response.getSnapshots("test-repo").size()); - verifySnapshotInfo("test-repo", response, indicesPerSnapshot); + verifySnapshotInfo(response, indicesPerSnapshot); } } @@ -3602,7 +3559,7 @@ public void testParallelRestoreOperations() { String repoName = "test-restore-snapshot-repo"; String snapshotName1 = "test-restore-snapshot1"; String snapshotName2 = "test-restore-snapshot2"; - String absolutePath = randomRepoPath().toAbsolutePath().toString(); + Path absolutePath = randomRepoPath().toAbsolutePath(); logger.info("Path [{}]", absolutePath); String restoredIndexName1 = indexName1 + "-restored"; String restoredIndexName2 = indexName2 + "-restored"; @@ -3616,11 +3573,7 @@ public void testParallelRestoreOperations() { String docId2 = Integer.toString(randomInt()); indexDoc(indexName2, docId2, "value", expectedValue); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository(repoName) - .setType("fs").setSettings(Settings.builder() - .put("location", absolutePath) - )); + createRepository(repoName, "fs", absolutePath); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName1) @@ -3663,7 +3616,7 @@ public void testParallelRestoreOperationsFromSingleSnapshot() throws Exception { String indexName2 = "testindex2"; String repoName = "test-restore-snapshot-repo"; String snapshotName = "test-restore-snapshot"; - String absolutePath = randomRepoPath().toAbsolutePath().toString(); + Path absolutePath = randomRepoPath().toAbsolutePath(); logger.info("Path [{}]", absolutePath); String restoredIndexName1 = indexName1 + "-restored"; String restoredIndexName2 = indexName2 + "-restored"; @@ -3677,11 +3630,7 @@ public void testParallelRestoreOperationsFromSingleSnapshot() throws Exception { String docId2 = Integer.toString(randomInt()); indexDoc(indexName2, docId2, "value", expectedValue); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository(repoName) - .setType("fs").setSettings(Settings.builder() - .put("location", absolutePath) - )); + createRepository(repoName, "fs", absolutePath); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName) @@ -3760,7 +3709,7 @@ public void testRestoreIncreasesPrimaryTerms() { public void testSnapshotDifferentIndicesBySameName() { String indexName = "testindex"; String repoName = "test-repo"; - String absolutePath = randomRepoPath().toAbsolutePath().toString(); + Path absolutePath = randomRepoPath().toAbsolutePath(); logger.info("Path [{}]", absolutePath); final int initialShardCount = randomIntBetween(1, 10); @@ -3773,10 +3722,7 @@ public void testSnapshotDifferentIndicesBySameName() { indexDoc(indexName, Integer.toString(i), "foo", "bar" + i); } - logger.info("--> creating repository"); - assertAcked(client().admin().cluster().preparePutRepository(repoName) - .setType("fs") - .setSettings(Settings.builder().put("location", absolutePath))); + createRepository(repoName, "fs", absolutePath); logger.info("--> snapshot with [{}] shards", initialShardCount); final SnapshotInfo snapshot1 = @@ -3837,7 +3783,7 @@ public void testSnapshotDifferentIndicesBySameName() { assertHitCount(client().prepareSearch("restored-3").setSize(0).get(), expectedCount); } - private void verifySnapshotInfo(final String repo, final GetSnapshotsResponse response, + private void verifySnapshotInfo(final GetSnapshotsResponse response, final Map> indicesPerSnapshot) { for (SnapshotInfo snapshotInfo : response.getSnapshots("test-repo")) { final List expected = snapshotInfo.indices(); diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotStatusApisIT.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotStatusApisIT.java index 043e0cd0fb77c..05a3c0a026158 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotStatusApisIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotStatusApisIT.java @@ -51,9 +51,7 @@ public class SnapshotStatusApisIT extends AbstractSnapshotIntegTestCase { public void testStatusApiConsistency() { Client client = client(); - logger.info("--> creating repository"); - assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings( - Settings.builder().put("location", randomRepoPath()).build())); + createRepository("test-repo", "fs", randomRepoPath()); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); @@ -125,10 +123,8 @@ public void testStatusAPICallInProgressSnapshot() throws Exception { public void testExceptionOnMissingSnapBlob() throws IOException { disableRepoConsistencyCheck("This test intentionally corrupts the repository"); - logger.info("--> creating repository"); final Path repoPath = randomRepoPath(); - assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings( - Settings.builder().put("location", repoPath).build())); + createRepository("test-repo", "fs", repoPath); logger.info("--> snapshot"); final CreateSnapshotResponse response = @@ -145,10 +141,8 @@ public void testExceptionOnMissingSnapBlob() throws IOException { public void testExceptionOnMissingShardLevelSnapBlob() throws IOException { disableRepoConsistencyCheck("This test intentionally corrupts the repository"); - logger.info("--> creating repository"); final Path repoPath = randomRepoPath(); - assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings( - Settings.builder().put("location", repoPath).build())); + createRepository("test-repo", "fs", repoPath); createIndex("test-idx-1"); ensureGreen(); @@ -175,9 +169,7 @@ public void testExceptionOnMissingShardLevelSnapBlob() throws IOException { } public void testGetSnapshotsWithoutIndices() { - logger.info("--> creating repository"); - assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings( - Settings.builder().put("location", randomRepoPath()).build())); + createRepository("test-repo", "fs", randomRepoPath()); logger.info("--> snapshot"); final SnapshotInfo snapshotInfo =