Skip to content

Commit 584f7f2

Browse files
authored
Simplify node stopping call (#88547)
There is no need to use stopRandomNode/namePredicate combination to stop a node by its name.
1 parent bd5e16d commit 584f7f2

File tree

32 files changed

+85
-108
lines changed

32 files changed

+85
-108
lines changed

modules/transport-netty4/src/internalClusterTest/java/org/elasticsearch/rest/discovery/Zen2RestApiIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void testClearVotingTombstonesWaitingForRemoval() throws Exception {
151151
final Response response = restClient.performRequest(request);
152152
assertThat(response.getStatusLine().getStatusCode(), is(200));
153153
assertThat(response.getEntity().getContentLength(), is(0L));
154-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeToWithdraw));
154+
internalCluster().stopNode(nodeToWithdraw);
155155
Response deleteResponse = restClient.performRequest(new Request("DELETE", "/_cluster/voting_config_exclusions"));
156156
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
157157
assertThat(deleteResponse.getEntity().getContentLength(), is(0L));
@@ -167,8 +167,8 @@ public void testRemoveTwoNodesAtOnce() throws Exception {
167167
final Response response = restClient.performRequest(request);
168168
assertThat(response.getStatusLine().getStatusCode(), is(200));
169169
assertThat(response.getEntity().getContentLength(), is(0L));
170-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
171-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(2)));
170+
internalCluster().stopNode(nodes.get(0));
171+
internalCluster().stopNode(nodes.get(2));
172172
ensureStableCluster(1);
173173
}
174174
}

modules/transport-netty4/src/internalClusterTest/java/org/elasticsearch/transport/netty4/ESLoggingHandlerIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest;
1515
import org.elasticsearch.common.logging.Loggers;
1616
import org.elasticsearch.test.ESIntegTestCase;
17-
import org.elasticsearch.test.InternalTestCluster;
1817
import org.elasticsearch.test.MockLogAppender;
1918
import org.elasticsearch.test.junit.annotations.TestLogging;
2019
import org.elasticsearch.transport.TcpTransport;
@@ -110,7 +109,7 @@ public void testConnectionLogging() throws IOException {
110109
);
111110

112111
final String nodeName = internalCluster().startNode();
113-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeName));
112+
internalCluster().stopNode(nodeName);
114113

115114
appender.assertAllExpectationsMatched();
116115
}

server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainIT.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.elasticsearch.core.TimeValue;
3333
import org.elasticsearch.index.shard.ShardId;
3434
import org.elasticsearch.test.ESIntegTestCase;
35-
import org.elasticsearch.test.InternalTestCluster;
3635
import org.elasticsearch.xcontent.ToXContent;
3736
import org.elasticsearch.xcontent.XContentBuilder;
3837
import org.elasticsearch.xcontent.XContentParser;
@@ -71,7 +70,7 @@ public void testUnassignedPrimaryWithExistingIndex() throws Exception {
7170
prepareIndex(1, 0);
7271

7372
logger.info("--> stopping the node with the primary");
74-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNodeName()));
73+
internalCluster().stopNode(primaryNodeName());
7574
ensureStableCluster(1);
7675
refreshClusterInfo();
7776

@@ -150,7 +149,7 @@ public void testUnassignedReplicaDelayedAllocation() throws Exception {
150149

151150
prepareIndex(1, 1);
152151
logger.info("--> stopping the node with the replica");
153-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(replicaNode().getName()));
152+
internalCluster().stopNode(replicaNode().getName());
154153
ensureStableCluster(2);
155154
refreshClusterInfo();
156155
assertBusy(() ->
@@ -291,8 +290,8 @@ public void testUnassignedReplicaWithPriorCopy() throws Exception {
291290
logger.info("--> shutting down all nodes except the one that holds the primary");
292291
Settings node0DataPathSettings = internalCluster().dataPathSettings(nodes.get(0));
293292
Settings node1DataPathSettings = internalCluster().dataPathSettings(nodes.get(1));
294-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
295-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(1)));
293+
internalCluster().stopNode(nodes.get(0));
294+
internalCluster().stopNode(nodes.get(1));
296295
ensureStableCluster(1);
297296

298297
logger.info("--> setting allocation filtering to only allow allocation on the currently running node");
@@ -1080,7 +1079,7 @@ public void testCannotAllocateStaleReplicaExplanation() throws Exception {
10801079
assertThat(primaryNodeName(), equalTo(primaryNode));
10811080

10821081
logger.info("--> stop node with the replica shard");
1083-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(replicaNode));
1082+
internalCluster().stopNode(replicaNode);
10841083

10851084
final IndexMetadata.State indexState = randomIndexState();
10861085
if (indexState == IndexMetadata.State.OPEN) {
@@ -1102,7 +1101,7 @@ public void testCannotAllocateStaleReplicaExplanation() throws Exception {
11021101
}
11031102

11041103
logger.info("--> stop the node with the primary");
1105-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNode));
1104+
internalCluster().stopNode(primaryNode);
11061105

11071106
logger.info("--> restart the node with the stale replica");
11081107
String restartedNode = internalCluster().startDataOnlyNode(replicaDataPathSettings);

server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.elasticsearch.tasks.TaskInfo;
4343
import org.elasticsearch.tasks.TaskManager;
4444
import org.elasticsearch.test.ESIntegTestCase;
45-
import org.elasticsearch.test.InternalTestCluster;
4645
import org.elasticsearch.threadpool.ThreadPool;
4746
import org.elasticsearch.transport.SendRequestTransportException;
4847
import org.elasticsearch.transport.Transport;
@@ -294,7 +293,7 @@ public void testCancelOrphanedTasks() throws Exception {
294293
client(nodeWithRootTask).execute(TransportTestAction.ACTION, rootRequest);
295294
allowPartialRequest(rootRequest);
296295
try {
297-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeWithRootTask));
296+
internalCluster().stopNode(nodeWithRootTask);
298297
assertBusy(() -> {
299298
for (TransportService transportService : internalCluster().getInstances(TransportService.class)) {
300299
for (CancellableTask task : transportService.getTaskManager().getCancellableTasks().values()) {

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.elasticsearch.index.shard.IndexShard;
4848
import org.elasticsearch.indices.IndicesService;
4949
import org.elasticsearch.test.ESIntegTestCase;
50-
import org.elasticsearch.test.InternalTestCluster;
5150
import org.elasticsearch.test.VersionUtils;
5251
import org.elasticsearch.xcontent.XContentType;
5352

@@ -668,7 +667,7 @@ public void testShrinkThenSplitWithFailedNode() throws Exception {
668667
ensureGreen();
669668

670669
final int nodeCount = cluster().size();
671-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(shrinkNode));
670+
internalCluster().stopNode(shrinkNode);
672671
ensureStableCluster(nodeCount - 1);
673672

674673
// demonstrate that the index.routing.allocation.initial_recovery setting from the shrink doesn't carry over into the split index,

server/src/internalClusterTest/java/org/elasticsearch/action/support/replication/TransportReplicationActionRetryOnClosedNodeIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.elasticsearch.plugins.Plugin;
3030
import org.elasticsearch.plugins.PluginsService;
3131
import org.elasticsearch.test.ESIntegTestCase;
32-
import org.elasticsearch.test.InternalTestCluster;
3332
import org.elasticsearch.test.transport.MockTransportService;
3433
import org.elasticsearch.threadpool.ThreadPool;
3534
import org.elasticsearch.transport.Transport;
@@ -224,7 +223,7 @@ public void testRetryOnStoppedTransportService() throws Exception {
224223
throw new AssertionError(e);
225224
}
226225
});
227-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primary));
226+
internalCluster().stopNode(primary);
228227

229228
assertTrue(doneLatch.await(10, TimeUnit.SECONDS));
230229
if (response.get() instanceof Exception) {

server/src/internalClusterTest/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.test.ESIntegTestCase;
2828
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
2929
import org.elasticsearch.test.ESIntegTestCase.Scope;
30-
import org.elasticsearch.test.InternalTestCluster;
3130
import org.elasticsearch.test.disruption.NetworkDisruption;
3231
import org.elasticsearch.test.transport.MockTransportService;
3332

@@ -133,7 +132,7 @@ public void testTwoNodesNoMasterBlock() throws Exception {
133132
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(otherNode)).get();
134133
logger.info("--> stop master node, no master block should appear");
135134
Settings masterDataPathSettings = internalCluster().dataPathSettings(masterNode);
136-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNode));
135+
internalCluster().stopNode(masterNode);
137136

138137
assertBusy(() -> {
139138
ClusterState clusterState = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
@@ -186,7 +185,7 @@ public void testTwoNodesNoMasterBlock() throws Exception {
186185
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(masterNode)).get();
187186
logger.info("--> stop non-master node, no master block should appear");
188187
Settings otherNodeDataPathSettings = internalCluster().dataPathSettings(otherNode);
189-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(otherNode));
188+
internalCluster().stopNode(otherNode);
190189

191190
assertBusy(() -> {
192191
ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();

server/src/internalClusterTest/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.test.ESIntegTestCase;
1818
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
1919
import org.elasticsearch.test.ESIntegTestCase.Scope;
20-
import org.elasticsearch.test.InternalTestCluster;
2120

2221
import java.io.IOException;
2322

@@ -258,7 +257,7 @@ public void testElectOnlyBetweenMasterNodes() throws Exception {
258257
equalTo(nextMasterEligableNodeName)
259258
);
260259
});
261-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodeName));
260+
internalCluster().stopNode(masterNodeName);
262261
assertThat(
263262
internalCluster().nonMasterClient()
264263
.admin()

server/src/internalClusterTest/java/org/elasticsearch/cluster/allocation/ClusterRerouteIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.elasticsearch.test.ESIntegTestCase;
4646
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
4747
import org.elasticsearch.test.ESIntegTestCase.Scope;
48-
import org.elasticsearch.test.InternalTestCluster;
4948
import org.elasticsearch.test.MockLogAppender;
5049

5150
import java.nio.file.Path;
@@ -247,7 +246,7 @@ public void testDelayWithALargeAmountOfShards() throws Exception {
247246
ensureGreen(TimeValue.timeValueMinutes(1));
248247

249248
logger.info("--> stopping node1");
250-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node_1));
249+
internalCluster().stopNode(node_1);
251250

252251
// This might run slowly on older hardware
253252
ensureGreen(TimeValue.timeValueMinutes(2));

server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ public void test3MasterNodes2Failed() throws Exception {
238238
Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode);
239239

240240
logger.info("--> stop 2nd and 3d master eligible node");
241-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(1)));
242-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(2)));
241+
internalCluster().stopNode(masterNodes.get(1));
242+
internalCluster().stopNode(masterNodes.get(2));
243243

244244
logger.info("--> ensure NO_MASTER_BLOCK on data-only node");
245245
assertBusy(() -> {
@@ -262,7 +262,7 @@ public void test3MasterNodes2Failed() throws Exception {
262262

263263
logger.info("--> stop 1st master-eligible node and data-only node");
264264
NodeEnvironment nodeEnvironment = internalCluster().getAnyMasterNodeInstance(NodeEnvironment.class);
265-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(0)));
265+
internalCluster().stopNode(masterNodes.get(0));
266266
assertBusy(() -> internalCluster().getInstance(GatewayMetaState.class, dataNode).allPendingAsyncStatesWritten());
267267
internalCluster().stopRandomDataNode();
268268

@@ -351,7 +351,7 @@ public void testNoInitialBootstrapAfterDetach() throws Exception {
351351
ClusterState state = internalCluster().client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
352352
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
353353

354-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node));
354+
internalCluster().stopNode(node);
355355
}
356356

357357
public void testCanRunUnsafeBootstrapAfterErroneousDetachWithoutLoosingMetadata() throws Exception {

0 commit comments

Comments
 (0)