From 716904fab7bee5deec83a3707fce2d74a5daa052 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 27 Jan 2020 14:09:13 +0100 Subject: [PATCH] Unmuted test with more logging and removed unchecked suppress warnings. See #48381 --- x-pack/qa/full-cluster-restart/build.gradle | 1 + .../xpack/restart/FullClusterRestartIT.java | 61 ++++++++----------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/x-pack/qa/full-cluster-restart/build.gradle b/x-pack/qa/full-cluster-restart/build.gradle index c04e41c5be8..58a5365c785 100644 --- a/x-pack/qa/full-cluster-restart/build.gradle +++ b/x-pack/qa/full-cluster-restart/build.gradle @@ -85,6 +85,7 @@ for (Version bwcVersion : bwcVersions.indexCompatible) { setting 'xpack.security.transport.ssl.key', 'testnode.pem' setting 'xpack.security.transport.ssl.certificate', 'testnode.crt' keystore 'xpack.security.transport.ssl.secure_key_passphrase', 'testnode' + setting 'logger.org.elasticsearch.xpack.watcher', 'DEBUG' } } diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index 29bf8b87c94..f462ef36429 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -110,7 +110,6 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(toStr(client().performRequest(getRequest)), containsString(doc)); } - @SuppressWarnings("unchecked") public void testSecurityNativeRealm() throws Exception { if (isRunningAgainstOldCluster()) { createUser(true); @@ -125,9 +124,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { fail("The security index does not have the expected setting [index.format]"); } else { concreteSecurityIndex = settingsResponseMap.keySet().iterator().next(); - Map indexSettingsMap = - (Map) settingsResponseMap.get(concreteSecurityIndex); - Map settingsMap = (Map) indexSettingsMap.get("settings"); + Map indexSettingsMap = (Map) settingsResponseMap.get(concreteSecurityIndex); + Map settingsMap = (Map) indexSettingsMap.get("settings"); logger.info("settings map {}", settingsMap); if (settingsMap.containsKey("index")) { @SuppressWarnings("unchecked") @@ -145,8 +143,6 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertRoleInfo(isRunningAgainstOldCluster()); } - @SuppressWarnings("unchecked") - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/48381") public void testWatcher() throws Exception { if (isRunningAgainstOldCluster()) { logger.info("Adding a watch on old cluster {}", getOldClusterVersion()); @@ -199,11 +195,11 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { fail("The security index does not have the expected setting [index.format]"); } else { concreteWatchesIndex = settingsResponseMap.keySet().iterator().next(); - Map indexSettingsMap = (Map) settingsResponseMap.get(concreteWatchesIndex); - Map settingsMap = (Map) indexSettingsMap.get("settings"); + Map indexSettingsMap = (Map) settingsResponseMap.get(concreteWatchesIndex); + Map settingsMap = (Map) indexSettingsMap.get("settings"); logger.info("settings map {}", settingsMap); if (settingsMap.containsKey("index")) { - int format = Integer.parseInt(String.valueOf(((Map)settingsMap.get("index")).get("format"))); + int format = Integer.parseInt(String.valueOf(((Map)settingsMap.get("index")).get("format"))); assertEquals("The watches index needs to be upgraded", UPGRADE_FIELD_EXPECTED_INDEX_FORMAT_VERSION, format); } } @@ -213,9 +209,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(startWatchResponse.get("acknowledged"), equalTo(Boolean.TRUE)); assertBusy(() -> { Map statsWatchResponse = entityAsMap(client().performRequest(new Request("GET", "_watcher/stats"))); - @SuppressWarnings("unchecked") - List states = ((List) statsWatchResponse.get("stats")) - .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); + List states = ((List) statsWatchResponse.get("stats")) + .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); assertThat(states, everyItem(is("started"))); }); @@ -232,9 +227,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertBusy(() -> { Map statsStoppedWatchResponse = entityAsMap(client().performRequest( new Request("GET", "_watcher/stats"))); - @SuppressWarnings("unchecked") - List states = ((List) statsStoppedWatchResponse.get("stats")) - .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); + List states = ((List) statsStoppedWatchResponse.get("stats")) + .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); assertThat(states, everyItem(is("stopped"))); }); } @@ -625,20 +619,19 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(response.get("timed_out"), equalTo(Boolean.FALSE)); } - @SuppressWarnings("unchecked") private void waitForHits(String indexName, int expectedHits) throws Exception { Request request = new Request("GET", "/" + indexName + "/_search"); request.addParameter("size", "0"); assertBusy(() -> { try { Map response = entityAsMap(client().performRequest(request)); - Map hits = (Map) response.get("hits"); + Map hits = (Map) response.get("hits"); logger.info("Hits are: {}", hits); - int total; + Integer total; if (getOldClusterVersion().onOrAfter(Version.V_7_0_0) || isRunningAgainstOldCluster() == false) { - total = (int) ((Map) hits.get("total")).get("value"); + total = (Integer) ((Map) hits.get("total")).get("value"); } else { - total = (int) hits.get("total"); + total = (Integer) hits.get("total"); } assertThat(total, greaterThanOrEqualTo(expectedHits)); } catch (IOException ioe) { @@ -744,7 +737,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { private void assertRoleInfo(final boolean oldCluster) throws Exception { final String role = oldCluster ? "preupgrade_role" : "postupgrade_role"; - @SuppressWarnings("unchecked") Map response = (Map) entityAsMap( + Map response = (Map) entityAsMap( client().performRequest(new Request("GET", getSecurityEndpoint() + "/role/" + role)) ).get(role); assertNotNull(response.get("run_as")); @@ -752,7 +745,6 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertNotNull(response.get("indices")); } - @SuppressWarnings("unchecked") private void assertRollUpJob(final String rollupJob) throws Exception { final Matcher expectedStates = anyOf(equalTo("indexing"), equalTo("started")); waitForRollUpJob(rollupJob, expectedStates); @@ -760,7 +752,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { // check that the rollup job is started using the RollUp API final Request getRollupJobRequest = new Request("GET", getRollupEndpoint() + "/job/" + rollupJob); Map getRollupJobResponse = entityAsMap(client().performRequest(getRollupJobRequest)); - Map job = getJob(getRollupJobResponse, rollupJob); + Map job = getJob(getRollupJobResponse, rollupJob); assertNotNull(job); assertThat(ObjectPath.eval("status.job_state", job), expectedStates); @@ -769,10 +761,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { taskRequest.addParameter("detailed", "true"); taskRequest.addParameter("actions", "xpack/rollup/*"); Map taskResponse = entityAsMap(client().performRequest(taskRequest)); - Map taskResponseNodes = (Map) taskResponse.get("nodes"); - Map taskResponseNode = (Map) taskResponseNodes.values().iterator().next(); - Map taskResponseTasks = (Map) taskResponseNode.get("tasks"); - Map taskResponseStatus = (Map) taskResponseTasks.values().iterator().next(); + Map taskResponseNodes = (Map) taskResponse.get("nodes"); + Map taskResponseNode = (Map) taskResponseNodes.values().iterator().next(); + Map taskResponseTasks = (Map) taskResponseNode.get("tasks"); + Map taskResponseStatus = (Map) taskResponseTasks.values().iterator().next(); assertThat(ObjectPath.eval("status.job_state", taskResponseStatus), expectedStates); // check that the rollup job is started using the Cluster State API @@ -808,28 +800,27 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { Response getRollupJobResponse = client().performRequest(getRollupJobRequest); assertThat(getRollupJobResponse.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); - Map job = getJob(getRollupJobResponse, rollupJob); + Map job = getJob(getRollupJobResponse, rollupJob); assertNotNull(job); assertThat(ObjectPath.eval("status.job_state", job), expectedStates); }, 30L, TimeUnit.SECONDS); } - private Map getJob(Response response, String targetJobId) throws IOException { + private Map getJob(Response response, String targetJobId) throws IOException { return getJob(ESRestTestCase.entityAsMap(response), targetJobId); } - @SuppressWarnings("unchecked") - private Map getJob(Map jobsMap, String targetJobId) throws IOException { + private Map getJob(Map jobsMap, String targetJobId) throws IOException { - List> jobs = - (List>) XContentMapValues.extractValue("jobs", jobsMap); + List jobs = (List) XContentMapValues.extractValue("jobs", jobsMap); if (jobs == null) { return null; } - for (Map job : jobs) { - String jobId = (String) ((Map) job.get("config")).get("id"); + for (Object entry : jobs) { + Map job = (Map) entry; + String jobId = (String) ((Map) job.get("config")).get("id"); if (jobId.equals(targetJobId)) { return job; }