From 2aa80f9ee3a88c22e574d063b302b70e0d94028a Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 6 Oct 2020 14:41:11 +0200 Subject: [PATCH] Dry up Searchable Snapshots ITs (#63190) (#63321) Just a few spots where we can dry up these tests using the snapshot test infrastructure in core that I found while studying the existing searchable snapshot tests. --- .../snapshots/ConcurrentSnapshotsIT.java | 3 +- .../DedicatedClusterSnapshotRestoreIT.java | 15 +-- .../SharedClusterSnapshotRestoreIT.java | 102 +++--------------- .../AbstractSnapshotIntegTestCase.java | 18 ++++ ...ableSnapshotsBlobStoreCacheIntegTests.java | 5 +- .../BaseSearchableSnapshotsIntegTestCase.java | 55 +--------- .../ClusterStateApplierOrderingTests.java | 10 +- ...SnapshotRecoveryStateIntegrationTests.java | 14 +-- ...hableSnapshotsCacheClearingIntegTests.java | 10 +- .../SearchableSnapshotsIntegTests.java | 89 ++++----------- .../SearchableSnapshotsLicenseIntegTests.java | 44 ++------ ...hableSnapshotsSystemIndicesIntegTests.java | 17 ++- ...ableSnapshotsUuidValidationIntegTests.java | 21 +--- 13 files changed, 85 insertions(+), 318 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java index e2a60c58fea..f4c817e0131 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java @@ -1196,8 +1196,7 @@ public class ConcurrentSnapshotsIT extends AbstractSnapshotIntegTestCase { final String indexFast = "index-fast"; createIndexWithContent(indexFast, dataNode2, dataNode); - final ActionFuture createFastSnapshot = - client().admin().cluster().prepareCreateSnapshot(repoName, "fast-snapshot").setWaitForCompletion(true).execute(); + final ActionFuture createFastSnapshot = startFullSnapshot(repoName, "fast-snapshot"); assertThat(createSlowFuture.isDone(), is(false)); unblockNode(repoName, dataNode); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index c31c3231bbc..78a51807793 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -580,10 +580,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest indexRandomDocs("test-idx", 100); - logger.info("--> start snapshot"); - assertThat(clusterAdmin().prepareCreateSnapshot("test-repo", "test-snap-1").setIndices("test-idx") - .setWaitForCompletion(true).get().getSnapshotInfo().state(), - equalTo(SnapshotState.SUCCESS)); + createSnapshot("test-repo", "test-snap-1", Collections.singletonList("test-idx")); logger.info("--> close the index"); assertAcked(client().admin().indices().prepareClose("test-idx")); @@ -796,9 +793,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest assertAcked(client().admin().indices().prepareResizeIndex(sourceIdx, shrunkIdx).get()); logger.info("--> snapshot the shrunk index"); - assertSuccessful(clusterAdmin() - .prepareCreateSnapshot(repo, snapshot) - .setWaitForCompletion(true).setIndices(shrunkIdx).execute()); + createSnapshot(repo, snapshot, Collections.singletonList(shrunkIdx)); logger.info("--> delete index and stop the data node"); assertAcked(client().admin().indices().prepareDelete(sourceIdx).get()); @@ -1095,11 +1090,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest assertTrue(shardStats + ": " + retentionLeases, retentionLeases.contains(leaseId)); final String snapshotName = "snapshot-retention-leases"; - logger.debug("--> create snapshot {}:{}", repoName, snapshotName); - CreateSnapshotResponse createResponse = clusterAdmin().prepareCreateSnapshot(repoName, snapshotName) - .setWaitForCompletion(true).setIndices(indexName).get(); - assertThat(createResponse.getSnapshotInfo().successfulShards(), equalTo(shardCount)); - assertThat(createResponse.getSnapshotInfo().failedShards(), equalTo(0)); + createSnapshot(repoName, snapshotName, Collections.singletonList(indexName)); if (randomBoolean()) { final int extraDocCount = iterations(10, 1000); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index 234d63a0383..0df7b20d7a2 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -76,6 +76,7 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -259,16 +260,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index(indexName, typeName, docId, "value", expectedValue); createRepository(repoName, "fs", absolutePath); - - logger.info("--> snapshot"); - CreateSnapshotResponse createSnapshotResponse = clusterAdmin().prepareCreateSnapshot(repoName, snapshotName) - .setWaitForCompletion(true) - .setIndices(indexName) - .get(); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); - assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS)); + createSnapshot(repoName, snapshotName, Collections.singletonList(indexName)); RestoreSnapshotResponse restoreSnapshotResponse = clusterAdmin().prepareRestoreSnapshot(repoName, snapshotName) .setWaitForCompletion(true) @@ -289,11 +281,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas assertTrue(originalIndexUUID, originalIndexUUID != null); assertFalse(originalIndexUUID, originalIndexUUID.equals(IndexMetadata.INDEX_UUID_NA_VALUE)); ensureGreen(); - CreateSnapshotResponse createSnapshotResponse = clusterAdmin().prepareCreateSnapshot("test-repo", "test-snap") - .setWaitForCompletion(true).setIndices("test").get(); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); + createSnapshot("test-repo", "test-snap", Collections.singletonList("test")); NumShards numShards = getNumShards("test"); cluster().wipeIndices("test"); @@ -456,12 +444,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas indexRandomDocs("test-idx", 100); - logger.info("--> snapshot"); - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") - .setWaitForCompletion(true).setIndices("test-idx").get(); - assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS)); - assertThat(createSnapshotResponse.getSnapshotInfo().totalShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().successfulShards())); + createSnapshot("test-repo", "test-snap", Collections.singletonList("test-idx")); createRepository("test-repo", "mock", Settings.builder().put("location", repositoryLocation).put("random", randomAlphaOfLength(10)) @@ -505,12 +488,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas createRepository("test-repo", "fs", repositoryLocation); createIndexWithRandomDocs("test-idx", 100); - logger.info("--> snapshot"); - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster() - .prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get(); - assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS)); - assertThat(createSnapshotResponse.getSnapshotInfo().totalShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().successfulShards())); + createSnapshot("test-repo", "test-snap", Collections.singletonList("test-idx")); createRepository("test-repo", "mock", Settings.builder().put("location", repositoryLocation).put("random", randomAlphaOfLength(10)) @@ -602,14 +580,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas // create a snapshot final NumShards numShards = getNumShards(indexName); - CreateSnapshotResponse snapshotResponse = clusterAdmin().prepareCreateSnapshot("test-repo", "test-snap") - .setWaitForCompletion(true) - .setIndices(indexName) - .get(); - - assertThat(snapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS)); - assertThat(snapshotResponse.getSnapshotInfo().successfulShards(), equalTo(numShards.numPrimaries)); - assertThat(snapshotResponse.getSnapshotInfo().failedShards(), equalTo(0)); + final SnapshotInfo snapshotInfo = createSnapshot("test-repo", "test-snap", Collections.singletonList(indexName)); + assertThat(snapshotInfo.successfulShards(), equalTo(numShards.numPrimaries)); // delete the test index assertAcked(client().admin().indices().prepareDelete(indexName)); @@ -681,12 +653,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas createIndexWithRandomDocs("test-idx", 100); - logger.info("--> snapshot"); - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") - .setWaitForCompletion(true).setIndices("test-idx").get(); - assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS)); - assertThat(createSnapshotResponse.getSnapshotInfo().totalShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().successfulShards())); + createSnapshot("test-repo", "test-snap", Collections.singletonList("test-idx")); logger.info("--> update repository with mock version"); createRepository("test-repo", "mock", Settings.builder() @@ -760,12 +727,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas index("test-idx", "_doc", Integer.toString(i * 10 + j), "foo", "bar" + i * 10 + j); } refresh(); - logger.info("--> snapshot {}", i); - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-" + i) - .setWaitForCompletion(true).setIndices("test-idx").get(); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); + createSnapshot("test-repo", "test-snap-" + i, Collections.singletonList("test-idx")); // Store number of files after each snapshot numberOfFiles[i] = numberOfFiles(repo); } @@ -948,12 +910,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas createIndexWithRandomDocs("test-idx", 100); - logger.info("--> snapshot"); - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") - .setWaitForCompletion(true).setIndices("test-idx").get(); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); + createSnapshot("test-repo", "test-snap", Collections.singletonList("test-idx")); assertThat(getSnapshot("test-repo", "test-snap").state(), equalTo(SnapshotState.SUCCESS)); @@ -1002,13 +959,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .put("max_snapshot_bytes_per_sec", throttleSnapshot ? "10k" : "0")); createIndexWithRandomDocs("test-idx", 100); - - logger.info("--> snapshot"); - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") - .setWaitForCompletion(true).setIndices("test-idx").get(); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); + createSnapshot("test-repo", "test-snap", Collections.singletonList("test-idx")); logger.info("--> delete index"); cluster().wipeIndices("test-idx"); @@ -1195,11 +1146,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas indexRandomDocs("test", randomIntBetween(10, 100)); assertNoFailures(client().admin().indices().prepareForceMerge("test").setFlush(true).setMaxNumSegments(1).get()); - CreateSnapshotResponse createSnapshotResponseFirst = client.admin().cluster().prepareCreateSnapshot("test-repo", "test") - .setWaitForCompletion(true).setIndices("test").get(); - assertThat(createSnapshotResponseFirst.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponseFirst.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponseFirst.getSnapshotInfo().totalShards())); + createSnapshot("test-repo", "test", Collections.singletonList("test")); assertThat(getSnapshot("test-repo", "test").state(), equalTo(SnapshotState.SUCCESS)); { SnapshotStatus snapshotStatus = client.admin().cluster().prepareSnapshotStatus("test-repo") @@ -1210,11 +1157,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas } } - CreateSnapshotResponse createSnapshotResponseSecond = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-1") - .setWaitForCompletion(true).setIndices("test").get(); - assertThat(createSnapshotResponseSecond.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponseSecond.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponseSecond.getSnapshotInfo().totalShards())); + createSnapshot("test-repo", "test-1", Collections.singletonList("test")); assertThat(getSnapshot("test-repo", "test-1").state(), equalTo(SnapshotState.SUCCESS)); { SnapshotStatus snapshotStatus = client.admin().cluster().prepareSnapshotStatus("test-repo") @@ -1226,11 +1169,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas } client().prepareDelete("test", "_doc", "1").get(); - CreateSnapshotResponse createSnapshotResponseThird = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-2") - .setWaitForCompletion(true).setIndices("test").get(); - assertThat(createSnapshotResponseThird.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponseThird.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponseThird.getSnapshotInfo().totalShards())); + createSnapshot("test-repo", "test-2", Collections.singletonList("test")); assertThat(getSnapshot("test-repo", "test-2").state(), equalTo(SnapshotState.SUCCESS)); { SnapshotStatus snapshotStatus = client.admin().cluster().prepareSnapshotStatus("test-repo") @@ -1791,11 +1730,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas } final String snapshotName = "test-snap-" + i; indicesPerSnapshot.put(snapshotName, indices); - client.admin().cluster() - .prepareCreateSnapshot("test-repo", snapshotName) - .setWaitForCompletion(true) - .setIndices(indices.toArray(new String[indices.size()])) - .get(); + createSnapshot("test-repo", snapshotName, indices); } logger.info("--> verify _all returns snapshot info"); @@ -1855,12 +1790,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas refresh(); - logger.info("--> snapshot"); - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshotName) - .setWaitForCompletion(true).setIndices(indexName).get(); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), - equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); + createSnapshot(repositoryName, snapshotName, Collections.singletonList(indexName)); logger.info("--> delete indices"); assertAcked(client.admin().indices().prepareDelete(indexName)); diff --git a/test/framework/src/main/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java index 22ba247acf2..0b46c773a18 100644 --- a/test/framework/src/main/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -83,6 +83,8 @@ import java.util.function.Predicate; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -386,6 +388,22 @@ public abstract class AbstractSnapshotIntegTestCase extends ESIntegTestCase { return snapshotInfo; } + protected SnapshotInfo createSnapshot(String repositoryName, String snapshot, List indices) { + logger.info("--> creating snapshot [{}] of {} in [{}]", snapshot, indices, repositoryName); + final CreateSnapshotResponse response = client().admin() + .cluster() + .prepareCreateSnapshot(repositoryName, snapshot) + .setIndices(indices.toArray(Strings.EMPTY_ARRAY)) + .setWaitForCompletion(true) + .get(); + + final SnapshotInfo snapshotInfo = response.getSnapshotInfo(); + assertThat(snapshotInfo.state(), is(SnapshotState.SUCCESS)); + assertThat(snapshotInfo.successfulShards(), greaterThan(0)); + assertThat(snapshotInfo.failedShards(), equalTo(0)); + return snapshotInfo; + } + protected void createIndexWithRandomDocs(String indexName, int docCount) throws InterruptedException { createIndex(indexName); ensureGreen(); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java index f26ee2944c1..2dd1e2cea8c 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java @@ -50,6 +50,7 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -118,9 +119,9 @@ public class SearchableSnapshotsBlobStoreCacheIntegTests extends BaseSearchableS final String repositoryName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final Path repositoryLocation = randomRepoPath(); - createFsRepository(repositoryName, repositoryLocation); + createRepository(repositoryName, "fs", repositoryLocation); - final SnapshotId snapshot = createSnapshot(repositoryName, org.elasticsearch.common.collect.List.of(indexName)); + final SnapshotId snapshot = createSnapshot(repositoryName, "test-snapshot", Collections.singletonList(indexName)).snapshotId(); assertAcked(client().admin().indices().prepareDelete(indexName)); // extract the list of blobs per shard from the snapshot directory on disk diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java index 86bf146a3c7..efbb2da0bb3 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java @@ -24,7 +24,6 @@ */ package org.elasticsearch.xpack.searchablesnapshots; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.common.Strings; @@ -33,28 +32,22 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.repositories.fs.FsRepository; -import org.elasticsearch.snapshots.SnapshotId; -import org.elasticsearch.snapshots.SnapshotInfo; -import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.xpack.core.XPackSettings; +import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; import org.elasticsearch.xpack.searchablesnapshots.cache.CacheService; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; -import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING; import static org.elasticsearch.license.LicenseService.SELF_GENERATED_LICENSE_TYPE; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -public abstract class BaseSearchableSnapshotsIntegTestCase extends ESIntegTestCase { +public abstract class BaseSearchableSnapshotsIntegTestCase extends AbstractSnapshotIntegTestCase { @Override protected boolean addMockInternalEngine() { return false; @@ -74,8 +67,7 @@ public abstract class BaseSearchableSnapshotsIntegTestCase extends ESIntegTestCa protected Settings nodeSettings(int nodeOrdinal) { final Settings.Builder builder = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(SELF_GENERATED_LICENSE_TYPE.getKey(), "trial") - .put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none"); + .put(SELF_GENERATED_LICENSE_TYPE.getKey(), "trial"); builder.put(XPackSettings.SECURITY_ENABLED.getKey(), false); if (randomBoolean()) { builder.put( @@ -105,40 +97,6 @@ public abstract class BaseSearchableSnapshotsIntegTestCase extends ESIntegTestCa return builder.build(); } - protected void createFsRepository(String repositoryName, Path location) { - createRepository( - repositoryName, - FsRepository.TYPE, - Settings.builder().put(FsRepository.LOCATION_SETTING.getKey(), location).build(), - true - ); - } - - protected void createRepository(String repositoryName, String repositoryType, Settings repositorySettings, boolean verify) { - assertAcked( - client().admin() - .cluster() - .preparePutRepository(repositoryName) - .setType(repositoryType) - .setSettings(repositorySettings) - .setVerify(verify) - ); - } - - protected SnapshotId createSnapshot(String repositoryName, List indices) { - final CreateSnapshotResponse response = client().admin() - .cluster() - .prepareCreateSnapshot(repositoryName, randomAlphaOfLength(10).toLowerCase(Locale.ROOT)) - .setIndices(indices.toArray(Strings.EMPTY_ARRAY)) - .setWaitForCompletion(true) - .get(); - - final SnapshotInfo snapshotInfo = response.getSnapshotInfo(); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.failedShards(), equalTo(0)); - return snapshotInfo.snapshotId(); - } - protected String mountSnapshot(String repositoryName, String snapshotName, String indexName, Settings restoredIndexSettings) throws Exception { final String restoredIndexName = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT); @@ -171,13 +129,6 @@ public abstract class BaseSearchableSnapshotsIntegTestCase extends ESIntegTestCa assertThat(restoreResponse.getRestoreInfo().failedShards(), equalTo(0)); } - protected void createRepo(String fsRepoName) { - final Path repo = randomRepoPath(); - assertAcked( - client().admin().cluster().preparePutRepository(fsRepoName).setType("fs").setSettings(Settings.builder().put("location", repo)) - ); - } - protected void createAndPopulateIndex(String indexName, Settings.Builder settings) throws InterruptedException { assertAcked(prepareCreate(indexName, settings)); ensureGreen(indexName); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/ClusterStateApplierOrderingTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/ClusterStateApplierOrderingTests.java index d617bb5ec56..f9881ae3906 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/ClusterStateApplierOrderingTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/ClusterStateApplierOrderingTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.searchablesnapshots; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -44,7 +43,7 @@ public class ClusterStateApplierOrderingTests extends BaseSearchableSnapshotsInt final String indexName = "test-index"; final String restoredIndexName = "restored-index"; - createRepo(fsRepoName); + createRepository(fsRepoName, "fs"); // Peer recovery always copies .liv files but we do not permit writing to searchable snapshot directories so this doesn't work, but // we can bypass this by forcing soft deletes to be used. TODO this restriction can be lifted when #55142 is resolved. @@ -57,12 +56,7 @@ public class ClusterStateApplierOrderingTests extends BaseSearchableSnapshotsInt indexRandom(true, true, indexRequestBuilders); refresh(indexName); - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(fsRepoName, "snapshot") - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); + final SnapshotInfo snapshotInfo = createFullSnapshot(fsRepoName, "snapshot"); assertThat(snapshotInfo.successfulShards(), greaterThan(0)); assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java index cd4e5e3ce68..ceb3d3dba34 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotRecoveryStateIntegrationTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.searchablesnapshots; import com.carrotsearch.hppc.ObjectContainer; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -41,7 +40,6 @@ import java.util.stream.Stream; import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; @ESIntegTestCase.ClusterScope(numDataNodes = 1) public class SearchableSnapshotRecoveryStateIntegrationTests extends BaseSearchableSnapshotsIntegTestCase { @@ -60,7 +58,7 @@ public class SearchableSnapshotRecoveryStateIntegrationTests extends BaseSearcha final String restoredIndexName = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - createRepo(fsRepoName); + createRepository(fsRepoName, "fs"); final Settings.Builder originalIndexSettings = Settings.builder(); originalIndexSettings.put(INDEX_SOFT_DELETES_SETTING.getKey(), true); @@ -68,15 +66,7 @@ public class SearchableSnapshotRecoveryStateIntegrationTests extends BaseSearcha createAndPopulateIndex(indexName, originalIndexSettings); - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(fsRepoName, snapshotName) - .setWaitForCompletion(true) - .get(); - - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); + final SnapshotInfo snapshotInfo = createFullSnapshot(fsRepoName, snapshotName); assertAcked(client().admin().indices().prepareDelete(indexName)); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCacheClearingIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCacheClearingIntegTests.java index 9dc498ba8f8..e4e9115393d 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCacheClearingIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCacheClearingIntegTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.searchablesnapshots; import org.apache.lucene.mockfile.FilterFileSystemProvider; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -103,19 +102,14 @@ public class SearchableSnapshotsCacheClearingIntegTests extends BaseSearchableSn final String restoredIndexName = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - createRepo(fsRepoName); + createRepository(fsRepoName, "fs"); final Settings.Builder originalIndexSettings = Settings.builder() .put(INDEX_SOFT_DELETES_SETTING.getKey(), true) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1); createAndPopulateIndex(indexName, originalIndexSettings); - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(fsRepoName, snapshotName) - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); + final SnapshotInfo snapshotInfo = createFullSnapshot(fsRepoName, snapshotName); assertThat(snapshotInfo.successfulShards(), greaterThan(0)); assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); assertAcked(client().admin().indices().prepareDelete(indexName)); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java index 5a9a45da93c..821f1111e9f 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java @@ -9,7 +9,6 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.search.TotalHits; import org.elasticsearch.ResourceNotFoundException; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; @@ -39,7 +38,6 @@ import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.recovery.RecoveryState; import org.elasticsearch.repositories.RepositoriesService; -import org.elasticsearch.repositories.fs.FsRepository; import org.elasticsearch.snapshots.SnapshotId; import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; @@ -92,13 +90,10 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT final String restoredIndexName = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - final Path repo = randomRepoPath(); - assertAcked( - client().admin() - .cluster() - .preparePutRepository(fsRepoName) - .setType("fs") - .setSettings(Settings.builder().put("location", repo).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)) + createRepository( + fsRepoName, + "fs", + Settings.builder().put("location", randomRepoPath()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES) ); // Peer recovery always copies .liv files but we do not permit writing to searchable snapshot directories so this doesn't work, but @@ -129,14 +124,7 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT () -> client().execute(SearchableSnapshotsStatsAction.INSTANCE, new SearchableSnapshotsStatsRequest()).actionGet() ); - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(fsRepoName, snapshotName) - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); + final SnapshotInfo snapshotInfo = createFullSnapshot(fsRepoName, snapshotName); ensureGreen(indexName); assertShardFolders(indexName, false); @@ -354,13 +342,10 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT final String restoredIndexName = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - final Path repo = randomRepoPath(); - assertAcked( - client().admin() - .cluster() - .preparePutRepository(fsRepoName) - .setType("fs") - .setSettings(Settings.builder().put("location", repo).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)) + createRepository( + fsRepoName, + "fs", + Settings.builder().put("location", randomRepoPath()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES) ); assertAcked(prepareCreate(indexName, Settings.builder().put(INDEX_SOFT_DELETES_SETTING.getKey(), true))); @@ -391,14 +376,7 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT } catch (InterruptedException | BrokenBarrierException e) { throw new AssertionError(e); } - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(fsRepoName, snapshotName) - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); + createFullSnapshot(fsRepoName, snapshotName); }); indexingThead.start(); @@ -434,15 +412,7 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT final String repositoryName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - assertAcked( - prepareCreate( - indexName, - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, between(1, 3)) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(INDEX_SOFT_DELETES_SETTING.getKey(), true) - ) - ); + assertAcked(prepareCreate(indexName, indexSettingsNoReplicas(between(1, 3)).put(INDEX_SOFT_DELETES_SETTING.getKey(), true))); final int nbDocs = between(10, 50); indexRandom( true, @@ -465,18 +435,11 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT } else { repositorySettings.put("max_restore_bytes_per_sec", ByteSizeValue.ZERO); } - assertAcked( - client().admin().cluster().preparePutRepository(repositoryName).setType(FsRepository.TYPE).setSettings(repositorySettings) - ); + createRepository(repositoryName, "fs", repositorySettings); final String restoredIndexName = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(repositoryName, snapshotName) - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); + final SnapshotInfo snapshotInfo = createFullSnapshot(repositoryName, snapshotName); assertThat(snapshotInfo.successfulShards(), greaterThan(0)); assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); @@ -537,7 +500,7 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT final String restoredIndexName = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - createRepo(fsRepoName); + createRepository(fsRepoName, "fs"); final int dataNodesCount = internalCluster().numDataNodes(); final Settings.Builder originalIndexSettings = Settings.builder(); @@ -554,14 +517,7 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT } createAndPopulateIndex(indexName, originalIndexSettings); - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(fsRepoName, snapshotName) - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); + createFullSnapshot(fsRepoName, snapshotName); assertAcked(client().admin().indices().prepareDelete(indexName)); @@ -665,21 +621,14 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT public void testSnapshotMountedIndexLeavesBlobsUntouched() throws Exception { final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final int numShards = between(1, 3); - createAndPopulateIndex( - indexName, - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(INDEX_SOFT_DELETES_SETTING.getKey(), true) - ); + createAndPopulateIndex(indexName, indexSettingsNoReplicas(numShards).put(INDEX_SOFT_DELETES_SETTING.getKey(), true)); ensureGreen(indexName); forceMerge(); final String repositoryName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - final Path repositoryLocation = randomRepoPath(); - createFsRepository(repositoryName, repositoryLocation); + createRepository(repositoryName, "fs"); - final SnapshotId snapshotOne = createSnapshot(repositoryName, Collections.singletonList(indexName)); + final SnapshotId snapshotOne = createSnapshot(repositoryName, "snapshot-1", Collections.singletonList(indexName)).snapshotId(); assertAcked(client().admin().indices().prepareDelete(indexName)); final SnapshotStatus snapshotOneStatus = client().admin() @@ -695,7 +644,7 @@ public class SearchableSnapshotsIntegTests extends BaseSearchableSnapshotsIntegT mountSnapshot(repositoryName, snapshotOne.getName(), indexName, indexName, Settings.EMPTY); ensureGreen(indexName); - final SnapshotId snapshotTwo = createSnapshot(repositoryName, Collections.singletonList(indexName)); + final SnapshotId snapshotTwo = createSnapshot(repositoryName, "snapshot-2", Collections.singletonList(indexName)).snapshotId(); final SnapshotStatus snapshotTwoStatus = client().admin() .cluster() .prepareSnapshotStatus(repositoryName) diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsLicenseIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsLicenseIntegTests.java index 117113634d0..55651b99c9d 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsLicenseIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsLicenseIntegTests.java @@ -27,14 +27,11 @@ package org.elasticsearch.xpack.searchablesnapshots; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionFuture; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettings; @@ -47,7 +44,6 @@ import org.elasticsearch.license.PostStartTrialAction; import org.elasticsearch.license.PostStartTrialRequest; import org.elasticsearch.license.PostStartTrialResponse; import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest; -import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; @@ -59,7 +55,6 @@ import org.elasticsearch.xpack.searchablesnapshots.action.SearchableSnapshotsSta import org.elasticsearch.xpack.searchablesnapshots.action.SearchableSnapshotsStatsResponse; import org.junit.Before; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -78,18 +73,9 @@ public class SearchableSnapshotsLicenseIntegTests extends BaseSearchableSnapshot @Before public void createAndMountSearchableSnapshot() throws Exception { - createRepo(repoName); - + createRepository(repoName, "fs"); createIndex(indexName); - - CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(repoName, snapshotName) - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); + createFullSnapshot(repoName, snapshotName); assertAcked(client().admin().indices().prepareDelete(indexName)); @@ -173,27 +159,11 @@ public class SearchableSnapshotsLicenseIntegTests extends BaseSearchableSnapshot // add a valid license again // This is a bit of a hack in tests, as we can't readd a trial license // We force this by clearing the existing basic license first - CountDownLatch latch = new CountDownLatch(1); - internalCluster().getCurrentMasterNodeInstance(ClusterService.class) - .submitStateUpdateTask("remove license", new ClusterStateUpdateTask() { - @Override - public ClusterState execute(ClusterState currentState) { - return ClusterState.builder(currentState) - .metadata(Metadata.builder(currentState.metadata()).removeCustom(LicensesMetadata.TYPE).build()) - .build(); - } - - @Override - public void onFailure(String source, Exception e) { - throw new AssertionError(e); - } - - @Override - public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { - latch.countDown(); - } - }); - latch.await(); + updateClusterState( + currentState -> ClusterState.builder(currentState) + .metadata(Metadata.builder(currentState.metadata()).removeCustom(LicensesMetadata.TYPE).build()) + .build() + ); PostStartTrialRequest startTrialRequest = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName()) .acknowledge(true); PostStartTrialResponse resp = client().execute(PostStartTrialAction.INSTANCE, startTrialRequest).get(); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsSystemIndicesIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsSystemIndicesIntegTests.java index 5ab030855c6..7e6ad655d15 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsSystemIndicesIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsSystemIndicesIntegTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.searchablesnapshots; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.OriginSettingClient; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -16,12 +15,14 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SystemIndexPlugin; +import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Locale; @@ -51,19 +52,13 @@ public class SearchableSnapshotsSystemIndicesIntegTests extends BaseSearchableSn createAndPopulateIndex(indexName, Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, isHidden)); final String repositoryName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - createRepo(repositoryName); + createRepository(repositoryName, "fs"); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - final CreateSnapshotResponse snapshotResponse = client.admin() - .cluster() - .prepareCreateSnapshot(repositoryName, snapshotName) - .setIndices(indexName) - .setWaitForCompletion(true) - .get(); - final int numPrimaries = getNumShards(indexName).numPrimaries; - assertThat(snapshotResponse.getSnapshotInfo().successfulShards(), equalTo(numPrimaries)); - assertThat(snapshotResponse.getSnapshotInfo().failedShards(), equalTo(0)); + final SnapshotInfo snapshotInfo = createSnapshot(repositoryName, snapshotName, Collections.singletonList(indexName)); + assertThat(snapshotInfo.successfulShards(), equalTo(numPrimaries)); + assertThat(snapshotInfo.failedShards(), equalTo(0)); if (randomBoolean()) { assertAcked(client.admin().indices().prepareClose(indexName)); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUuidValidationIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUuidValidationIntegTests.java index 283f7a92387..b5c06ca4400 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUuidValidationIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUuidValidationIntegTests.java @@ -9,7 +9,6 @@ package org.elasticsearch.xpack.searchablesnapshots; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotAction; import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.action.support.ActionFilter; @@ -19,7 +18,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.snapshots.SnapshotRestoreException; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; @@ -34,8 +32,6 @@ import static java.util.Collections.singletonList; import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; public class SearchableSnapshotsUuidValidationIntegTests extends BaseSearchableSnapshotsIntegTestCase { @@ -91,12 +87,12 @@ public class SearchableSnapshotsUuidValidationIntegTests extends BaseSearchableS final String restoredIndexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - createRepo(fsRepoName); + createRepository(fsRepoName, "fs"); final Settings.Builder originalIndexSettings = Settings.builder().put(INDEX_SOFT_DELETES_SETTING.getKey(), true); createAndPopulateIndex(indexName, originalIndexSettings); - createSnapshot(fsRepoName, snapshotName); + createFullSnapshot(fsRepoName, snapshotName); final MountSearchableSnapshotRequest req = new MountSearchableSnapshotRequest( restoredIndexName, @@ -114,7 +110,7 @@ public class SearchableSnapshotsUuidValidationIntegTests extends BaseSearchableS restoreBlockingActionFilter.awaitExecution(); assertAcked(client().admin().cluster().prepareDeleteSnapshot(fsRepoName, snapshotName).get()); - createSnapshot(fsRepoName, snapshotName); + createFullSnapshot(fsRepoName, snapshotName); assertFalse(responseFuture.isDone()); restoreBlockingActionFilter.unblock(); @@ -127,17 +123,6 @@ public class SearchableSnapshotsUuidValidationIntegTests extends BaseSearchableS assertAcked(client().admin().indices().prepareDelete(indexName)); } - private static void createSnapshot(String fsRepoName, String snapshotName) { - final CreateSnapshotResponse createSnapshotResponse = client().admin() - .cluster() - .prepareCreateSnapshot(fsRepoName, snapshotName) - .setWaitForCompletion(true) - .get(); - final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); - } - private static RestoreBlockingActionFilter getBlockingActionFilter() { for (final ActionFilter filter : internalCluster().getCurrentMasterNodeInstance(ActionFilters.class).filters()) { if (filter instanceof RestoreBlockingActionFilter) {