[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:
Lee Hinman 2020-01-31 15:38:28 -07:00 committed by GitHub
parent 2e0bba0f63
commit 4594a210bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 8 deletions

View File

@ -41,8 +41,10 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -104,6 +106,11 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase {
createSnapshotPolicy(policyName, "snap", "*/1 * * * * ?", repoId, indexName, true); 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 // Check that the snapshot was actually taken
assertBusy(() -> { assertBusy(() -> {
Response response = client().performRequest(new Request("GET", "/_snapshot/" + repoId + "/_all")); 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); snapshotResponseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
} }
assertThat(snapshotResponseMap.size(), greaterThan(0)); assertThat(snapshotResponseMap.size(), greaterThan(0));
final Map<String, Object> snapResponse; Map<String, Object> snapResponse = ((List<Map<String, Object>>) snapshotResponseMap.get("snapshots")).stream()
try { .peek(allReposSnapshots -> logger.info("--> all repository's snapshots: {}", allReposSnapshots))
List<Map<String, Object>> snapshots = (List<Map<String, Object>>) snapshotResponseMap.get("snapshots"); .filter(repoHasSnapshot)
assertTrue(snapshots.stream().anyMatch(s -> s.containsKey("snapshot") && s.get("snapshot").toString().startsWith("snap-"))); .peek(allRepos -> logger.info("--> snapshots with 'snap-' snapshot: {}", allRepos))
snapResponse = snapshots.get(0); .findFirst()
} catch (Exception e) { .orElseThrow(() -> new AssertionError("failed to find snapshot response in " + snapshotResponseMap));
throw new AssertionError("failed to find snapshot response in " + snapshotResponseMap, e);
}
assertThat(snapResponse.get("indices"), equalTo(Collections.singletonList(indexName))); assertThat(snapResponse.get("indices"), equalTo(Collections.singletonList(indexName)));
Map<String, Object> metadata = (Map<String, Object>) snapResponse.get("metadata"); Map<String, Object> metadata = (Map<String, Object>) snapResponse.get("metadata");
assertNotNull(metadata); assertNotNull(metadata);