Skip to content

Commit a6624bb

Browse files
authored
[Test] Update test in SharedClusterSnapshotRestoreIT (#30200)
The `testDeleteSnapshotWithMissingIndexAndShardMetadata` test uses an obsolete repository directory structure based on index names instead of UUIDs. Because it swallows exceptions when deleting test files the test never failed when the directory structure changed. This commit fixes the test to use the right directory structure and file names and to not swallow exceptions anymore.
1 parent 0a6312a commit a6624bb

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import org.elasticsearch.snapshots.mockstore.MockRepository;
9494
import org.elasticsearch.test.junit.annotations.TestLogging;
9595

96+
import java.io.IOException;
9697
import java.nio.channels.SeekableByteChannel;
9798
import java.nio.file.Files;
9899
import java.nio.file.Path;
@@ -1243,30 +1244,44 @@ public void testDeleteSnapshotWithMissingIndexAndShardMetadata() throws Exceptio
12431244
.put("compress", false)
12441245
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
12451246

1246-
createIndex("test-idx-1", "test-idx-2");
1247+
final String[] indices = {"test-idx-1", "test-idx-2"};
1248+
createIndex(indices);
12471249
logger.info("--> indexing some data");
12481250
indexRandom(true,
12491251
client().prepareIndex("test-idx-1", "_doc").setSource("foo", "bar"),
12501252
client().prepareIndex("test-idx-2", "_doc").setSource("foo", "bar"));
12511253

12521254
logger.info("--> creating snapshot");
1253-
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).setIndices("test-idx-*").get();
1254-
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
1255-
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
1255+
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1")
1256+
.setWaitForCompletion(true).setIndices(indices).get();
1257+
final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo();
1258+
assertThat(snapshotInfo.successfulShards(), greaterThan(0));
1259+
assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards()));
1260+
1261+
RepositoriesService service = internalCluster().getInstance(RepositoriesService.class, internalCluster().getMasterName());
1262+
Repository repository = service.repository("test-repo");
1263+
1264+
final Map<String, IndexId> indexIds = repository.getRepositoryData().getIndices();
1265+
final Path indicesPath = repo.resolve("indices");
12561266

12571267
logger.info("--> delete index metadata and shard metadata");
1258-
Path indices = repo.resolve("indices");
1259-
Path testIndex1 = indices.resolve("test-idx-1");
1260-
Path testIndex2 = indices.resolve("test-idx-2");
1261-
Path testIndex2Shard0 = testIndex2.resolve("0");
1262-
IOUtils.deleteFilesIgnoringExceptions(testIndex1.resolve("snapshot-test-snap-1"));
1263-
IOUtils.deleteFilesIgnoringExceptions(testIndex2Shard0.resolve("snapshot-test-snap-1"));
1268+
for (String index : indices) {
1269+
Path shardZero = indicesPath.resolve(indexIds.get(index).getId()).resolve("0");
1270+
if (randomBoolean()) {
1271+
Files.delete(shardZero.resolve("index-0"));
1272+
}
1273+
Files.delete(shardZero.resolve("snap-" + snapshotInfo.snapshotId().getUUID() + ".dat"));
1274+
}
12641275

12651276
logger.info("--> delete snapshot");
12661277
client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();
12671278

12681279
logger.info("--> make sure snapshot doesn't exist");
12691280
assertThrows(client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap-1"), SnapshotMissingException.class);
1281+
1282+
for (String index : indices) {
1283+
assertTrue(Files.notExists(indicesPath.resolve(indexIds.get(index).getId())));
1284+
}
12701285
}
12711286

12721287
public void testDeleteSnapshotWithMissingMetadata() throws Exception {
@@ -1420,9 +1435,13 @@ public void testSnapshotWithMissingShardLevelIndexFile() throws Exception {
14201435

14211436
logger.info("--> deleting shard level index file");
14221437
try (Stream<Path> files = Files.list(repo.resolve("indices"))) {
1423-
files.forEach(indexPath ->
1424-
IOUtils.deleteFilesIgnoringExceptions(indexPath.resolve("0").resolve("index-0"))
1425-
);
1438+
files.forEach(indexPath -> {
1439+
try {
1440+
Files.delete(indexPath.resolve("0").resolve("index-0"));
1441+
} catch (IOException e) {
1442+
throw new RuntimeException("Failed to delete expected file", e);
1443+
}
1444+
});
14261445
}
14271446

14281447
logger.info("--> creating another snapshot");

0 commit comments

Comments
 (0)