Skip to content

Commit 1337476

Browse files
authored
Clean up awaitClusterState overloads (#132529)
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 9200652 commit 1337476

File tree

12 files changed

+17
-37
lines changed

12 files changed

+17
-37
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
@@ -568,7 +568,7 @@ protected void addBwCFailedSnapshot(String repoName, String snapshotName, Map<St
568568
);
569569
}
570570

571-
protected void awaitNDeletionsInProgress(int count) throws Exception {
571+
protected void awaitNDeletionsInProgress(int count) {
572572
logger.info("--> wait for [{}] deletions to show up in the cluster state", count);
573573
awaitClusterState(state -> SnapshotDeletionsInProgress.get(state).getEntries().size() == count);
574574
}
@@ -580,7 +580,6 @@ protected void awaitNoMoreRunningOperations() throws Exception {
580580
protected void awaitNoMoreRunningOperations(String viaNode) throws Exception {
581581
logger.info("--> verify no more operations in the cluster state");
582582
awaitClusterState(
583-
logger,
584583
viaNode,
585584
state -> SnapshotsInProgress.get(state).isEmpty() && SnapshotDeletionsInProgress.get(state).hasDeletionsInProgress() == false
586585
);
@@ -615,13 +614,13 @@ public static ActionFuture<CreateSnapshotResponse> startFullSnapshot(
615614
.execute();
616615
}
617616

618-
protected void awaitNumberOfSnapshotsInProgress(int count) throws Exception {
617+
protected void awaitNumberOfSnapshotsInProgress(int count) {
619618
awaitNumberOfSnapshotsInProgress(logger, count);
620619
}
621620

622-
public static void awaitNumberOfSnapshotsInProgress(Logger logger, int count) throws Exception {
621+
public static void awaitNumberOfSnapshotsInProgress(Logger logger, int count) {
623622
logger.info("--> wait for [{}] snapshots to show up in the cluster state", count);
624-
awaitClusterState(logger, state -> SnapshotsInProgress.get(state).count() == count);
623+
awaitClusterState(state -> SnapshotsInProgress.get(state).count() == count);
625624
}
626625

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

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

Lines changed: 2 additions & 5 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,10 +238,8 @@ 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 {
244-
final var listener = addTemporaryStateListener(clusterService, statePredicate, ESTestCase.TEST_REQUEST_TIMEOUT);
245-
ESTestCase.safeAwait(listener, ESTestCase.TEST_REQUEST_TIMEOUT);
241+
public static void awaitClusterState(Predicate<ClusterState> statePredicate, ClusterService clusterService) {
242+
ESTestCase.safeAwait(addTemporaryStateListener(clusterService, statePredicate, TimeValue.THIRTY_SECONDS), TimeValue.THIRTY_SECONDS);
246243
}
247244

248245
public static void awaitNoPendingTasks(ClusterService clusterService) {

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;
@@ -1219,20 +1218,12 @@ public static PendingClusterTasksResponse getClusterPendingTasks(Client client)
12191218
}
12201219
}
12211220

1222-
protected void awaitClusterState(Predicate<ClusterState> statePredicate) throws Exception {
1223-
awaitClusterState(logger, internalCluster().getMasterName(), statePredicate);
1221+
public static void awaitClusterState(Predicate<ClusterState> statePredicate) {
1222+
awaitClusterState(internalCluster().getMasterName(), statePredicate);
12241223
}
12251224

1226-
protected void awaitClusterState(String viaNode, Predicate<ClusterState> statePredicate) throws Exception {
1227-
ClusterServiceUtils.awaitClusterState(logger, statePredicate, internalCluster().getInstance(ClusterService.class, viaNode));
1228-
}
1229-
1230-
public static void awaitClusterState(Logger logger, Predicate<ClusterState> statePredicate) throws Exception {
1231-
awaitClusterState(logger, internalCluster().getMasterName(), statePredicate);
1232-
}
1233-
1234-
public static void awaitClusterState(Logger logger, String viaNode, Predicate<ClusterState> statePredicate) throws Exception {
1235-
ClusterServiceUtils.awaitClusterState(logger, statePredicate, internalCluster().getInstance(ClusterService.class, viaNode));
1225+
public static void awaitClusterState(String viaNode, Predicate<ClusterState> statePredicate) {
1226+
ClusterServiceUtils.awaitClusterState(statePredicate, internalCluster().getInstance(ClusterService.class, viaNode));
12361227
}
12371228

12381229
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)