Skip to content

Commit

Permalink
Cleanup AbstractSnapshotIntegTest (#55579)
Browse files Browse the repository at this point in the history
* Dry up repository creation in spots where we aren't using any custom settings
* `BlobStoreFormatIT` doesn't have to be an `IT` it's just a unit test
  • Loading branch information
original-brownbear authored Apr 23, 2020
1 parent c018f30 commit 0fb74db
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand Down Expand Up @@ -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 {
Expand All @@ -259,5 +260,4 @@ private long checksum(byte[] buffer) throws IOException {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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("-*")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1551,5 +1532,4 @@ public EnumSet<Metadata.XContentContext> context() {
return EnumSet.of(Metadata.XContentContext.GATEWAY, Metadata.XContentContext.SNAPSHOT);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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<String, Repository.Factory> getRepositories(Environment env, NamedXContentRegistry namedXContentRegistry,
ClusterService clusterService) {
return Collections.singletonMap("coutingmock",
return Collections.singletonMap(TYPE,
metadata -> new CountingMockRepository(metadata, env, namedXContentRegistry, clusterService));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 0fb74db

Please sign in to comment.