Skip to content

Commit 5c7a226

Browse files
committed
Migrate some tests that use nodeDescriptions to using nodeNames
1 parent b0d0a97 commit 5c7a226

File tree

7 files changed

+45
-58
lines changed

7 files changed

+45
-58
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@ public class AddVotingConfigExclusionsRequest extends MasterNodeRequest<AddVotin
5454
private final TimeValue timeout;
5555

5656
/**
57-
* Construct a request to add voting config exclusions for master-eligible nodes matching the given descriptions, and wait for a
57+
* Construct a request to add voting config exclusions for master-eligible nodes matching the given node names, and wait for a
5858
* default 30 seconds for these exclusions to take effect, removing the nodes from the voting configuration.
59-
* @param nodeDescriptions Descriptions of the nodes to add - see {@link DiscoveryNodes#resolveNodes(String...)}
59+
* @param nodeNames Names of the nodes to add - see {@link AddVotingConfigExclusionsRequest#resolveVotingConfigExclusions(ClusterState)}
6060
*/
61-
public AddVotingConfigExclusionsRequest(String[] nodeDescriptions) {
62-
this(nodeDescriptions, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY, TimeValue.timeValueSeconds(30));
61+
public AddVotingConfigExclusionsRequest(String... nodeNames) {
62+
this(Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY, nodeNames, TimeValue.timeValueSeconds(30));
6363
}
6464

6565
/**
6666
* Construct a request to add voting config exclusions for master-eligible nodes matching the given descriptions, and wait for these
6767
* nodes to be removed from the voting configuration.
6868
* @param nodeDescriptions Descriptions of the nodes whose exclusions to add - see {@link DiscoveryNodes#resolveNodes(String...)}.
69+
* @param nodeIds Ids of the nodes whose exclusions to add - see {@link AddVotingConfigExclusionsRequest#resolveVotingConfigExclusions(ClusterState)
70+
* @param nodeNames Names of the nodes whose exclusions to add - see {@link AddVotingConfigExclusionsRequest#resolveVotingConfigExclusions(ClusterState)
6971
* @param timeout How long to wait for the added exclusions to take effect and be removed from the voting configuration.
7072
*/
7173
public AddVotingConfigExclusionsRequest(String[] nodeDescriptions, String[] nodeIds, String[] nodeNames, TimeValue timeout) {

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ public void testSerializationForNodeIdOrNodeName() throws IOException {
6868
assertThat(deserialized.getNodeNames(), equalTo(originalRequest.getNodeNames()));
6969
assertThat(deserialized.getTimeout(), equalTo(originalRequest.getTimeout()));
7070

71-
originalRequest = new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY,
72-
Strings.EMPTY_ARRAY, new String[]{"nodeName1", "nodeName2"}, TimeValue.ZERO);
73-
deserialized = copyWriteable(originalRequest, writableRegistry(),
74-
AddVotingConfigExclusionsRequest::new);
71+
originalRequest = new AddVotingConfigExclusionsRequest("nodeName1", "nodeName2");
72+
deserialized = copyWriteable(originalRequest, writableRegistry(), AddVotingConfigExclusionsRequest::new);
7573

7674
assertThat(deserialized.getNodeDescriptions(), equalTo(originalRequest.getNodeDescriptions()));
7775
assertThat(deserialized.getNodeIds(), equalTo(originalRequest.getNodeIds()));
@@ -110,15 +108,15 @@ public void testResolve() {
110108
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")).nodes(new Builder()
111109
.add(localNode).add(otherNode1).add(otherNode2).add(otherDataNode).localNodeId(localNode.getId())).build();
112110

113-
assertThat(makeRequest("_all").resolveVotingConfigExclusions(clusterState),
111+
assertThat(makeRequestWithNodeDescriptions("_all").resolveVotingConfigExclusions(clusterState),
114112
containsInAnyOrder(localNodeExclusion, otherNode1Exclusion, otherNode2Exclusion));
115-
assertThat(makeRequest("_local").resolveVotingConfigExclusions(clusterState),
113+
assertThat(makeRequestWithNodeDescriptions("_local").resolveVotingConfigExclusions(clusterState),
116114
contains(localNodeExclusion));
117-
assertThat(makeRequest("other*").resolveVotingConfigExclusions(clusterState),
115+
assertThat(makeRequestWithNodeDescriptions("other*").resolveVotingConfigExclusions(clusterState),
118116
containsInAnyOrder(otherNode1Exclusion, otherNode2Exclusion));
119117

120118
assertThat(expectThrows(IllegalArgumentException.class,
121-
() -> makeRequest("not-a-node").resolveVotingConfigExclusions(clusterState)).getMessage(),
119+
() -> makeRequestWithNodeDescriptions("not-a-node").resolveVotingConfigExclusions(clusterState)).getMessage(),
122120
equalTo("add voting config exclusions request for [not-a-node] matched no master-eligible nodes"));
123121
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
124122
}
@@ -230,14 +228,10 @@ public void testResolveByNodeNames() {
230228
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster"))
231229
.nodes(new Builder().add(node1).add(node2).add(node3).localNodeId(node1.getId())).build();
232230

233-
assertThat(new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY,
234-
new String[]{"nodeName1", "nodeName2"}, TimeValue.ZERO)
235-
.resolveVotingConfigExclusions(clusterState),
231+
assertThat(new AddVotingConfigExclusionsRequest("nodeName1", "nodeName2").resolveVotingConfigExclusions(clusterState),
236232
containsInAnyOrder(node1Exclusion, node2Exclusion));
237233

238-
assertThat(new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY,
239-
new String[]{"nodeName1", "unresolvableNodeName"}, TimeValue.ZERO)
240-
.resolveVotingConfigExclusions(clusterState),
234+
assertThat(new AddVotingConfigExclusionsRequest("nodeName1", "unresolvableNodeName").resolveVotingConfigExclusions(clusterState),
241235
containsInAnyOrder(node1Exclusion, unresolvableVotingConfigExclusion));
242236
}
243237

@@ -316,16 +310,17 @@ public void testResolveAndCheckMaximum() {
316310
.coordinationMetaData(CoordinationMetaData.builder().addVotingConfigExclusion(otherNode1Exclusion).build()));
317311
final ClusterState clusterState = builder.build();
318312

319-
assertThat(makeRequest("_local").resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 2, "setting.name"),
313+
assertThat(makeRequestWithNodeDescriptions("_local").resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 2, "setting.name"),
320314
contains(localNodeExclusion));
321315
assertThat(expectThrows(IllegalArgumentException.class,
322-
() -> makeRequest("_local").resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 1, "setting.name")).getMessage(),
316+
() -> makeRequestWithNodeDescriptions("_local").resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 1, "setting.name")).getMessage(),
323317
equalTo("add voting config exclusions request for [_local] would add [1] exclusions to the existing [1] which would " +
324318
"exceed the maximum of [1] set by [setting.name]"));
325319
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
326320
}
327321

328-
private static AddVotingConfigExclusionsRequest makeRequest(String... descriptions) {
329-
return new AddVotingConfigExclusionsRequest(descriptions);
322+
private static AddVotingConfigExclusionsRequest makeRequestWithNodeDescriptions(String... nodeDescriptions) {
323+
return new AddVotingConfigExclusionsRequest(nodeDescriptions, Strings.EMPTY_ARRAY,
324+
Strings.EMPTY_ARRAY, TimeValue.timeValueSeconds(30));
330325
}
331326
}

server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ public void testWithdrawsVoteFromANode() throws InterruptedException {
152152
final CountDownLatch countDownLatch = new CountDownLatch(1);
153153

154154
clusterStateObserver.waitForNextChange(new AdjustConfigurationForExclusions());
155-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
156-
new AddVotingConfigExclusionsRequest(new String[]{"other1"}),
155+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest("other1"),
157156
expectSuccess(r -> {
158157
assertNotNull(r);
159158
countDownLatch.countDown();
@@ -162,15 +161,14 @@ public void testWithdrawsVoteFromANode() throws InterruptedException {
162161

163162
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
164163
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
165-
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
166164
}
167165

168166
public void testWithdrawsVotesFromMultipleNodes() throws InterruptedException {
169167
final CountDownLatch countDownLatch = new CountDownLatch(1);
170168

171169
clusterStateObserver.waitForNextChange(new AdjustConfigurationForExclusions());
172170
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
173-
new AddVotingConfigExclusionsRequest(new String[]{"other1", "other2"}),
171+
new AddVotingConfigExclusionsRequest("other1", "other2"),
174172
expectSuccess(r -> {
175173
assertNotNull(r);
176174
countDownLatch.countDown();
@@ -180,15 +178,13 @@ public void testWithdrawsVotesFromMultipleNodes() throws InterruptedException {
180178
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
181179
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(),
182180
containsInAnyOrder(otherNode1Exclusion, otherNode2Exclusion));
183-
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
184181
}
185182

186183
public void testWithdrawsVotesFromNodesMatchingWildcard() throws InterruptedException {
187184
final CountDownLatch countDownLatch = new CountDownLatch(1);
188185

189186
clusterStateObserver.waitForNextChange(new AdjustConfigurationForExclusions());
190-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
191-
new AddVotingConfigExclusionsRequest(new String[]{"other*"}),
187+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, makeRequestWithNodeDescriptions("other*"),
192188
expectSuccess(r -> {
193189
assertNotNull(r);
194190
countDownLatch.countDown();
@@ -205,8 +201,7 @@ public void testWithdrawsVotesFromAllMasterEligibleNodes() throws InterruptedExc
205201
final CountDownLatch countDownLatch = new CountDownLatch(1);
206202

207203
clusterStateObserver.waitForNextChange(new AdjustConfigurationForExclusions());
208-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
209-
new AddVotingConfigExclusionsRequest(new String[]{"_all"}),
204+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, makeRequestWithNodeDescriptions("_all"),
210205
expectSuccess(r -> {
211206
assertNotNull(r);
212207
countDownLatch.countDown();
@@ -223,8 +218,7 @@ public void testWithdrawsVoteFromLocalNode() throws InterruptedException {
223218
final CountDownLatch countDownLatch = new CountDownLatch(1);
224219

225220
clusterStateObserver.waitForNextChange(new AdjustConfigurationForExclusions());
226-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
227-
new AddVotingConfigExclusionsRequest(new String[]{"_local"}),
221+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, makeRequestWithNodeDescriptions("_local"),
228222
expectSuccess(r -> {
229223
assertNotNull(r);
230224
countDownLatch.countDown();
@@ -236,6 +230,7 @@ public void testWithdrawsVoteFromLocalNode() throws InterruptedException {
236230
contains(localNodeExclusion));
237231
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
238232
}
233+
239234
public void testReturnsImmediatelyIfVoteAlreadyWithdrawn() throws InterruptedException {
240235
final ClusterState state = clusterService.state();
241236
setState(clusterService, builder(state)
@@ -248,8 +243,7 @@ public void testReturnsImmediatelyIfVoteAlreadyWithdrawn() throws InterruptedExc
248243
final CountDownLatch countDownLatch = new CountDownLatch(1);
249244

250245
// no observer to reconfigure
251-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
252-
new AddVotingConfigExclusionsRequest(new String[]{"other1"}, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY, TimeValue.ZERO),
246+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest("other1"),
253247
expectSuccess(r -> {
254248
assertNotNull(r);
255249
countDownLatch.countDown();
@@ -259,15 +253,13 @@ public void testReturnsImmediatelyIfVoteAlreadyWithdrawn() throws InterruptedExc
259253
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
260254
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(),
261255
contains(otherNode1Exclusion));
262-
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
263256
}
264257

265-
public void testReturnsErrorIfNoMatchingNodes() throws InterruptedException {
258+
public void testReturnsErrorIfNoMatchingNodeDescriptions() throws InterruptedException {
266259
final CountDownLatch countDownLatch = new CountDownLatch(1);
267260
final SetOnce<TransportException> exceptionHolder = new SetOnce<>();
268261

269-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
270-
new AddVotingConfigExclusionsRequest(new String[]{"not-a-node"}),
262+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, makeRequestWithNodeDescriptions("not-a-node"),
271263
expectError(e -> {
272264
exceptionHolder.set(e);
273265
countDownLatch.countDown();
@@ -287,7 +279,7 @@ public void testOnlyMatchesMasterEligibleNodes() throws InterruptedException {
287279
final SetOnce<TransportException> exceptionHolder = new SetOnce<>();
288280

289281
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
290-
new AddVotingConfigExclusionsRequest(new String[]{"_all", "master:false"}),
282+
makeRequestWithNodeDescriptions("_all", "master:false"),
291283
expectError(e -> {
292284
exceptionHolder.set(e);
293285
countDownLatch.countDown();
@@ -341,9 +333,7 @@ public void testExcludeAbsentNodesByNodeNames() throws InterruptedException {
341333
final CountDownLatch countDownLatch = new CountDownLatch(1);
342334

343335
clusterStateObserver.waitForNextChange(new AdjustConfigurationForExclusions());
344-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
345-
new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY,
346-
new String[]{"absent_node"}, TimeValue.timeValueSeconds(30)),
336+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest("absent_node"),
347337
expectSuccess(e -> {
348338
countDownLatch.countDown();
349339
})
@@ -359,8 +349,7 @@ public void testExcludeExistingNodesByNodeNames() throws InterruptedException {
359349

360350
clusterStateObserver.waitForNextChange(new AdjustConfigurationForExclusions());
361351
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
362-
new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY,
363-
new String[]{"other1", "other2"}, TimeValue.timeValueSeconds(30)),
352+
new AddVotingConfigExclusionsRequest("other1", "other2"),
364353
expectSuccess(r -> {
365354
assertNotNull(r);
366355
countDownLatch.countDown();
@@ -384,8 +373,7 @@ public void testSucceedsEvenIfAllExclusionsAlreadyAdded() throws InterruptedExce
384373

385374
final CountDownLatch countDownLatch = new CountDownLatch(1);
386375

387-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
388-
new AddVotingConfigExclusionsRequest(new String[]{"other1"}),
376+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest("other1"),
389377
expectSuccess(r -> {
390378
assertNotNull(r);
391379
countDownLatch.countDown();
@@ -395,7 +383,6 @@ public void testSucceedsEvenIfAllExclusionsAlreadyAdded() throws InterruptedExce
395383
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
396384
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(),
397385
contains(otherNode1Exclusion));
398-
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
399386
}
400387

401388
public void testExcludeByNodeIdSucceedsEvenIfAllExclusionsAlreadyAdded() throws InterruptedException {
@@ -436,9 +423,7 @@ public void testExcludeByNodeNameSucceedsEvenIfAllExclusionsAlreadyAdded() throw
436423

437424
final CountDownLatch countDownLatch = new CountDownLatch(1);
438425

439-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
440-
new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY,
441-
new String[]{"other1"}, TimeValue.timeValueSeconds(30)),
426+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest("other1"),
442427
expectSuccess(r -> {
443428
assertNotNull(r);
444429
countDownLatch.countDown();
@@ -488,8 +473,7 @@ public void testReturnsErrorIfMaximumExclusionCountExceeded() throws Interrupted
488473
final CountDownLatch countDownLatch = new CountDownLatch(1);
489474
final SetOnce<TransportException> exceptionHolder = new SetOnce<>();
490475

491-
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
492-
new AddVotingConfigExclusionsRequest(new String[]{"other*"}),
476+
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, makeRequestWithNodeDescriptions("other*"),
493477
expectError(e -> {
494478
exceptionHolder.set(e);
495479
countDownLatch.countDown();
@@ -601,4 +585,10 @@ public void onTimeout(TimeValue timeout) {
601585
throw new AssertionError("unexpected timeout");
602586
}
603587
}
588+
589+
private AddVotingConfigExclusionsRequest makeRequestWithNodeDescriptions(String... nodeDescriptions) {
590+
return new AddVotingConfigExclusionsRequest(nodeDescriptions, Strings.EMPTY_ARRAY,
591+
Strings.EMPTY_ARRAY, TimeValue.timeValueSeconds(30));
592+
}
593+
604594
}

0 commit comments

Comments
 (0)