Skip to content

Commit

Permalink
Add tests with node.roles for cluster manager
Browse files Browse the repository at this point in the history
Signed-off-by: Sandesh Kumar <[email protected]>
  • Loading branch information
sandeshkr419 committed Mar 6, 2023
1 parent 0333f98 commit 8353014
Showing 1 changed file with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,7 @@ private void waitForNodes(int numNodes) {
public void testNodeCounts() {
int total = 1;
internalCluster().startNode();
Map<String, Integer> expectedCounts = new HashMap<>();
expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
Map<String, Integer> expectedCounts = getExpectedCounts(1, 1, 1, 1, 1, 0, 0);
int numNodes = randomIntBetween(1, 5);

ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
Expand Down Expand Up @@ -148,25 +141,21 @@ public void testNodeCounts() {
}

// Validate assigning value "master" to setting "node.roles" can get correct count in Node Stats response after MASTER_ROLE deprecated.
public void testNodeCountsWithDeprecatedMasterRole() {
public void testNodeCountsWithDeprecatedMasterRole() throws ExecutionException, InterruptedException {
int total = 1;
Settings settings = Settings.builder()
.putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), Collections.singletonList(DiscoveryNodeRole.MASTER_ROLE.roleName()))
.build();
internalCluster().startNode(settings);
waitForNodes(total);

Map<String, Integer> expectedCounts = new HashMap<>();
expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 0);
expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 0);
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 0);
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 0, 0, 0);

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));
}

private static void incrementCountForRole(String role, Map<String, Integer> counts) {
Expand Down Expand Up @@ -324,7 +313,7 @@ public void testFieldTypes() {
}
}

public void testNodeCountsWithLegacyMasterSetting() throws ExecutionException, InterruptedException {
public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, InterruptedException {
int total = 1;
Settings legacyMasterSettings = Settings.builder()
.put("node.master", true)
Expand All @@ -343,7 +332,24 @@ public void testNodeCountsWithLegacyMasterSetting() throws ExecutionException, I
assertEquals(expectedRoles, getNodeRoles(0));
}

public void testNodeCountsWithLegacySeedDataNodeSetting() throws ExecutionException, InterruptedException {
public void testNodeRolesWithClusterManagerRole() throws ExecutionException, InterruptedException {
int total = 1;
Settings legacyMasterSettings = Settings.builder()
.put("node.roles", "cluster_manager, remote_cluster_client").build();

internalCluster().startNodes(legacyMasterSettings);
waitForNodes(total);

Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 1, 0, 0);

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));
}

public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionException, InterruptedException {
int total = 1;
Settings legacyDataNodeSettings = Settings.builder()
.put("node.master", true)
Expand All @@ -363,7 +369,7 @@ public void testNodeCountsWithLegacySeedDataNodeSetting() throws ExecutionExcept
assertEquals(expectedRoles, getNodeRoles(0));
}

public void testNodeCountsWithLegacyDataNodeSetting() throws ExecutionException, InterruptedException {
public void testNodeRolesWithLegacyDataNodeSettings() throws ExecutionException, InterruptedException {
int total = 1;
Settings legacyDataNodeSettings = Settings.builder()
.put("node.master", false)
Expand Down

0 comments on commit 8353014

Please sign in to comment.