From 9026aedc2c9d05e875f1eaea0601fc87483ed638 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 16 Feb 2022 20:00:28 -0800 Subject: [PATCH] Replace master in server test classes Signed-off-by: Tianli Feng --- ...ansportClusterStateActionDisruptionIT.java | 8 +- .../cluster/MinimumMasterNodesIT.java | 6 +- .../discovery/ClusterDisruptionIT.java | 20 ++--- .../discovery/DiscoveryDisruptionIT.java | 28 +++---- .../discovery/MasterDisruptionIT.java | 29 ++++--- .../store/IndicesStoreIntegrationIT.java | 18 ++--- .../ClusterFormationFailureHelperTests.java | 16 ++-- .../cluster/node/DiscoveryNodesTests.java | 4 +- ...shakingTransportAddressConnectorTests.java | 2 +- .../opensearch/discovery/PeerFinderTests.java | 6 +- .../opensearch/env/NodeEnvironmentTests.java | 4 +- .../env/NodeRepurposeCommandTests.java | 75 ++++++++++--------- .../transport/RemoteClusterServiceTests.java | 6 +- 13 files changed, 120 insertions(+), 102 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/state/TransportClusterStateActionDisruptionIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/state/TransportClusterStateActionDisruptionIT.java index c6f47a01ed2d2..f49a0c9a722a6 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/state/TransportClusterStateActionDisruptionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/state/TransportClusterStateActionDisruptionIT.java @@ -204,9 +204,9 @@ public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception String value = "none"; while (shutdown.get() == false) { value = "none".equals(value) ? "all" : "none"; - final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames())); + final String nonClusterManagerNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames())); assertAcked( - client(nonMasterNode).admin() + client(nonClusterManagerNode).admin() .cluster() .prepareUpdateSettings() .setPersistentSettings(Settings.builder().put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), value)) @@ -235,8 +235,8 @@ public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception } assertBusy(() -> { - final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames())); - final String claimedMasterName = internalCluster().getMasterName(nonMasterNode); + final String nonClusterManagerNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames())); + final String claimedMasterName = internalCluster().getMasterName(nonClusterManagerNode); assertThat(claimedMasterName, not(equalTo(masterName))); }); diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/MinimumMasterNodesIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/MinimumMasterNodesIT.java index d6c5d7a950d1f..04bbaeef1b57b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/MinimumMasterNodesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/MinimumMasterNodesIT.java @@ -309,11 +309,11 @@ public void testThreeNodesNoMasterBlock() throws Exception { assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100); } - List nonMasterNodes = new ArrayList<>( + List nonClusterManagerNodes = new ArrayList<>( Sets.difference(Sets.newHashSet(internalCluster().getNodeNames()), Collections.singleton(internalCluster().getMasterName())) ); - Settings nonMasterDataPathSettings1 = internalCluster().dataPathSettings(nonMasterNodes.get(0)); - Settings nonMasterDataPathSettings2 = internalCluster().dataPathSettings(nonMasterNodes.get(1)); + Settings nonMasterDataPathSettings1 = internalCluster().dataPathSettings(nonClusterManagerNodes.get(0)); + Settings nonMasterDataPathSettings2 = internalCluster().dataPathSettings(nonClusterManagerNodes.get(1)); internalCluster().stopRandomNonMasterNode(); internalCluster().stopRandomNonMasterNode(); diff --git a/server/src/internalClusterTest/java/org/opensearch/discovery/ClusterDisruptionIT.java b/server/src/internalClusterTest/java/org/opensearch/discovery/ClusterDisruptionIT.java index 2294d7e354d2d..29dfde4e4c933 100644 --- a/server/src/internalClusterTest/java/org/opensearch/discovery/ClusterDisruptionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/discovery/ClusterDisruptionIT.java @@ -340,26 +340,26 @@ public void testRejoinDocumentExistsInAllShardCopies() throws Exception { // simulate handling of sending shard failure during an isolation public void testSendingShardFailure() throws Exception { List nodes = startCluster(3); - String masterNode = internalCluster().getMasterName(); - List nonMasterNodes = nodes.stream().filter(node -> !node.equals(masterNode)).collect(Collectors.toList()); - String nonMasterNode = randomFrom(nonMasterNodes); + String clusterManagerNode = internalCluster().getMasterName(); + List nonClusterManagerNodes = nodes.stream().filter(node -> !node.equals(clusterManagerNode)).collect(Collectors.toList()); + String nonClusterManagerNode = randomFrom(nonClusterManagerNodes); assertAcked( prepareCreate("test").setSettings( Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) ) ); ensureGreen(); - String nonMasterNodeId = internalCluster().clusterService(nonMasterNode).localNode().getId(); + String nonClusterManagerNodeId = internalCluster().clusterService(nonClusterManagerNode).localNode().getId(); // fail a random shard ShardRouting failedShard = randomFrom( - clusterService().state().getRoutingNodes().node(nonMasterNodeId).shardsWithState(ShardRoutingState.STARTED) + clusterService().state().getRoutingNodes().node(nonClusterManagerNodeId).shardsWithState(ShardRoutingState.STARTED) ); - ShardStateAction service = internalCluster().getInstance(ShardStateAction.class, nonMasterNode); + ShardStateAction service = internalCluster().getInstance(ShardStateAction.class, nonClusterManagerNode); CountDownLatch latch = new CountDownLatch(1); AtomicBoolean success = new AtomicBoolean(); - String isolatedNode = randomBoolean() ? masterNode : nonMasterNode; + String isolatedNode = randomBoolean() ? clusterManagerNode : nonClusterManagerNode; TwoPartitions partitions = isolateNode(isolatedNode); // we cannot use the NetworkUnresponsive disruption type here as it will swallow the "shard failed" request, calling neither // onSuccess nor onFailure on the provided listener. @@ -387,10 +387,10 @@ public void onFailure(Exception e) { } ); - if (isolatedNode.equals(nonMasterNode)) { - assertNoMaster(nonMasterNode); + if (isolatedNode.equals(nonClusterManagerNode)) { + assertNoMaster(nonClusterManagerNode); } else { - ensureStableCluster(2, nonMasterNode); + ensureStableCluster(2, nonClusterManagerNode); } // heal the partition diff --git a/server/src/internalClusterTest/java/org/opensearch/discovery/DiscoveryDisruptionIT.java b/server/src/internalClusterTest/java/org/opensearch/discovery/DiscoveryDisruptionIT.java index ea29489da9165..8ae128f19a945 100644 --- a/server/src/internalClusterTest/java/org/opensearch/discovery/DiscoveryDisruptionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/discovery/DiscoveryDisruptionIT.java @@ -201,31 +201,31 @@ public void testElectMasterWithLatestVersion() throws Exception { public void testNodeNotReachableFromMaster() throws Exception { startCluster(3); - String masterNode = internalCluster().getMasterName(); - String nonMasterNode = null; - while (nonMasterNode == null) { - nonMasterNode = randomFrom(internalCluster().getNodeNames()); - if (nonMasterNode.equals(masterNode)) { - nonMasterNode = null; + String clusterManagerNode = internalCluster().getMasterName(); + String nonClusterManagerNode = null; + while (nonClusterManagerNode == null) { + nonClusterManagerNode = randomFrom(internalCluster().getNodeNames()); + if (nonClusterManagerNode.equals(clusterManagerNode)) { + nonClusterManagerNode = null; } } - logger.info("blocking request from master [{}] to [{}]", masterNode, nonMasterNode); + logger.info("blocking request from master [{}] to [{}]", clusterManagerNode, nonClusterManagerNode); MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance( TransportService.class, - masterNode + clusterManagerNode ); if (randomBoolean()) { - masterTransportService.addUnresponsiveRule(internalCluster().getInstance(TransportService.class, nonMasterNode)); + masterTransportService.addUnresponsiveRule(internalCluster().getInstance(TransportService.class, nonClusterManagerNode)); } else { - masterTransportService.addFailToSendNoConnectRule(internalCluster().getInstance(TransportService.class, nonMasterNode)); + masterTransportService.addFailToSendNoConnectRule(internalCluster().getInstance(TransportService.class, nonClusterManagerNode)); } - logger.info("waiting for [{}] to be removed from cluster", nonMasterNode); - ensureStableCluster(2, masterNode); + logger.info("waiting for [{}] to be removed from cluster", nonClusterManagerNode); + ensureStableCluster(2, clusterManagerNode); - logger.info("waiting for [{}] to have no master", nonMasterNode); - assertNoMaster(nonMasterNode); + logger.info("waiting for [{}] to have no master", nonClusterManagerNode); + assertNoMaster(nonClusterManagerNode); logger.info("healing partition and checking cluster reforms"); masterTransportService.clearAllRules(); diff --git a/server/src/internalClusterTest/java/org/opensearch/discovery/MasterDisruptionIT.java b/server/src/internalClusterTest/java/org/opensearch/discovery/MasterDisruptionIT.java index 06fc638b299aa..30b3877cc661b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/discovery/MasterDisruptionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/discovery/MasterDisruptionIT.java @@ -71,33 +71,40 @@ public class MasterDisruptionIT extends AbstractDisruptionTestCase { public void testMasterNodeGCs() throws Exception { List nodes = startCluster(3); - String oldMasterNode = internalCluster().getMasterName(); + String oldClusterManagerNode = internalCluster().getMasterName(); // a very long GC, but it's OK as we remove the disruption when it has had an effect - SingleNodeDisruption masterNodeDisruption = new IntermittentLongGCDisruption(random(), oldMasterNode, 100, 200, 30000, 60000); + SingleNodeDisruption masterNodeDisruption = new IntermittentLongGCDisruption( + random(), + oldClusterManagerNode, + 100, + 200, + 30000, + 60000 + ); internalCluster().setDisruptionScheme(masterNodeDisruption); masterNodeDisruption.startDisrupting(); - Set oldNonMasterNodesSet = new HashSet<>(nodes); - oldNonMasterNodesSet.remove(oldMasterNode); + Set oldNonClusterManagerNodesSet = new HashSet<>(nodes); + oldNonClusterManagerNodesSet.remove(oldClusterManagerNode); - List oldNonMasterNodes = new ArrayList<>(oldNonMasterNodesSet); + List oldNonClusterManagerNodes = new ArrayList<>(oldNonClusterManagerNodesSet); - logger.info("waiting for nodes to de-elect master [{}]", oldMasterNode); - for (String node : oldNonMasterNodesSet) { - assertDifferentMaster(node, oldMasterNode); + logger.info("waiting for nodes to de-elect master [{}]", oldClusterManagerNode); + for (String node : oldNonClusterManagerNodesSet) { + assertDifferentMaster(node, oldClusterManagerNode); } logger.info("waiting for nodes to elect a new master"); - ensureStableCluster(2, oldNonMasterNodes.get(0)); + ensureStableCluster(2, oldNonClusterManagerNodes.get(0)); // restore GC masterNodeDisruption.stopDisrupting(); final TimeValue waitTime = new TimeValue(DISRUPTION_HEALING_OVERHEAD.millis() + masterNodeDisruption.expectedTimeToHeal().millis()); - ensureStableCluster(3, waitTime, false, oldNonMasterNodes.get(0)); + ensureStableCluster(3, waitTime, false, oldNonClusterManagerNodes.get(0)); // make sure all nodes agree on master String newMaster = internalCluster().getMasterName(); - assertThat(newMaster, not(equalTo(oldMasterNode))); + assertThat(newMaster, not(equalTo(oldClusterManagerNode))); assertMaster(newMaster, nodes); } diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/store/IndicesStoreIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/store/IndicesStoreIntegrationIT.java index b85afa80496d0..6ed9fab91a67d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/store/IndicesStoreIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/store/IndicesStoreIntegrationIT.java @@ -459,11 +459,11 @@ public void testShardActiveElsewhereDoesNotDeleteAnother() throws Exception { public void testShardActiveElseWhere() throws Exception { List nodes = internalCluster().startNodes(2); - final String masterNode = internalCluster().getMasterName(); - final String nonMasterNode = nodes.get(0).equals(masterNode) ? nodes.get(1) : nodes.get(0); + final String clusterManagerNode = internalCluster().getMasterName(); + final String nonClusterManagerNode = nodes.get(0).equals(clusterManagerNode) ? nodes.get(1) : nodes.get(0); - final String masterId = internalCluster().clusterService(masterNode).localNode().getId(); - final String nonMasterId = internalCluster().clusterService(nonMasterNode).localNode().getId(); + final String clusterManagerId = internalCluster().clusterService(clusterManagerNode).localNode().getId(); + final String nonClusterManagerId = internalCluster().clusterService(nonClusterManagerNode).localNode().getId(); final int numShards = scaledRandomIntBetween(2, 10); assertAcked( @@ -476,14 +476,14 @@ public void testShardActiveElseWhere() throws Exception { waitNoPendingTasksOnAll(); ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get(); final Index index = stateResponse.getState().metadata().index("test").getIndex(); - RoutingNode routingNode = stateResponse.getState().getRoutingNodes().node(nonMasterId); + RoutingNode routingNode = stateResponse.getState().getRoutingNodes().node(nonClusterManagerId); final int[] node2Shards = new int[routingNode.numberOfOwningShards()]; int i = 0; for (ShardRouting shardRouting : routingNode) { node2Shards[i] = shardRouting.shardId().id(); i++; } - logger.info("Node [{}] has shards: {}", nonMasterNode, Arrays.toString(node2Shards)); + logger.info("Node [{}] has shards: {}", nonClusterManagerNode, Arrays.toString(node2Shards)); // disable relocations when we do this, to make sure the shards are not relocated from node2 // due to rebalancing, and delete its content @@ -496,14 +496,14 @@ public void testShardActiveElseWhere() throws Exception { ) .get(); - ClusterApplierService clusterApplierService = internalCluster().getInstance(ClusterService.class, nonMasterNode) + ClusterApplierService clusterApplierService = internalCluster().getInstance(ClusterService.class, nonClusterManagerNode) .getClusterApplierService(); ClusterState currentState = clusterApplierService.state(); IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(index); for (int j = 0; j < numShards; j++) { indexRoutingTableBuilder.addIndexShard( new IndexShardRoutingTable.Builder(new ShardId(index, j)).addShard( - TestShardRouting.newShardRouting("test", j, masterId, true, ShardRoutingState.STARTED) + TestShardRouting.newShardRouting("test", j, clusterManagerId, true, ShardRoutingState.STARTED) ).build() ); } @@ -528,7 +528,7 @@ public void onFailure(String source, Exception e) { waitNoPendingTasksOnAll(); logger.info("Checking if shards aren't removed"); for (int shard : node2Shards) { - assertShardExists(nonMasterNode, index, shard); + assertShardExists(nonClusterManagerNode, index, shard); } } diff --git a/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java b/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java index aa9c99ee8a0ff..2058f2d180711 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java @@ -818,8 +818,8 @@ public void testDescriptionAfterBootstrapping() { ) ); - final DiscoveryNode otherMasterNode = new DiscoveryNode("other-master", buildNewFakeTransportAddress(), Version.CURRENT); - final DiscoveryNode otherNonMasterNode = new DiscoveryNode( + final DiscoveryNode otherClusterManagerNode = new DiscoveryNode("other-master", buildNewFakeTransportAddress(), Version.CURRENT); + final DiscoveryNode otherNonClusterManagerNode = new DiscoveryNode( "other-non-master", buildNewFakeTransportAddress(), emptyMap(), @@ -833,7 +833,13 @@ public void testDescriptionAfterBootstrapping() { String[] configNodeIds = new String[] { "n1", "n2" }; final ClusterState stateWithOtherNodes = ClusterState.builder(ClusterName.DEFAULT) - .nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId()).add(otherMasterNode).add(otherNonMasterNode)) + .nodes( + DiscoveryNodes.builder() + .add(localNode) + .localNodeId(localNode.getId()) + .add(otherClusterManagerNode) + .add(otherNonClusterManagerNode) + ) .metadata( Metadata.builder() .coordinationMetadata( @@ -864,13 +870,13 @@ public void testDescriptionAfterBootstrapping() { + "discovery will continue using [] from hosts providers and [" + localNode + ", " - + otherMasterNode + + otherClusterManagerNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0", "master not discovered or elected yet, an election requires two nodes with ids [n1, n2], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" - + otherMasterNode + + otherClusterManagerNode + ", " + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0" diff --git a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java index b1732e1248a07..b9904eec98cc6 100644 --- a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java @@ -108,12 +108,12 @@ public void testAll() { assertThat(discoveryNodes.resolveNodes(new String[0]), arrayContainingInAnyOrder(allNodes)); assertThat(discoveryNodes.resolveNodes("_all"), arrayContainingInAnyOrder(allNodes)); - final String[] nonMasterNodes = StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) + final String[] nonClusterManagerNodes = StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) .map(n -> n.value) .filter(n -> n.isMasterNode() == false) .map(DiscoveryNode::getId) .toArray(String[]::new); - assertThat(discoveryNodes.resolveNodes("_all", "master:false"), arrayContainingInAnyOrder(nonMasterNodes)); + assertThat(discoveryNodes.resolveNodes("_all", "master:false"), arrayContainingInAnyOrder(nonClusterManagerNodes)); assertThat(discoveryNodes.resolveNodes("master:false", "_all"), arrayContainingInAnyOrder(allNodes)); } diff --git a/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java b/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java index 403d2e2122855..7c5b434e950cd 100644 --- a/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java +++ b/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java @@ -190,7 +190,7 @@ public void testLogsFullConnectionFailureAfterSuccessfulHandshake() throws Excep } } - public void testDoesNotConnectToNonMasterNode() throws InterruptedException { + public void testDoesNotConnectToNonClusterManagerNode() throws InterruptedException { remoteNode = new DiscoveryNode("remote-node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); discoveryAddress = getDiscoveryAddress(); remoteClusterName = "local-cluster"; diff --git a/server/src/test/java/org/opensearch/discovery/PeerFinderTests.java b/server/src/test/java/org/opensearch/discovery/PeerFinderTests.java index 3f54ae5c755f0..f5e2d091ee4fd 100644 --- a/server/src/test/java/org/opensearch/discovery/PeerFinderTests.java +++ b/server/src/test/java/org/opensearch/discovery/PeerFinderTests.java @@ -336,7 +336,7 @@ public void testDoesNotAddUnreachableNodesFromUnicastHostsList() { } public void testDoesNotAddNonMasterEligibleNodesFromUnicastHostsList() { - final DiscoveryNode nonMasterNode = new DiscoveryNode( + final DiscoveryNode nonClusterManagerNode = new DiscoveryNode( "node-from-hosts-list", buildNewFakeTransportAddress(), emptyMap(), @@ -344,8 +344,8 @@ public void testDoesNotAddNonMasterEligibleNodesFromUnicastHostsList() { Version.CURRENT ); - providedAddresses.add(nonMasterNode.getAddress()); - transportAddressConnector.addReachableNode(nonMasterNode); + providedAddresses.add(nonClusterManagerNode.getAddress()); + transportAddressConnector.addReachableNode(nonClusterManagerNode); peerFinder.activate(lastAcceptedNodes); runAllRunnableTasks(); diff --git a/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java index 011b5c8ea0e4e..d15974143d0c3 100644 --- a/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java @@ -566,10 +566,10 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException { verifyFailsOnMetadata(noDataNoMasterSettings, indexPath); // build settings using same path.data as original but without master role - Settings noMasterSettings = nonMasterNode(settings); + Settings noClusterManagerSettings = nonMasterNode(settings); // test that we can create master=false env regardless of data. - newNodeEnvironment(noMasterSettings).close(); + newNodeEnvironment(noClusterManagerSettings).close(); // test that we can create data=true, master=true env. Also remove state dir to leave only shard data for following asserts try (NodeEnvironment env = newNodeEnvironment(settings)) { diff --git a/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java b/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java index 45ec6d8ebf75a..e4f36d359de1c 100644 --- a/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java +++ b/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java @@ -75,18 +75,18 @@ public class NodeRepurposeCommandTests extends OpenSearchTestCase { private static final Index INDEX = new Index("testIndex", "testUUID"); - private Settings dataMasterSettings; + private Settings dataClusterManagerSettings; private Environment environment; private Path[] nodePaths; - private Settings dataNoMasterSettings; - private Settings noDataNoMasterSettings; - private Settings noDataMasterSettings; + private Settings dataNoClusterManagerSettings; + private Settings noDataNoClusterManagerSettings; + private Settings noDataClusterManagerSettings; @Before public void createNodePaths() throws IOException { - dataMasterSettings = buildEnvSettings(Settings.EMPTY); - environment = TestEnvironment.newEnvironment(dataMasterSettings); - try (NodeEnvironment nodeEnvironment = new NodeEnvironment(dataMasterSettings, environment)) { + dataClusterManagerSettings = buildEnvSettings(Settings.EMPTY); + environment = TestEnvironment.newEnvironment(dataClusterManagerSettings); + try (NodeEnvironment nodeEnvironment = new NodeEnvironment(dataClusterManagerSettings, environment)) { nodePaths = nodeEnvironment.nodeDataPaths(); final String nodeId = randomAlphaOfLength(10); try ( @@ -95,36 +95,36 @@ public void createNodePaths() throws IOException { nodeId, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, - new ClusterSettings(dataMasterSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), + new ClusterSettings(dataClusterManagerSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L ).createWriter() ) { writer.writeFullStateAndCommit(1L, ClusterState.EMPTY_STATE); } } - dataNoMasterSettings = nonMasterNode(dataMasterSettings); - noDataNoMasterSettings = removeRoles( - dataMasterSettings, + dataNoClusterManagerSettings = nonMasterNode(dataClusterManagerSettings); + noDataNoClusterManagerSettings = removeRoles( + dataClusterManagerSettings, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))) ); - noDataMasterSettings = masterNode(nonDataNode(dataMasterSettings)); + noDataClusterManagerSettings = masterNode(nonDataNode(dataClusterManagerSettings)); } public void testEarlyExitNoCleanup() throws Exception { - createIndexDataFiles(dataMasterSettings, randomInt(10), randomBoolean()); + createIndexDataFiles(dataClusterManagerSettings, randomInt(10), randomBoolean()); - verifyNoQuestions(dataMasterSettings, containsString(NO_CLEANUP)); - verifyNoQuestions(dataNoMasterSettings, containsString(NO_CLEANUP)); + verifyNoQuestions(dataClusterManagerSettings, containsString(NO_CLEANUP)); + verifyNoQuestions(dataNoClusterManagerSettings, containsString(NO_CLEANUP)); } public void testNothingToCleanup() throws Exception { - verifyNoQuestions(noDataNoMasterSettings, containsString(NO_DATA_TO_CLEAN_UP_FOUND)); - verifyNoQuestions(noDataMasterSettings, containsString(NO_SHARD_DATA_TO_CLEAN_UP_FOUND)); + verifyNoQuestions(noDataNoClusterManagerSettings, containsString(NO_DATA_TO_CLEAN_UP_FOUND)); + verifyNoQuestions(noDataClusterManagerSettings, containsString(NO_SHARD_DATA_TO_CLEAN_UP_FOUND)); - Environment environment = TestEnvironment.newEnvironment(noDataMasterSettings); + Environment environment = TestEnvironment.newEnvironment(noDataClusterManagerSettings); if (randomBoolean()) { - try (NodeEnvironment env = new NodeEnvironment(noDataMasterSettings, environment)) { + try (NodeEnvironment env = new NodeEnvironment(noDataClusterManagerSettings, environment)) { try ( PersistedClusterStateService.Writer writer = OpenSearchNodeCommand.createPersistedClusterStateService( Settings.EMPTY, @@ -136,19 +136,24 @@ public void testNothingToCleanup() throws Exception { } } - verifyNoQuestions(noDataNoMasterSettings, containsString(NO_DATA_TO_CLEAN_UP_FOUND)); - verifyNoQuestions(noDataMasterSettings, containsString(NO_SHARD_DATA_TO_CLEAN_UP_FOUND)); + verifyNoQuestions(noDataNoClusterManagerSettings, containsString(NO_DATA_TO_CLEAN_UP_FOUND)); + verifyNoQuestions(noDataClusterManagerSettings, containsString(NO_SHARD_DATA_TO_CLEAN_UP_FOUND)); - createIndexDataFiles(dataMasterSettings, 0, randomBoolean()); + createIndexDataFiles(dataClusterManagerSettings, 0, randomBoolean()); - verifyNoQuestions(noDataMasterSettings, containsString(NO_SHARD_DATA_TO_CLEAN_UP_FOUND)); + verifyNoQuestions(noDataClusterManagerSettings, containsString(NO_SHARD_DATA_TO_CLEAN_UP_FOUND)); } public void testLocked() throws IOException { - try (NodeEnvironment env = new NodeEnvironment(dataMasterSettings, TestEnvironment.newEnvironment(dataMasterSettings))) { + try ( + NodeEnvironment env = new NodeEnvironment( + dataClusterManagerSettings, + TestEnvironment.newEnvironment(dataClusterManagerSettings) + ) + ) { assertThat( - expectThrows(OpenSearchException.class, () -> verifyNoQuestions(noDataNoMasterSettings, null)).getMessage(), + expectThrows(OpenSearchException.class, () -> verifyNoQuestions(noDataNoClusterManagerSettings, null)).getMessage(), containsString(NodeRepurposeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG) ); } @@ -158,7 +163,7 @@ public void testCleanupAll() throws Exception { int shardCount = randomIntBetween(1, 10); boolean verbose = randomBoolean(); boolean hasClusterState = randomBoolean(); - createIndexDataFiles(dataMasterSettings, shardCount, hasClusterState); + createIndexDataFiles(dataClusterManagerSettings, shardCount, hasClusterState); String messageText = NodeRepurposeCommand.noMasterMessage(1, environment.dataFiles().length * shardCount, 0); @@ -168,22 +173,22 @@ public void testCleanupAll() throws Exception { conditionalNot(containsString("no name for uuid: testUUID"), verbose == false || hasClusterState) ); - verifyUnchangedOnAbort(noDataNoMasterSettings, outputMatcher, verbose); + verifyUnchangedOnAbort(noDataNoClusterManagerSettings, outputMatcher, verbose); // verify test setup - expectThrows(IllegalStateException.class, () -> new NodeEnvironment(noDataNoMasterSettings, environment).close()); + expectThrows(IllegalStateException.class, () -> new NodeEnvironment(noDataNoClusterManagerSettings, environment).close()); - verifySuccess(noDataNoMasterSettings, outputMatcher, verbose); + verifySuccess(noDataNoClusterManagerSettings, outputMatcher, verbose); // verify cleaned. - new NodeEnvironment(noDataNoMasterSettings, environment).close(); + new NodeEnvironment(noDataNoClusterManagerSettings, environment).close(); } public void testCleanupShardData() throws Exception { int shardCount = randomIntBetween(1, 10); boolean verbose = randomBoolean(); boolean hasClusterState = randomBoolean(); - createIndexDataFiles(dataMasterSettings, shardCount, hasClusterState); + createIndexDataFiles(dataClusterManagerSettings, shardCount, hasClusterState); Matcher matcher = allOf( containsString(NodeRepurposeCommand.shardMessage(environment.dataFiles().length * shardCount, 1)), @@ -192,15 +197,15 @@ public void testCleanupShardData() throws Exception { conditionalNot(containsString("no name for uuid: testUUID"), verbose == false || hasClusterState) ); - verifyUnchangedOnAbort(noDataMasterSettings, matcher, verbose); + verifyUnchangedOnAbort(noDataClusterManagerSettings, matcher, verbose); // verify test setup - expectThrows(IllegalStateException.class, () -> new NodeEnvironment(noDataMasterSettings, environment).close()); + expectThrows(IllegalStateException.class, () -> new NodeEnvironment(noDataClusterManagerSettings, environment).close()); - verifySuccess(noDataMasterSettings, matcher, verbose); + verifySuccess(noDataClusterManagerSettings, matcher, verbose); // verify clean. - new NodeEnvironment(noDataMasterSettings, environment).close(); + new NodeEnvironment(noDataClusterManagerSettings, environment).close(); } static void verifySuccess(Settings settings, Matcher outputMatcher, boolean verbose) throws Exception { diff --git a/server/src/test/java/org/opensearch/transport/RemoteClusterServiceTests.java b/server/src/test/java/org/opensearch/transport/RemoteClusterServiceTests.java index 75ba1fb56aa1d..eac3d2b5c693b 100644 --- a/server/src/test/java/org/opensearch/transport/RemoteClusterServiceTests.java +++ b/server/src/test/java/org/opensearch/transport/RemoteClusterServiceTests.java @@ -553,11 +553,11 @@ public void testRemoteNodeRoles() throws IOException, InterruptedException { final Settings settings = Settings.EMPTY; final List knownNodes = new CopyOnWriteArrayList<>(); final Settings data = nonMasterNode(); - final Settings dedicatedMaster = masterOnlyNode(); + final Settings dedicatedClusterManager = masterOnlyNode(); try ( - MockTransportService c1N1 = startTransport("cluster_1_node_1", knownNodes, Version.CURRENT, dedicatedMaster); + MockTransportService c1N1 = startTransport("cluster_1_node_1", knownNodes, Version.CURRENT, dedicatedClusterManager); MockTransportService c1N2 = startTransport("cluster_1_node_2", knownNodes, Version.CURRENT, data); - MockTransportService c2N1 = startTransport("cluster_2_node_1", knownNodes, Version.CURRENT, dedicatedMaster); + MockTransportService c2N1 = startTransport("cluster_2_node_1", knownNodes, Version.CURRENT, dedicatedClusterManager); MockTransportService c2N2 = startTransport("cluster_2_node_2", knownNodes, Version.CURRENT, data) ) { final DiscoveryNode c1N1Node = c1N1.getLocalDiscoNode();