From 4594a210bff1c111c93d4137d761cfcab9437af6 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Fri, 31 Jan 2020 15:38:28 -0700 Subject: [PATCH] =?UTF-8?q?[7.x]=20Fix=20SnapshotLifecycleRestIT.testFullP?= =?UTF-8?q?olicySnapshot=20(#517=E2=80=A6=20(#51778)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../xpack/slm/SnapshotLifecycleRestIT.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java index f3f74ea41fc..78e08846a12 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java @@ -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> 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 snapResponse; - try { - List> snapshots = (List>) 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 snapResponse = ((List>) 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 metadata = (Map) snapResponse.get("metadata"); assertNotNull(metadata);