Skip to content

Commit e334175

Browse files
Tianli Fenggithub-actions[bot]
Tianli Feng
authored andcommitted
[TEST] Add back necessary tests for deprecated settings that are replaced during applying inclusive naming (#2825)
Signed-off-by: Tianli Feng <ftianli@amazon.com> (cherry picked from commit 00c0bf2)
1 parent 3537b5a commit e334175

File tree

10 files changed

+519
-29
lines changed

10 files changed

+519
-29
lines changed

server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.hamcrest.Matchers;
5252

5353
import java.io.IOException;
54+
import java.util.Collections;
5455
import java.util.HashMap;
5556
import java.util.HashSet;
5657
import java.util.Map;
@@ -144,6 +145,27 @@ public void testNodeCounts() {
144145
}
145146
}
146147

148+
// Validate assigning value "master" to setting "node.roles" can get correct count in Node Stats response after MASTER_ROLE deprecated.
149+
public void testNodeCountsWithDeprecatedMasterRole() {
150+
int total = 1;
151+
Settings settings = Settings.builder()
152+
.putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), Collections.singletonList(DiscoveryNodeRole.MASTER_ROLE.roleName()))
153+
.build();
154+
internalCluster().startNode(settings);
155+
waitForNodes(total);
156+
157+
Map<String, Integer> expectedCounts = new HashMap<>();
158+
expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 0);
159+
expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1);
160+
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
161+
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 0);
162+
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 0);
163+
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
164+
165+
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
166+
assertCounts(response.getNodesStats().getCounts(), total, expectedCounts);
167+
}
168+
147169
private static void incrementCountForRole(String role, Map<String, Integer> counts) {
148170
Integer count = counts.get(role);
149171
if (count == null) {

server/src/test/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,64 @@ public void testResolveAndCheckMaximum() {
450450
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
451451
}
452452

453+
// As of 2.0, MASTER_ROLE is deprecated to promote inclusive language.
454+
// Validate node with MASTER_ROLE can be resolved by resolveVotingConfigExclusions() like before.
455+
// The following 3 tests assign nodes by description, id and name respectively.
456+
public void testResolveByNodeDescriptionWithDeprecatedMasterRole() {
457+
final DiscoveryNode localNode = new DiscoveryNode(
458+
"local",
459+
"local",
460+
buildNewFakeTransportAddress(),
461+
emptyMap(),
462+
singleton(DiscoveryNodeRole.MASTER_ROLE),
463+
Version.CURRENT
464+
);
465+
final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode);
466+
467+
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster"))
468+
.nodes(new Builder().add(localNode).localNodeId(localNode.getId()))
469+
.build();
470+
471+
assertThat(makeRequestWithNodeDescriptions("_local").resolveVotingConfigExclusions(clusterState), contains(localNodeExclusion));
472+
allowedWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
473+
}
474+
475+
public void testResolveByNodeIdWithDeprecatedMasterRole() {
476+
final DiscoveryNode node = new DiscoveryNode(
477+
"nodeName",
478+
"nodeId",
479+
buildNewFakeTransportAddress(),
480+
emptyMap(),
481+
singleton(DiscoveryNodeRole.MASTER_ROLE),
482+
Version.CURRENT
483+
);
484+
final VotingConfigExclusion nodeExclusion = new VotingConfigExclusion(node);
485+
486+
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")).nodes(new Builder().add(node)).build();
487+
488+
assertThat(
489+
new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, new String[] { "nodeId" }, Strings.EMPTY_ARRAY, TimeValue.ZERO)
490+
.resolveVotingConfigExclusions(clusterState),
491+
contains(nodeExclusion)
492+
);
493+
}
494+
495+
public void testResolveByNodeNameWithDeprecatedMasterRole() {
496+
final DiscoveryNode node = new DiscoveryNode(
497+
"nodeName",
498+
"nodeId",
499+
buildNewFakeTransportAddress(),
500+
emptyMap(),
501+
singleton(DiscoveryNodeRole.MASTER_ROLE),
502+
Version.CURRENT
503+
);
504+
final VotingConfigExclusion nodeExclusion = new VotingConfigExclusion(node);
505+
506+
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")).nodes(new Builder().add(node)).build();
507+
508+
assertThat(new AddVotingConfigExclusionsRequest("nodeName").resolveVotingConfigExclusions(clusterState), contains(nodeExclusion));
509+
}
510+
453511
private static AddVotingConfigExclusionsRequest makeRequestWithNodeDescriptions(String... nodeDescriptions) {
454512
return new AddVotingConfigExclusionsRequest(
455513
nodeDescriptions,

server/src/test/java/org/opensearch/action/support/master/TransportMasterNodeActionTests.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,40 @@ protected void masterOperation(Request request, ClusterState state, ActionListen
525525
assertTrue(listener.isDone());
526526
assertThat(listener.get(), equalTo(response));
527527
}
528+
529+
// Validate TransportMasterNodeAction.testDelegateToMaster() works correctly on node with the deprecated MASTER_ROLE.
530+
public void testDelegateToMasterOnNodeWithDeprecatedMasterRole() throws ExecutionException, InterruptedException {
531+
DiscoveryNode localNode = new DiscoveryNode(
532+
"local_node",
533+
buildNewFakeTransportAddress(),
534+
Collections.emptyMap(),
535+
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE),
536+
Version.CURRENT
537+
);
538+
DiscoveryNode remoteNode = new DiscoveryNode(
539+
"remote_node",
540+
buildNewFakeTransportAddress(),
541+
Collections.emptyMap(),
542+
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE),
543+
Version.CURRENT
544+
);
545+
DiscoveryNode[] allNodes = new DiscoveryNode[] { localNode, remoteNode };
546+
547+
Request request = new Request();
548+
setState(clusterService, ClusterStateCreationUtils.state(localNode, remoteNode, allNodes));
549+
550+
PlainActionFuture<Response> listener = new PlainActionFuture<>();
551+
new Action("internal:testAction", transportService, clusterService, threadPool).execute(request, listener);
552+
553+
assertThat(transport.capturedRequests().length, equalTo(1));
554+
CapturingTransport.CapturedRequest capturedRequest = transport.capturedRequests()[0];
555+
assertTrue(capturedRequest.node.isMasterNode());
556+
assertThat(capturedRequest.request, equalTo(request));
557+
assertThat(capturedRequest.action, equalTo("internal:testAction"));
558+
559+
Response response = new Response();
560+
transport.handleResponse(capturedRequest.requestId, response);
561+
assertTrue(listener.isDone());
562+
assertThat(listener.get(), equalTo(response));
563+
}
528564
}

server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,35 @@ public void testChangedCustomMetadataSet() {
314314
assertTrue(changedCustomMetadataTypeSet.contains(customMetadata1.getWriteableName()));
315315
}
316316

317+
// Validate the above test case testLocalNodeIsMaster() passes when the deprecated 'master' role is assigned to the local node.
318+
public void testLocalNodeIsMasterWithDeprecatedMasterRole() {
319+
final DiscoveryNodes.Builder builderLocalIsMaster = DiscoveryNodes.builder();
320+
final DiscoveryNode node0 = newNode("node_0", Set.of(DiscoveryNodeRole.MASTER_ROLE));
321+
final DiscoveryNode node1 = newNode("node_1", Set.of(DiscoveryNodeRole.DATA_ROLE));
322+
builderLocalIsMaster.add(node0).add(node1).masterNodeId(node0.getId()).localNodeId(node0.getId());
323+
324+
final DiscoveryNodes.Builder builderLocalNotMaster = DiscoveryNodes.builder();
325+
builderLocalNotMaster.add(node0).add(node1).masterNodeId(node0.getId()).localNodeId(node1.getId());
326+
327+
ClusterState previousState = createSimpleClusterState();
328+
final Metadata metadata = createMetadata(initialIndices);
329+
ClusterState newState = ClusterState.builder(TEST_CLUSTER_NAME)
330+
.nodes(builderLocalIsMaster.build())
331+
.metadata(metadata)
332+
.routingTable(createRoutingTable(1, metadata))
333+
.build();
334+
ClusterChangedEvent event = new ClusterChangedEvent("_na_", newState, previousState);
335+
assertTrue("local node should be master", event.localNodeMaster());
336+
337+
newState = ClusterState.builder(TEST_CLUSTER_NAME)
338+
.nodes(builderLocalNotMaster.build())
339+
.metadata(metadata)
340+
.routingTable(createRoutingTable(1, metadata))
341+
.build();
342+
event = new ClusterChangedEvent("_na_", newState, previousState);
343+
assertFalse("local node should not be master", event.localNodeMaster());
344+
}
345+
317346
private static class CustomMetadata2 extends TestCustomMetadata {
318347
protected CustomMetadata2(String data) {
319348
super(data);

0 commit comments

Comments
 (0)