summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2022-09-19 21:37:32 +0200
committerHarald Musum <musum@yahooinc.com>2022-09-19 21:37:32 +0200
commit5609231a42961235bbdb041922a3b026401a8d30 (patch)
treeb516d39ea44e1e39dc5e907a19139e630dbe4b9d /clustercontroller-core
parentdd11dce329e66dc6474a00b798f46a1ee5febfb0 (diff)
Simplify: Require wait task to be non-null
Diffstat (limited to 'clustercontroller-core')
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java39
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java17
2 files changed, 32 insertions, 24 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
index be06ea5a0d5..41874b9a224 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
@@ -21,6 +21,7 @@ import com.yahoo.vdslib.state.State;
import com.yahoo.vespa.clustercontroller.core.rpc.RpcServer;
import com.yahoo.vespa.clustercontroller.core.testutils.LogFormatter;
import com.yahoo.vespa.clustercontroller.core.testutils.WaitCondition;
+import com.yahoo.vespa.clustercontroller.core.testutils.WaitTask;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -114,22 +115,28 @@ public class RpcServerTest extends FleetControllerTest {
timer.advanceTime(options.nodeStateRequestTimeoutMS() + options.maxSlobrokDisconnectGracePeriod());
wait(new WaitCondition.StateWait(fleetController(), fleetController().getMonitor()) {
- @Override
- public String isConditionMet() {
- if (currentState == null) {
- return "No cluster state defined yet";
- }
- NodeState distState = currentState.getNodeState(new Node(NodeType.DISTRIBUTOR, 0));
- if (distState.getState() != State.DOWN) {
- return "Distributor not detected down yet: " + currentState.toString();
- }
- NodeState storState = currentState.getNodeState(new Node(NodeType.STORAGE, 9));
- if (!storState.getState().oneOf("md")) {
- return "Storage node not detected down yet: " + currentState.toString();
- }
- return null;
- }
- }, null, timeout());
+ @Override
+ public String isConditionMet() {
+ if (currentState == null) {
+ return "No cluster state defined yet";
+ }
+ NodeState distState = currentState.getNodeState(new Node(NodeType.DISTRIBUTOR, 0));
+ if (distState.getState() != State.DOWN) {
+ return "Distributor not detected down yet: " + currentState.toString();
+ }
+ NodeState storState = currentState.getNodeState(new Node(NodeType.STORAGE, 9));
+ if (!storState.getState().oneOf("md")) {
+ return "Storage node not detected down yet: " + currentState.toString();
+ }
+ return null;
+ }
+ }, new WaitTask() {
+ @Override
+ public boolean performWaitTask() {
+ return false;
+ }
+ },
+ timeout());
int rpcPort = fleetController().getRpcPort();
Target connection = supervisor.connect(new Spec("localhost", rpcPort));
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java
index a7de2f0eedb..5bff101906d 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java
@@ -10,6 +10,7 @@ import java.time.Instant;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -88,7 +89,9 @@ public interface Waiter {
}
public final void wait(WaitCondition c, WaitTask wt, Duration timeout) {
- log.log(Level.INFO, "Waiting for " + c + (wt == null ? "" : " with wait task " + wt));
+ Objects.requireNonNull(wt, "wait task cannot be null");
+
+ log.log(Level.INFO, "Waiting for " + c + " with wait task " + wt);
Instant endTime = Instant.now().plus(timeout);
String lastReason = null;
while (true) {
@@ -104,17 +107,15 @@ public interface Waiter {
}
try {
boolean allowWait = true;
- if (wt != null) {
- if (wt.performWaitTask()) {
- data.getMonitor().notifyAll();
- allowWait = false;
- }
+ if (wt.performWaitTask()) {
+ data.getMonitor().notifyAll();
+ allowWait = false;
}
Duration timeLeft = Duration.between(Instant.now(), endTime);
if (timeLeft.isNegative())
- throw new IllegalStateException("Timed out waiting max " + timeout + " ms for " + c + (wt == null ? "" : "\n with wait task " + wt) + ",\n reason: " + reason);
+ throw new IllegalStateException("Timed out waiting max " + timeout + " ms for " + c + "\n with wait task " + wt + ",\n reason: " + reason);
if (allowWait)
- data.getMonitor().wait(wt == null ? WaitTask.defaultTaskFrequencyMillis : Math.min(wt.getWaitTaskFrequencyInMillis(), timeLeft.toMillis()));
+ data.getMonitor().wait(Math.min(wt.getWaitTaskFrequencyInMillis(), timeLeft.toMillis()));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}