[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
This commit is contained in:
Lee Hinman 2020-01-24 14:30:42 -07:00 committed by GitHub
parent 2425a1a890
commit 8560847dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,9 +105,14 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase {
snapshotResponseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
}
assertThat(snapshotResponseMap.size(), greaterThan(0));
assertThat(((List<Map<String, Object>>) snapshotResponseMap.get("snapshots")).size(), greaterThan(0));
Map<String, Object> snapResponse = ((List<Map<String, Object>>) snapshotResponseMap.get("snapshots")).get(0);
assertThat(snapResponse.get("snapshot").toString(), startsWith("snap-"));
final Map<String, Object> snapResponse;
try {
List<Map<String, Object>> snapshots = (List<Map<String, Object>>) snapshotResponseMap.get("snapshots");
assertTrue(snapshots.stream().anyMatch(s -> s.containsKey("snapshot") && s.get("snapshot").toString().startsWith("snap-")));
snapResponse = snapshots.get(0);
} catch (Exception e) {
throw new AssertionError("failed to find snapshot response in " + snapshotResponseMap, e);
}
assertThat(snapResponse.get("indices"), equalTo(Collections.singletonList(indexName)));
Map<String, Object> metadata = (Map<String, Object>) snapResponse.get("metadata");
assertNotNull(metadata);