Skip to content

Commit 465998f

Browse files
Cleanup Duplication in Snapshot ITs (#58818)
Just a few obvious static cleanups of duplication to push back against the ever increasing complexity of these tests.
1 parent 9af4c1a commit 465998f

File tree

8 files changed

+233
-491
lines changed

8 files changed

+233
-491
lines changed

server/src/internalClusterTest/java/org/elasticsearch/discovery/SnapshotDisruptionIT.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,10 @@ public void testDisruptionAfterFinalization() throws Exception {
8888

8989
createRandomIndex(idxName);
9090

91-
logger.info("--> creating repository");
92-
assertAcked(client().admin().cluster().preparePutRepository("test-repo")
93-
.setType("fs").setSettings(Settings.builder()
94-
.put("location", randomRepoPath())
95-
.put("compress", randomBoolean())
96-
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
91+
createRepository("test-repo", "fs", Settings.builder()
92+
.put("location", randomRepoPath())
93+
.put("compress", randomBoolean())
94+
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
9795

9896
final String masterNode1 = internalCluster().getMasterName();
9997
Set<String> otherNodes = new HashSet<>(allMasterEligibleNodes);
@@ -178,21 +176,18 @@ public void testDisruptionAfterShardFinalization() throws Exception {
178176
index(idxName, JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject());
179177

180178
final String repoName = "test-repo";
181-
182-
logger.info("--> creating repository");
183-
assertAcked(client().admin().cluster().preparePutRepository(repoName).setType("mock")
184-
.setSettings(Settings.builder().put("location", randomRepoPath())));
179+
createRepository(repoName, "mock", randomRepoPath());
185180

186181
final String masterNode = internalCluster().getMasterName();
187182

188-
AbstractSnapshotIntegTestCase.blockAllDataNodes(repoName);
183+
blockAllDataNodes(repoName);
189184

190185
final String snapshot = "test-snap";
191186
logger.info("--> starting snapshot");
192187
ActionFuture<CreateSnapshotResponse> future = client(masterNode).admin().cluster()
193188
.prepareCreateSnapshot(repoName, snapshot).setWaitForCompletion(true).execute();
194189

195-
AbstractSnapshotIntegTestCase.waitForBlockOnAnyDataNode(repoName, TimeValue.timeValueSeconds(10L));
190+
waitForBlockOnAnyDataNode(repoName, TimeValue.timeValueSeconds(10L));
196191

197192
NetworkDisruption networkDisruption = new NetworkDisruption(
198193
new NetworkDisruption.TwoPartitions(Collections.singleton(masterNode), Collections.singleton(dataNode)),
@@ -206,7 +201,7 @@ public void testDisruptionAfterShardFinalization() throws Exception {
206201

207202
logger.info("--> stopping disrupting");
208203
networkDisruption.stopDisrupting();
209-
AbstractSnapshotIntegTestCase.unblockAllDataNodes(repoName);
204+
unblockAllDataNodes(repoName);
210205

211206
ensureStableCluster(2, masterNode);
212207
logger.info("--> done");
@@ -217,11 +212,11 @@ public void testDisruptionAfterShardFinalization() throws Exception {
217212
index(idxName, JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject());
218213

219214
logger.info("--> run a snapshot that fails to finalize but succeeds on the data node");
220-
AbstractSnapshotIntegTestCase.blockMasterFromFinalizingSnapshotOnIndexFile(repoName);
215+
blockMasterFromFinalizingSnapshotOnIndexFile(repoName);
221216
final ActionFuture<CreateSnapshotResponse> snapshotFuture =
222217
client(masterNode).admin().cluster().prepareCreateSnapshot(repoName, "snapshot-2").setWaitForCompletion(true).execute();
223-
AbstractSnapshotIntegTestCase.waitForBlock(masterNode, repoName, TimeValue.timeValueSeconds(10L));
224-
AbstractSnapshotIntegTestCase.unblockNode(repoName, masterNode);
218+
waitForBlock(masterNode, repoName, TimeValue.timeValueSeconds(10L));
219+
unblockNode(repoName, masterNode);
225220
assertFutureThrows(snapshotFuture, SnapshotException.class);
226221

227222
logger.info("--> create a snapshot expected to be successful");

server/src/internalClusterTest/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryCleanupIT.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.concurrent.ExecutionException;
3535
import java.util.concurrent.TimeUnit;
3636

37-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3837
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFutureThrows;
3938
import static org.hamcrest.Matchers.is;
4039

@@ -82,12 +81,9 @@ private String startBlockedCleanup(String repoName) throws Exception {
8281
internalCluster().startMasterOnlyNodes(2);
8382
internalCluster().startDataOnlyNodes(1);
8483

85-
logger.info("--> creating repository");
86-
assertAcked(client().admin().cluster().preparePutRepository(repoName)
87-
.setType("mock").setSettings(Settings.builder()
88-
.put("location", randomRepoPath())
89-
.put("compress", randomBoolean())
90-
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
84+
createRepository(repoName, "mock", Settings.builder()
85+
.put("location", randomRepoPath()).put("compress", randomBoolean())
86+
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
9187

9288
logger.info("--> snapshot");
9389
client().admin().cluster().prepareCreateSnapshot(repoName, "test-snap")
@@ -116,11 +112,8 @@ public void testCleanupOldIndexN() throws ExecutionException, InterruptedExcepti
116112
internalCluster().startNodes(Settings.EMPTY);
117113

118114
final String repoName = "test-repo";
119-
logger.info("--> creating repository");
120-
assertAcked(client().admin().cluster().preparePutRepository(repoName).setType("fs").setSettings(Settings.builder()
121-
.put("location", randomRepoPath())
122-
.put("compress", randomBoolean())
123-
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
115+
createRepository(repoName, "fs", Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean())
116+
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
124117

125118
logger.info("--> create three snapshots");
126119
for (int i = 0; i < 3; ++i) {

server/src/internalClusterTest/java/org/elasticsearch/snapshots/CorruptedBlobStoreRepositoryIT.java

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,11 @@ public void testConcurrentlyChangeRepositoryContents() throws Exception {
6666

6767
Path repo = randomRepoPath();
6868
final String repoName = "test-repo";
69-
logger.info("--> creating repository at {}", repo.toAbsolutePath());
70-
assertAcked(client.admin().cluster().preparePutRepository(repoName)
71-
.setType("fs").setSettings(Settings.builder()
72-
.put("location", repo)
73-
.put("compress", false)
74-
// Don't cache repository data because the test manually modifies the repository data
75-
.put(BlobStoreRepository.CACHE_REPOSITORY_DATA.getKey(), false)
76-
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
69+
createRepository(repoName, "fs", Settings.builder()
70+
.put("location", repo).put("compress", false)
71+
// Don't cache repository data because the test manually modifies the repository data
72+
.put(BlobStoreRepository.CACHE_REPOSITORY_DATA.getKey(), false)
73+
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
7774

7875
createIndex("test-idx-1", "test-idx-2");
7976
logger.info("--> indexing some data");
@@ -125,12 +122,9 @@ public void testConcurrentlyChangeRepositoryContents() throws Exception {
125122
public void testFindDanglingLatestGeneration() throws Exception {
126123
Path repo = randomRepoPath();
127124
final String repoName = "test-repo";
128-
logger.info("--> creating repository at {}", repo.toAbsolutePath());
129-
assertAcked(client().admin().cluster().preparePutRepository(repoName)
130-
.setType("fs").setSettings(Settings.builder()
131-
.put("location", repo)
132-
.put("compress", false)
133-
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
125+
createRepository(repoName, "fs", Settings.builder()
126+
.put("location", repo).put("compress", false)
127+
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
134128

135129
createIndex("test-idx-1", "test-idx-2");
136130
logger.info("--> indexing some data");
@@ -200,14 +194,12 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
200194
public void testHandlingMissingRootLevelSnapshotMetadata() throws Exception {
201195
Path repo = randomRepoPath();
202196
final String repoName = "test-repo";
203-
logger.info("--> creating repository at {}", repo.toAbsolutePath());
204-
assertAcked(client().admin().cluster().preparePutRepository(repoName)
205-
.setType("fs").setSettings(Settings.builder()
206-
.put("location", repo)
207-
.put("compress", false)
208-
// Don't cache repository data because the test manually modifies the repository data
209-
.put(BlobStoreRepository.CACHE_REPOSITORY_DATA.getKey(), false)
210-
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
197+
createRepository(repoName, "fs", Settings.builder()
198+
.put("location", repo)
199+
.put("compress", false)
200+
// Don't cache repository data because the test manually modifies the repository data
201+
.put(BlobStoreRepository.CACHE_REPOSITORY_DATA.getKey(), false)
202+
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
211203

212204
final String snapshotPrefix = "test-snap-";
213205
final int snapshots = randomIntBetween(1, 2);
@@ -268,13 +260,11 @@ public void testMountCorruptedRepositoryData() throws Exception {
268260

269261
Path repo = randomRepoPath();
270262
final String repoName = "test-repo";
271-
logger.info("--> creating repository at {}", repo.toAbsolutePath());
272-
assertAcked(client.admin().cluster().preparePutRepository(repoName)
273-
.setType("fs").setSettings(Settings.builder()
274-
.put("location", repo)
275-
// Don't cache repository data because the test manually modifies the repository data
276-
.put(BlobStoreRepository.CACHE_REPOSITORY_DATA.getKey(), false)
277-
.put("compress", false)));
263+
createRepository(repoName, "fs", Settings.builder()
264+
.put("location", repo)
265+
// Don't cache repository data because the test manually modifies the repository data
266+
.put(BlobStoreRepository.CACHE_REPOSITORY_DATA.getKey(), false)
267+
.put("compress", false));
278268

279269
final String snapshot = "test-snap";
280270

@@ -292,12 +282,9 @@ public void testMountCorruptedRepositoryData() throws Exception {
292282
logger.info("--> verify loading repository data throws RepositoryException");
293283
expectThrows(RepositoryException.class, () -> getRepositoryData(repository));
294284

295-
logger.info("--> mount repository path in a new repository");
296285
final String otherRepoName = "other-repo";
297-
assertAcked(client.admin().cluster().preparePutRepository(otherRepoName)
298-
.setType("fs").setSettings(Settings.builder()
299-
.put("location", repo)
300-
.put("compress", false)));
286+
createRepository(otherRepoName, "fs", Settings.builder()
287+
.put("location", repo).put("compress", false));
301288
final Repository otherRepo = internalCluster().getCurrentMasterNodeInstance(RepositoriesService.class).repository(otherRepoName);
302289

303290
logger.info("--> verify loading repository data from newly mounted repository throws RepositoryException");
@@ -317,7 +304,7 @@ public void testHandleSnapshotErrorWithBwCFormat() throws IOException {
317304
final String indexName = "test-index";
318305
createIndex(indexName);
319306

320-
assertCreateSnapshotSuccess(repoName, "snapshot-1");
307+
createFullSnapshot(repoName, "snapshot-1");
321308

322309
// In the old metadata version the shard level metadata could be moved to the next generation for all sorts of reasons, this should
323310
// not break subsequent repository operations
@@ -331,7 +318,7 @@ public void testHandleSnapshotErrorWithBwCFormat() throws IOException {
331318
logger.info("--> delete old version snapshot");
332319
client().admin().cluster().prepareDeleteSnapshot(repoName, oldVersionSnapshot).get();
333320

334-
assertCreateSnapshotSuccess(repoName, "snapshot-2");
321+
createFullSnapshot(repoName, "snapshot-2");
335322
}
336323

337324
public void testRepairBrokenShardGenerations() throws IOException {
@@ -347,7 +334,7 @@ public void testRepairBrokenShardGenerations() throws IOException {
347334
final String indexName = "test-index";
348335
createIndex(indexName);
349336

350-
assertCreateSnapshotSuccess(repoName, "snapshot-1");
337+
createFullSnapshot(repoName, "snapshot-1");
351338

352339
logger.info("--> delete old version snapshot");
353340
client().admin().cluster().prepareDeleteSnapshot(repoName, oldVersionSnapshot).get();
@@ -381,17 +368,7 @@ public void testRepairBrokenShardGenerations() throws IOException {
381368
client().admin().cluster().prepareDeleteRepository(repoName).get();
382369
createRepository(repoName, "fs", repoPath);
383370

384-
assertCreateSnapshotSuccess(repoName, "snapshot-2");
385-
}
386-
387-
private void assertCreateSnapshotSuccess(String repoName, String snapshotName) {
388-
logger.info("--> create another snapshot");
389-
final SnapshotInfo snapshotInfo = client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName)
390-
.setWaitForCompletion(true).get().getSnapshotInfo();
391-
assertThat(snapshotInfo.state(), is(SnapshotState.SUCCESS));
392-
final int successfulShards = snapshotInfo.successfulShards();
393-
assertThat(successfulShards, greaterThan(0));
394-
assertThat(successfulShards, equalTo(snapshotInfo.totalShards()));
371+
createFullSnapshot(repoName, "snapshot-2");
395372
}
396373

397374
private void assertRepositoryBlocked(Client client, String repo, String existingSnapshot) {

0 commit comments

Comments
 (0)