Randomize the number of snapshots in deleteSnapshotTest

This commit is contained in:
Igor Motov 2013-11-11 14:42:43 -05:00
parent e32f16b789
commit ab52ab48dd
2 changed files with 17 additions and 15 deletions

View File

@ -27,6 +27,7 @@ import org.elasticsearch.repositories.RepositoryMissingException;
import org.elasticsearch.snapshots.mockstore.MockRepository; import org.elasticsearch.snapshots.mockstore.MockRepository;
import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.After; import org.junit.After;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import java.io.File; import java.io.File;
@ -45,7 +46,7 @@ public abstract class AbstractSnapshotTests extends ElasticsearchIntegrationTest
wipeRepositories(); wipeRepositories();
} }
@After @Before
public final void wipeBefore() { public final void wipeBefore() {
wipeRepositories(); wipeRepositories();
} }

View File

@ -269,7 +269,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
} }
@Test @Test
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix") @LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
public void snapshotFileFailureDuringSnapshotTest() throws Exception { public void snapshotFileFailureDuringSnapshotTest() throws Exception {
Client client = client(); Client client = client();
@ -322,7 +322,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
} }
@Test @Test
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix") @LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
public void dataFileFailureDuringSnapshotTest() throws Exception { public void dataFileFailureDuringSnapshotTest() throws Exception {
Client client = client(); Client client = client();
logger.info("--> creating repository"); logger.info("--> creating repository");
@ -367,7 +367,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
} }
@Test @Test
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix") @LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
public void dataFileFailureDuringRestoreTest() throws Exception { public void dataFileFailureDuringRestoreTest() throws Exception {
File repositoryLocation = newTempDir(LifecycleScope.TEST); File repositoryLocation = newTempDir(LifecycleScope.TEST);
Client client = client(); Client client = client();
@ -415,7 +415,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
@Test @Test
@TestLogging("snapshots:TRACE") @TestLogging("snapshots:TRACE")
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix") @LuceneTestCase.AwaitsFix(bugUrl = "imotov is working on the fix")
public void deletionOfFailingToRecoverIndexShouldStopRestore() throws Exception { public void deletionOfFailingToRecoverIndexShouldStopRestore() throws Exception {
File repositoryLocation = newTempDir(LifecycleScope.TEST); File repositoryLocation = newTempDir(LifecycleScope.TEST);
Client client = client(); Client client = client();
@ -507,6 +507,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
@Test @Test
public void deleteSnapshotTest() throws Exception { public void deleteSnapshotTest() throws Exception {
final int numberOfSnapshots = between(5, 15);
Client client = client(); Client client = client();
File repo = newTempDir(LifecycleScope.SUITE); File repo = newTempDir(LifecycleScope.SUITE);
@ -520,9 +521,9 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
createIndex("test-idx"); createIndex("test-idx");
ensureGreen(); ensureGreen();
int[] numberOfFiles = new int[10]; int[] numberOfFiles = new int[numberOfSnapshots];
logger.info("--> creating 10 snapshots data"); logger.info("--> creating {} snapshots ", numberOfSnapshots);
for (int i = 0; i < 10; i++) { for (int i = 0; i < numberOfSnapshots; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
index("test-idx", "doc", Integer.toString(i * 10 + j), "foo", "bar" + i * 10 + j); index("test-idx", "doc", Integer.toString(i * 10 + j), "foo", "bar" + i * 10 + j);
} }
@ -534,11 +535,11 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
// Store number of files after each snapshot // Store number of files after each snapshot
numberOfFiles[i] = numberOfFiles(repo); numberOfFiles[i] = numberOfFiles(repo);
} }
assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(100L)); assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(10L * numberOfSnapshots));
int numberOfFilesBeforeDeletion = numberOfFiles(repo); int numberOfFilesBeforeDeletion = numberOfFiles(repo);
logger.info("--> delete all snapshots except the first one and last one"); logger.info("--> delete all snapshots except the first one and last one");
for (int i = 1; i < 9; i++) { for (int i = 1; i < numberOfSnapshots - 1; i++) {
run(client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-" + i)); run(client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-" + i));
} }
@ -550,17 +551,17 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
wipeIndex("test-idx"); wipeIndex("test-idx");
logger.info("--> restore index"); logger.info("--> restore index");
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap-9").setWaitForCompletion(true).execute().actionGet(); String lastSnapshot = "test-snap-" + (numberOfSnapshots - 1);
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", lastSnapshot).setWaitForCompletion(true).execute().actionGet();
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
ensureGreen(); ensureGreen();
assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(100L)); assertThat(run(client.prepareCount("test-idx")).getCount(), equalTo(10L * numberOfSnapshots));
logger.info("--> delete the last snapshot"); logger.info("--> delete the last snapshot");
run(client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-9")); run(client.admin().cluster().prepareDeleteSnapshot("test-repo", lastSnapshot));
logger.info("--> make sure that number of files is back to what it was when the first snapshot was made"); logger.info("--> make sure that number of files is back to what it was when the first snapshot was made");
assertThat(numberOfFiles(repo), equalTo(numberOfFiles[0])); assertThat(numberOfFiles(repo), equalTo(numberOfFiles[0]));
} }
@Test @Test
@ -664,7 +665,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
@Test @Test
@TestLogging("cluster.routing.allocation.decider:TRACE") @TestLogging("cluster.routing.allocation.decider:TRACE")
@LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix") // @LuceneTestCase.AwaitsFix(bugUrl="imotov is working on the fix")
public void moveShardWhileSnapshottingTest() throws Exception { public void moveShardWhileSnapshottingTest() throws Exception {
Client client = client(); Client client = client();
File repositoryLocation = newTempDir(LifecycleScope.TEST); File repositoryLocation = newTempDir(LifecycleScope.TEST);