From fb5b6fb69f2de324b0ae177a164c12d7d6904173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Fern=C3=A1ndez=20Casta=C3=B1o?= Date: Wed, 11 Aug 2021 16:31:44 +0200 Subject: [PATCH] Fix IndexSnapshotsServiceIT and SnapshotsRecoveryPlannerServiceTests Closes #76343 Backport of #76351 --- .../repositories/IndexSnapshotsServiceIT.java | 8 +++++--- .../plan/SnapshotsRecoveryPlannerServiceTests.java | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/repositories/IndexSnapshotsServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/repositories/IndexSnapshotsServiceIT.java index 4cee3a7b2bb85..074608f6a434b 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/repositories/IndexSnapshotsServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/repositories/IndexSnapshotsServiceIT.java @@ -209,10 +209,11 @@ public void testGetShardSnapshotFailureHandlingLetOtherRepositoriesRequestsMakeP createIndexWithContent(indexName); int snapshotIdx = 0; - createSnapshot(failingRepoName, "empty-snap-" + snapshotIdx++, Collections.singletonList(indexName)); + createSnapshot(failingRepoName, String.format(Locale.ROOT, "snap-%03d", snapshotIdx++), Collections.singletonList(indexName)); SnapshotInfo latestSnapshot = null; for (String workingRepoName : workingRepoNames) { - latestSnapshot = createSnapshot(workingRepoName, "empty-snap-" + snapshotIdx++, Collections.singletonList(indexName)); + String snapshot = String.format(Locale.ROOT, "snap-%03d", snapshotIdx++); + latestSnapshot = createSnapshot(workingRepoName, snapshot, Collections.singletonList(indexName)); } final MockRepository repository = getRepositoryOnMaster(failingRepoName); @@ -266,7 +267,8 @@ public void testGetShardSnapshotInMultipleRepositoriesReturnsTheLatestSnapshot() int snapshotIdx = 0; SnapshotInfo expectedLatestSnapshot = null; for (String repository : repositories) { - expectedLatestSnapshot = createSnapshot(repository, "snap-" + snapshotIdx++, Collections.singletonList(indexName)); + String snapshot = String.format(Locale.ROOT, "snap-%03d", snapshotIdx++); + expectedLatestSnapshot = createSnapshot(repository, snapshot, Collections.singletonList(indexName)); } GetShardSnapshotResponse response = getLatestSnapshotForShardFuture(repositories, indexName, 0).actionGet(); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java index b8156e4c2d0a0..6d00b3a931ef1 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java @@ -258,7 +258,11 @@ public void testPlannerTriesToUseMostFilesFromSnapshots() throws Exception { new ShardSnapshotsService(null, null, null, null) { @Override public void fetchLatestSnapshotsForShard(ShardId shardId, ActionListener> listener) { - listener.onResponse(Optional.of(availableSnapshots.get(availableSnapshots.size() - 1))); + if (availableSnapshots.isEmpty()) { + listener.onResponse(Optional.empty()); + } else { + listener.onResponse(Optional.of(availableSnapshots.get(availableSnapshots.size() - 1))); + } } }, true