diff options
author | Harald Musum <musum@yahooinc.com> | 2023-01-02 08:20:36 +0100 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2023-01-02 08:20:36 +0100 |
commit | f06fe807d37320afa23236404e7d9157a618530e (patch) | |
tree | f3365a988f9a2c1d6696467b1d1dab0293645f14 /clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DummyVdsNode.java | |
parent | 92bddcb26f6f16e9c0589d81eccab56e1e417953 (diff) |
Rename and document to make waiting requests code clearer
Diffstat (limited to 'clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DummyVdsNode.java')
-rw-r--r-- | clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DummyVdsNode.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DummyVdsNode.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DummyVdsNode.java index 80b2e2dbc42..b0f5056791a 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DummyVdsNode.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DummyVdsNode.java @@ -62,11 +62,11 @@ public class DummyVdsNode { static class Req { Request request; - long timeout; + long timeToReply; - Req(Request r, long timeout) { + Req(Request r, long timeToReply) { request = r; - this.timeout = timeout; + this.timeToReply = timeToReply; } } static class BackOff implements BackOffPolicy { @@ -75,6 +75,8 @@ public class DummyVdsNode { public boolean shouldWarn(double v) { return false; } public boolean shouldInform(double v) { return false; } } + + /** List of requests that should be replied to after a specified time */ private final List<Req> waitingRequests = new LinkedList<>(); /** @@ -93,8 +95,8 @@ public class DummyVdsNode { long currentTime = timer.getCurrentTimeInMillis(); for (Iterator<Req> it = waitingRequests.iterator(); it.hasNext(); ) { Req r = it.next(); - if (r.timeout <= currentTime) { - log.log(Level.FINE, () -> "Dummy node " + DummyVdsNode.this + ": Responding to node state request at time " + currentTime); + if (currentTime >= r.timeToReply) { + log.log(Level.INFO, () -> "Dummy node " + DummyVdsNode.this + ": Responding to node state request at time " + currentTime); r.request.returnValues().add(new StringValue(nodeState.serialize())); if (r.request.methodName().equals("getnodestate3")) { r.request.returnValues().add(new StringValue(hostInfo)); @@ -349,11 +351,12 @@ public class DummyVdsNode { boolean sentReply = sendGetNodeStateReply(index); NodeState givenState = (oldState.equals("unknown") ? null : NodeState.deserialize(type, oldState)); if (givenState != null && (givenState.equals(nodeState) || sentReply)) { - log.log(Level.FINE, () -> "Dummy node " + this + ": Has same state as reported " + givenState + ". Queuing request. Timeout is " + timeout + " ms. " - + "Will be answered at time " + (timer.getCurrentTimeInMillis() + timeout * 800L / 1000)); + long timeToReply = timer.getCurrentTimeInMillis() + timeout * 800L / 1000; + log.log(Level.FINE, () -> "Dummy node " + this + " has same state as reported (" + givenState + "). Queuing request. Timeout is " + timeout + " ms. " + + "Will be answered at time " + timeToReply); req.detach(); - waitingRequests.add(new Req(req, timer.getCurrentTimeInMillis() + timeout * 800L / 1000)); - log.log(Level.FINE, () -> "Dummy node " + this + " has now " + waitingRequests.size() + " entries and is " + (waitingRequests.isEmpty() ? "empty" : "not empty")); + waitingRequests.add(new Req(req, timeToReply)); + log.log(Level.FINE, () -> "Dummy node " + this + " has " + waitingRequests.size() + " requests waiting to be answered"); timer.notifyAll(); } else { log.log(Level.FINE, () -> "Dummy node " + this + ": Request had " + (givenState == null ? "no state" : "different state(" + givenState +")") + ". Answering with " + nodeState); |