Skip to content

Commit

Permalink
[7.x] Fix SnapshotLifecycleRestIT.testFullPolicySnapshot (#517… (#51778)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dakrone committed Jan 31, 2020
1 parent 2e0bba0 commit 4594a21
Showing 1 changed file with 13 additions and 8 deletions.
Expand Up @@ -41,8 +41,10 @@
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;
Expand Down Expand Up @@ -104,6 +106,11 @@ public void testFullPolicySnapshot() throws Exception {

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"));
Expand All @@ -112,14 +119,12 @@ public void testFullPolicySnapshot() throws Exception {
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);
Expand Down

0 comments on commit 4594a21

Please sign in to comment.