Skip to content

Commit 2e60abb

Browse files
committed
[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 129804a commit 2e60abb

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@
8585
import org.elasticsearch.plugins.Plugin;
8686
import org.elasticsearch.repositories.IndexId;
8787
import org.elasticsearch.repositories.RepositoriesService;
88+
import org.elasticsearch.repositories.Repository;
8889
import org.elasticsearch.repositories.RepositoryData;
8990
import org.elasticsearch.repositories.RepositoryException;
9091
import org.elasticsearch.script.MockScriptEngine;
9192
import org.elasticsearch.script.StoredScriptsIT;
9293
import org.elasticsearch.snapshots.mockstore.MockRepository;
9394
import org.elasticsearch.test.junit.annotations.TestLogging;
9495

96+
import java.io.IOException;
9597
import java.nio.channels.SeekableByteChannel;
9698
import java.nio.file.Files;
9799
import java.nio.file.Path;
@@ -1241,30 +1243,44 @@ public void testDeleteSnapshotWithMissingIndexAndShardMetadata() throws Exceptio
12411243
.put("compress", false)
12421244
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
12431245

1244-
createIndex("test-idx-1", "test-idx-2");
1246+
final String[] indices = {"test-idx-1", "test-idx-2"};
1247+
createIndex(indices);
12451248
logger.info("--> indexing some data");
12461249
indexRandom(true,
12471250
client().prepareIndex("test-idx-1", "_doc").setSource("foo", "bar"),
12481251
client().prepareIndex("test-idx-2", "_doc").setSource("foo", "bar"));
12491252

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

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

12631275
logger.info("--> delete snapshot");
12641276
client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();
12651277

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

12701286
public void testDeleteSnapshotWithMissingMetadata() throws Exception {
@@ -1357,9 +1373,13 @@ public void testSnapshotWithMissingShardLevelIndexFile() throws Exception {
13571373

13581374
logger.info("--> deleting shard level index file");
13591375
try (Stream<Path> files = Files.list(repo.resolve("indices"))) {
1360-
files.forEach(indexPath ->
1361-
IOUtils.deleteFilesIgnoringExceptions(indexPath.resolve("0").resolve("index-0"))
1362-
);
1376+
files.forEach(indexPath -> {
1377+
try {
1378+
Files.delete(indexPath.resolve("0").resolve("index-0"));
1379+
} catch (IOException e) {
1380+
throw new RuntimeException("Failed to delete expected file", e);
1381+
}
1382+
});
13631383
}
13641384

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

0 commit comments

Comments
 (0)