Skip to content

Commit 5d9f2cd

Browse files
committed
Clean up awaitClusterState overloads
The `logger` parameter is unused, it doesn't throw any checked exceptions, and there's no need for `protected` instance methods when they're also available as `public static`.
1 parent ee74efc commit 5d9f2cd

File tree

12 files changed

+16
-35
lines changed

12 files changed

+16
-35
lines changed

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/snapshots/RestGetSnapshotsIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void testSortAndPaginateWithInProgress() throws Exception {
204204
inProgressSnapshots.add(AbstractSnapshotIntegTestCase.startFullSnapshot(logger, repoName, snapshotName, false));
205205
}
206206
AbstractSnapshotIntegTestCase.awaitNumberOfSnapshotsInProgress(logger, inProgressCount);
207-
AbstractSnapshotIntegTestCase.awaitClusterState(logger, state -> {
207+
AbstractSnapshotIntegTestCase.awaitClusterState(state -> {
208208
final var snapshotsInProgress = SnapshotsInProgress.get(state);
209209
boolean firstIndexSuccessfullySnapshot = snapshotsInProgress.asStream()
210210
.flatMap(s -> s.shards().entrySet().stream())

server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateActionDisruptionIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception
157157

158158
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
159159
awaitClusterState(
160-
logger,
161160
nonMasterNode,
162161
state -> Optional.ofNullable(state.nodes().getMasterNode()).map(m -> m.getName().equals(masterName) == false).orElse(false)
163162
);

server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,6 @@ public void onRequestSent(
10731073
final ActionFuture<AcknowledgedResponse> deleteResponse = startDeleteSnapshot(repoName, snapshotName);
10741074

10751075
awaitClusterState(
1076-
logger,
10771076
otherDataNode,
10781077
state -> SnapshotsInProgress.get(state)
10791078
.forRepo(repoName)

test/framework/src/main/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ protected void addBwCFailedSnapshot(String repoName, String snapshotName, Map<St
560560
);
561561
}
562562

563-
protected void awaitNDeletionsInProgress(int count) throws Exception {
563+
protected void awaitNDeletionsInProgress(int count) {
564564
logger.info("--> wait for [{}] deletions to show up in the cluster state", count);
565565
awaitClusterState(state -> SnapshotDeletionsInProgress.get(state).getEntries().size() == count);
566566
}
@@ -572,7 +572,6 @@ protected void awaitNoMoreRunningOperations() throws Exception {
572572
protected void awaitNoMoreRunningOperations(String viaNode) throws Exception {
573573
logger.info("--> verify no more operations in the cluster state");
574574
awaitClusterState(
575-
logger,
576575
viaNode,
577576
state -> SnapshotsInProgress.get(state).isEmpty() && SnapshotDeletionsInProgress.get(state).hasDeletionsInProgress() == false
578577
);
@@ -607,13 +606,13 @@ public static ActionFuture<CreateSnapshotResponse> startFullSnapshot(
607606
.execute();
608607
}
609608

610-
protected void awaitNumberOfSnapshotsInProgress(int count) throws Exception {
609+
protected void awaitNumberOfSnapshotsInProgress(int count) {
611610
awaitNumberOfSnapshotsInProgress(logger, count);
612611
}
613612

614-
public static void awaitNumberOfSnapshotsInProgress(Logger logger, int count) throws Exception {
613+
public static void awaitNumberOfSnapshotsInProgress(Logger logger, int count) {
615614
logger.info("--> wait for [{}] snapshots to show up in the cluster state", count);
616-
awaitClusterState(logger, state -> SnapshotsInProgress.get(state).count() == count);
615+
awaitClusterState(state -> SnapshotsInProgress.get(state).count() == count);
617616
}
618617

619618
protected SnapshotInfo assertSuccessful(ActionFuture<CreateSnapshotResponse> future) throws Exception {

test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
package org.elasticsearch.test;
1010

11-
import org.apache.logging.log4j.Logger;
1211
import org.apache.logging.log4j.core.util.Throwables;
1312
import org.elasticsearch.ElasticsearchException;
1413
import org.elasticsearch.action.ActionListener;
@@ -239,8 +238,7 @@ public static void setAllElapsedMillis(ClusterStatePublicationEvent clusterState
239238
clusterStatePublicationEvent.setMasterApplyElapsedMillis(0L);
240239
}
241240

242-
public static void awaitClusterState(Logger logger, Predicate<ClusterState> statePredicate, ClusterService clusterService)
243-
throws Exception {
241+
public static void awaitClusterState(Predicate<ClusterState> statePredicate, ClusterService clusterService) {
244242
final var listener = addTemporaryStateListener(clusterService, statePredicate, ESTestCase.TEST_REQUEST_TIMEOUT);
245243
ESTestCase.safeAwait(listener, ESTestCase.TEST_REQUEST_TIMEOUT);
246244
}

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
1818

1919
import org.apache.http.HttpHost;
20-
import org.apache.logging.log4j.Logger;
2120
import org.apache.lucene.search.Sort;
2221
import org.apache.lucene.search.TotalHits;
2322
import org.apache.lucene.tests.util.LuceneTestCase;
@@ -1215,20 +1214,12 @@ public static PendingClusterTasksResponse getClusterPendingTasks(Client client)
12151214
}
12161215
}
12171216

1218-
protected void awaitClusterState(Predicate<ClusterState> statePredicate) throws Exception {
1219-
awaitClusterState(logger, internalCluster().getMasterName(), statePredicate);
1217+
public static void awaitClusterState(Predicate<ClusterState> statePredicate) {
1218+
awaitClusterState(internalCluster().getMasterName(), statePredicate);
12201219
}
12211220

1222-
protected void awaitClusterState(String viaNode, Predicate<ClusterState> statePredicate) throws Exception {
1223-
ClusterServiceUtils.awaitClusterState(logger, statePredicate, internalCluster().getInstance(ClusterService.class, viaNode));
1224-
}
1225-
1226-
public static void awaitClusterState(Logger logger, Predicate<ClusterState> statePredicate) throws Exception {
1227-
awaitClusterState(logger, internalCluster().getMasterName(), statePredicate);
1228-
}
1229-
1230-
public static void awaitClusterState(Logger logger, String viaNode, Predicate<ClusterState> statePredicate) throws Exception {
1231-
ClusterServiceUtils.awaitClusterState(logger, statePredicate, internalCluster().getInstance(ClusterService.class, viaNode));
1221+
public static void awaitClusterState(String viaNode, Predicate<ClusterState> statePredicate) {
1222+
ClusterServiceUtils.awaitClusterState(statePredicate, internalCluster().getInstance(ClusterService.class, viaNode));
12321223
}
12331224

12341225
public static String getNodeId(String nodeName) {

test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ public String getMasterName(@Nullable String viaNode) {
20642064
throw new AssertionError("Unable to get master name, no node found");
20652065
}
20662066
try {
2067-
ClusterServiceUtils.awaitClusterState(logger, state -> state.nodes().getMasterNode() != null, clusterService(viaNode));
2067+
ClusterServiceUtils.awaitClusterState(state -> state.nodes().getMasterNode() != null, clusterService(viaNode));
20682068
final ClusterState state = client(viaNode).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
20692069
final DiscoveryNode masterNode = state.nodes().getMasterNode();
20702070
if (masterNode == null) {

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ public void doTestRunPolicyWithFailureToReadPolicy(boolean asyncAction, boolean
490490

491491
// The cluster state can take a few extra milliseconds to update after the steps are executed
492492
ClusterServiceUtils.awaitClusterState(
493-
logger,
494493
s -> s.metadata().getProject(state.projectId()).index(indexMetadata.getIndex()).getLifecycleExecutionState().stepInfo() != null,
495494
clusterService
496495
);

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlSingleNodeTestCase.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ public void tearDown() throws Exception {
121121

122122
protected void waitForMlTemplates() throws Exception {
123123
// block until the templates are installed
124-
ClusterServiceUtils.awaitClusterState(
125-
logger,
126-
MachineLearning::criticalTemplatesInstalled,
127-
getInstanceFromNode(ClusterService.class)
128-
);
124+
ClusterServiceUtils.awaitClusterState(MachineLearning::criticalTemplatesInstalled, getInstanceFromNode(ClusterService.class));
129125
}
130126

131127
protected <T> void blockingCall(Consumer<ActionListener<T>> function, AtomicReference<T> response, AtomicReference<Exception> error)

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ protected Collection<Class<? extends Plugin>> getMockPlugins() {
169169
}
170170

171171
@Before
172-
public void ensureTemplatesArePresent() throws Exception {
172+
public void ensureTemplatesArePresent() {
173173
if (cluster().size() > 0) {
174-
awaitClusterState(logger, MachineLearning::criticalTemplatesInstalled);
174+
awaitClusterState(MachineLearning::criticalTemplatesInstalled);
175175
}
176176
}
177177

0 commit comments

Comments
 (0)