Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakiness for getNodeRoles based tests #7395

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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