From 354595964281cd69e551584d7529bca5fde937c5 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 10 May 2023 10:16:23 -0700 Subject: [PATCH] Fix flakiness for getNodeRoles based tests (#7395) (#7506) (cherry picked from commit b65047fe7ecdf429e167f0b9844997a860441fa0) Signed-off-by: Kunal Kotwani Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../admin/cluster/stats/ClusterStatsIT.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java index 1fa9ef2f91712..cc1f8169afd3f 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java @@ -37,6 +37,7 @@ import org.opensearch.action.admin.cluster.node.stats.NodeStats; import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest; import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse; +import org.opensearch.client.Client; import org.opensearch.client.Requests; import org.opensearch.cluster.health.ClusterHealthStatus; import org.opensearch.cluster.node.DiscoveryNodeRole; @@ -152,11 +153,12 @@ public void testNodeCountsWithDeprecatedMasterRole() throws ExecutionException, Map expectedCounts = getExpectedCounts(0, 1, 1, 0, 0, 0, 0); - ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get(); + Client client = client(); + ClusterStatsResponse response = client.admin().cluster().prepareClusterStats().get(); assertCounts(response.getNodesStats().getCounts(), total, expectedCounts); Set expectedRoles = Set.of(DiscoveryNodeRole.MASTER_ROLE.roleName()); - assertEquals(expectedRoles, getNodeRoles(0)); + assertEquals(expectedRoles, getNodeRoles(client, 0)); } private static void incrementCountForRole(String role, Map counts) { @@ -327,14 +329,15 @@ public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, I Map expectedCounts = getExpectedCounts(0, 1, 1, 0, 1, 0, 0); - ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); + Client client = client(); + ClusterStatsResponse clusterStatsResponse = client.admin().cluster().prepareClusterStats().get(); assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedCounts); Set expectedRoles = Set.of( DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName() ); - assertEquals(expectedRoles, getNodeRoles(0)); + assertEquals(expectedRoles, getNodeRoles(client, 0)); } public void testNodeRolesWithClusterManagerRole() throws ExecutionException, InterruptedException { @@ -356,14 +359,15 @@ public void testNodeRolesWithClusterManagerRole() throws ExecutionException, Int Map expectedCounts = getExpectedCounts(0, 1, 1, 0, 1, 0, 0); - ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); + Client client = client(); + ClusterStatsResponse clusterStatsResponse = client.admin().cluster().prepareClusterStats().get(); assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedCounts); Set expectedRoles = Set.of( DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName() ); - assertEquals(expectedRoles, getNodeRoles(0)); + assertEquals(expectedRoles, getNodeRoles(client, 0)); } public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionException, InterruptedException { @@ -379,7 +383,8 @@ public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionExcept Map expectedRoleCounts = getExpectedCounts(1, 1, 1, 0, 1, 0, 0); - ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); + Client client = client(); + ClusterStatsResponse clusterStatsResponse = client.admin().cluster().prepareClusterStats().get(); assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedRoleCounts); Set expectedRoles = Set.of( @@ -387,7 +392,7 @@ public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionExcept DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), DiscoveryNodeRole.DATA_ROLE.roleName() ); - assertEquals(expectedRoles, getNodeRoles(0)); + assertEquals(expectedRoles, getNodeRoles(client, 0)); } public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException, InterruptedException { @@ -405,14 +410,15 @@ public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException, Map expectedRoleCounts = getExpectedCounts(1, 1, 1, 0, 1, 0, 0); - ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); + Client client = client(); + ClusterStatsResponse clusterStatsResponse = client.admin().cluster().prepareClusterStats().get(); assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedRoleCounts); Set> expectedNodesRoles = Set.of( Set.of(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName()), Set.of(DiscoveryNodeRole.DATA_ROLE.roleName(), DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName()) ); - assertEquals(expectedNodesRoles, Set.of(getNodeRoles(0), getNodeRoles(1))); + assertEquals(expectedNodesRoles, Set.of(getNodeRoles(client, 0), getNodeRoles(client, 1))); } private Map getExpectedCounts( @@ -435,8 +441,8 @@ private Map getExpectedCounts( return expectedCounts; } - private Set getNodeRoles(int nodeNumber) throws ExecutionException, InterruptedException { - NodesStatsResponse nodesStatsResponse = client().admin().cluster().nodesStats(new NodesStatsRequest()).get(); + private Set getNodeRoles(Client client, int nodeNumber) throws ExecutionException, InterruptedException { + NodesStatsResponse nodesStatsResponse = client.admin().cluster().nodesStats(new NodesStatsRequest()).get(); return nodesStatsResponse.getNodes() .get(nodeNumber) .getNode()