Skip to content

Commit ab52ab4

Browse files
committed
Randomize the number of snapshots in deleteSnapshotTest
1 parent e32f16b commit ab52ab4

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/test/java/org/elasticsearch/snapshots/AbstractSnapshotTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.snapshots.mockstore.MockRepository;
2828
import org.elasticsearch.test.ElasticsearchIntegrationTest;
2929
import org.junit.After;
30+
import org.junit.Before;
3031
import org.junit.Ignore;
3132

3233
import java.io.File;
@@ -45,7 +46,7 @@ public final void wipeAfter() {
4546
wipeRepositories();
4647
}
4748

48-
@After
49+
@Before
4950
public final void wipeBefore() {
5051
wipeRepositories();
5152
}

src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public void includeGlobalStateTest() throws Exception {
269269
}
270270

271271
@Test
272-
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix")
272+
@LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
273273
public void snapshotFileFailureDuringSnapshotTest() throws Exception {
274274
Client client = client();
275275

@@ -322,7 +322,7 @@ public void snapshotFileFailureDuringSnapshotTest() throws Exception {
322322
}
323323

324324
@Test
325-
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix")
325+
@LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
326326
public void dataFileFailureDuringSnapshotTest() throws Exception {
327327
Client client = client();
328328
logger.info("--> creating repository");
@@ -367,7 +367,7 @@ public void dataFileFailureDuringSnapshotTest() throws Exception {
367367
}
368368

369369
@Test
370-
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix")
370+
@LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
371371
public void dataFileFailureDuringRestoreTest() throws Exception {
372372
File repositoryLocation = newTempDir(LifecycleScope.TEST);
373373
Client client = client();
@@ -415,7 +415,7 @@ public void dataFileFailureDuringRestoreTest() throws Exception {
415415

416416
@Test
417417
@TestLogging("snapshots:TRACE")
418-
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix")
418+
@LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
419419
public void deletionOfFailingToRecoverIndexShouldStopRestore() throws Exception {
420420
File repositoryLocation = newTempDir(LifecycleScope.TEST);
421421
Client client = client();
@@ -507,6 +507,7 @@ public void unallocatedShardsTest() throws Exception {
507507

508508
@Test
509509
public void deleteSnapshotTest() throws Exception {
510+
final int numberOfSnapshots = between(5, 15);
510511
Client client = client();
511512

512513
File repo = newTempDir(LifecycleScope.SUITE);
@@ -520,9 +521,9 @@ public void deleteSnapshotTest() throws Exception {
520521
createIndex("test-idx");
521522
ensureGreen();
522523

523-
int[] numberOfFiles = new int[10];
524-
logger.info("--> creating 10 snapshots data");
525-
for (int i = 0; i < 10; i++) {
524+
int[] numberOfFiles = new int[numberOfSnapshots];
525+
logger.info("--> creating {} snapshots ", numberOfSnapshots);
526+
for (int i = 0; i < numberOfSnapshots; i++) {
526527
for (int j = 0; j < 10; j++) {
527528
index("test-idx", "doc", Integer.toString(i * 10 + j), "foo", "bar" + i * 10 + j);
528529
}
@@ -534,11 +535,11 @@ public void deleteSnapshotTest() throws Exception {
534535
// Store number of files after each snapshot
535536
numberOfFiles[i] = numberOfFiles(repo);
536537
}
537-
assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(100L));
538+
assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(10L * numberOfSnapshots));
538539
int numberOfFilesBeforeDeletion = numberOfFiles(repo);
539540

540541
logger.info("--> delete all snapshots except the first one and last one");
541-
for (int i = 1; i < 9; i++) {
542+
for (int i = 1; i < numberOfSnapshots - 1; i++) {
542543
run(client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-" + i));
543544
}
544545

@@ -550,17 +551,17 @@ public void deleteSnapshotTest() throws Exception {
550551
wipeIndex("test-idx");
551552

552553
logger.info("--> restore index");
553-
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap-9").setWaitForCompletion(true).execute().actionGet();
554+
String lastSnapshot = "test-snap-" + (numberOfSnapshots - 1);
555+
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", lastSnapshot).setWaitForCompletion(true).execute().actionGet();
554556
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
555557

556558
ensureGreen();
557-
assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(100L));
559+
assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(10L * numberOfSnapshots));
558560

559561
logger.info("--> delete the last snapshot");
560-
run(client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-9"));
562+
run(client.admin().cluster().prepareDeleteSnapshot("test-repo", lastSnapshot));
561563
logger.info("--> make sure that number of files is back to what it was when the first snapshot was made");
562564
assertThat(numberOfFiles(repo), equalTo(numberOfFiles[0]));
563-
564565
}
565566

566567
@Test
@@ -664,7 +665,7 @@ public void renameOnRestoreTest() throws Exception {
664665

665666
@Test
666667
@TestLogging("cluster.routing.allocation.decider:TRACE")
667-
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix")
668+
// @LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix")
668669
public void moveShardWhileSnapshottingTest() throws Exception {
669670
Client client = client();
670671
File repositoryLocation = newTempDir(LifecycleScope.TEST);

0 commit comments

Comments
 (0)