Skip to content

Commit

Permalink
Fix flakiness for getNodeRoles based tests (opensearch-project#7395) (o…
Browse files Browse the repository at this point in the history
…pensearch-project#7506)

(cherry picked from commit b65047f)

Signed-off-by: Kunal Kotwani <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent bac7ef8 commit 3545959
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,11 +153,12 @@ public void testNodeCountsWithDeprecatedMasterRole() throws ExecutionException,

Map<String, Integer> 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<String> expectedRoles = Set.of(DiscoveryNodeRole.MASTER_ROLE.roleName());
assertEquals(expectedRoles, getNodeRoles(0));
assertEquals(expectedRoles, getNodeRoles(client, 0));
}

private static void incrementCountForRole(String role, Map<String, Integer> counts) {
Expand Down Expand Up @@ -327,14 +329,15 @@ public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, I

Map<String, Integer> 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<String> 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 {
Expand All @@ -356,14 +359,15 @@ public void testNodeRolesWithClusterManagerRole() throws ExecutionException, Int

Map<String, Integer> 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<String> 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 {
Expand All @@ -379,15 +383,16 @@ public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionExcept

Map<String, Integer> 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<String> expectedRoles = Set.of(
DiscoveryNodeRole.MASTER_ROLE.roleName(),
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 {
Expand All @@ -405,14 +410,15 @@ public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException,

Map<String, Integer> 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<Set<String>> 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<String, Integer> getExpectedCounts(
Expand All @@ -435,8 +441,8 @@ private Map<String, Integer> getExpectedCounts(
return expectedCounts;
}

private Set<String> getNodeRoles(int nodeNumber) throws ExecutionException, InterruptedException {
NodesStatsResponse nodesStatsResponse = client().admin().cluster().nodesStats(new NodesStatsRequest()).get();
private Set<String> getNodeRoles(Client client, int nodeNumber) throws ExecutionException, InterruptedException {
NodesStatsResponse nodesStatsResponse = client.admin().cluster().nodesStats(new NodesStatsRequest()).get();
return nodesStatsResponse.getNodes()
.get(nodeNumber)
.getNode()
Expand Down

0 comments on commit 3545959

Please sign in to comment.