Skip to content

Commit 8560847

Browse files
authored
[7.x] Check all snapshots in SnapshotLifecycleRestIT.testFullP… (#51448)
* Check all snapshots in SnapshotLifecycleRestIT.testFullPolicy Rather than check the first returned snapshot for a snapshot starting with `snap-` in SnapshotLifecycleRestIT.testFullPolicy, this commit changes the test to find any snapshots starting with `snap-`. In the event that there are no snapshots (the failure case), this also exposes the full results map so we can diagnose why a failure occurred. Relates to #50358 * Use a more imperative style for checking
1 parent 2425a1a commit 8560847

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@ public void testFullPolicySnapshot() throws Exception {
105105
snapshotResponseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
106106
}
107107
assertThat(snapshotResponseMap.size(), greaterThan(0));
108-
assertThat(((List<Map<String, Object>>) snapshotResponseMap.get("snapshots")).size(), greaterThan(0));
109-
Map<String, Object> snapResponse = ((List<Map<String, Object>>) snapshotResponseMap.get("snapshots")).get(0);
110-
assertThat(snapResponse.get("snapshot").toString(), startsWith("snap-"));
108+
final Map<String, Object> snapResponse;
109+
try {
110+
List<Map<String, Object>> snapshots = (List<Map<String, Object>>) snapshotResponseMap.get("snapshots");
111+
assertTrue(snapshots.stream().anyMatch(s -> s.containsKey("snapshot") && s.get("snapshot").toString().startsWith("snap-")));
112+
snapResponse = snapshots.get(0);
113+
} catch (Exception e) {
114+
throw new AssertionError("failed to find snapshot response in " + snapshotResponseMap, e);
115+
}
111116
assertThat(snapResponse.get("indices"), equalTo(Collections.singletonList(indexName)));
112117
Map<String, Object> metadata = (Map<String, Object>) snapResponse.get("metadata");
113118
assertNotNull(metadata);

0 commit comments

Comments
 (0)