[7.x] Fix SnapshotLifecycleRestIT.testFullPolicySnapshot (#517… (#51778)
* Fix SnapshotLifecycleRestIT.testFullPolicySnapshot This previously was missing some key information in the output of the failure. This captures that information and adds logging at each step so we can determine the cause *if* it fails again. Resolves #50358
This commit is contained in:
parent
2e0bba0f63
commit
4594a210bf
|
@ -41,8 +41,10 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
@ -104,6 +106,11 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase {
|
|||
|
||||
createSnapshotPolicy(policyName, "snap", "*/1 * * * * ?", repoId, indexName, true);
|
||||
|
||||
// A test for whether the repository's snapshots have any snapshots starting with "snap-"
|
||||
Predicate<Map<String, Object>> repoHasSnapshot = snapMap -> Optional.ofNullable((String) snapMap.get("snapshot"))
|
||||
.map(snapName -> snapName.startsWith("snap-"))
|
||||
.orElse(false);
|
||||
|
||||
// Check that the snapshot was actually taken
|
||||
assertBusy(() -> {
|
||||
Response response = client().performRequest(new Request("GET", "/_snapshot/" + repoId + "/_all"));
|
||||
|
@ -112,14 +119,12 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase {
|
|||
snapshotResponseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
|
||||
}
|
||||
assertThat(snapshotResponseMap.size(), greaterThan(0));
|
||||
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);
|
||||
}
|
||||
Map<String, Object> snapResponse = ((List<Map<String, Object>>) snapshotResponseMap.get("snapshots")).stream()
|
||||
.peek(allReposSnapshots -> logger.info("--> all repository's snapshots: {}", allReposSnapshots))
|
||||
.filter(repoHasSnapshot)
|
||||
.peek(allRepos -> logger.info("--> snapshots with 'snap-' snapshot: {}", allRepos))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("failed to find snapshot response in " + snapshotResponseMap));
|
||||
assertThat(snapResponse.get("indices"), equalTo(Collections.singletonList(indexName)));
|
||||
Map<String, Object> metadata = (Map<String, Object>) snapResponse.get("metadata");
|
||||
assertNotNull(metadata);
|
||||
|
|
Loading…
Reference in New Issue