jsancio commented on code in PR #19854:
URL: https://github.com/apache/kafka/pull/19854#discussion_r2232057083
##########
raft/src/test/java/org/apache/kafka/raft/RequestManagerTest.java:
##########
@@ -245,6 +245,41 @@ public void testFindReadyWithRequestTimedOut() {
assertFalse(cache.isResponseExpected(otherNode, 1));
}
+ @Test
+ public void testHasRequestTimedOut() {
+ List<Node> bootstrapList = makeBootstrapList(2);
+ RequestManager cache = new RequestManager(
+ bootstrapList,
+ retryBackoffMs,
+ requestTimeoutMs,
+ random
+ );
+
+ // Find a ready node with the starting state
+ Node bootstrapNode1 =
cache.findReadyBootstrapServer(time.milliseconds()).get();
+ assertTrue(
+ bootstrapList.contains(bootstrapNode1),
+ String.format("%s is not in %s", bootstrapNode1, bootstrapList)
+ );
+ // Before sending a request, no request should have timed out
+ assertFalse(cache.hasRequestTimedOut(bootstrapNode1,
time.milliseconds()));
+
+ // Send a request
+ cache.onRequestSent(bootstrapNode1, 1, time.milliseconds());
+ assertEquals(
+ Optional.empty(),
+ cache.findReadyBootstrapServer(time.milliseconds())
+ );
+ assertFalse(cache.hasRequestTimedOut(bootstrapNode1,
time.milliseconds()));
+
+ time.sleep(requestTimeoutMs / 2);
+ assertFalse(cache.hasRequestTimedOut(bootstrapNode1,
time.milliseconds()));
+
+ // Timeout the request
+ time.sleep(requestTimeoutMs / 2);
Review Comment:
In integer division, `value / 2 + value / 2` does not equal `value`. You can
see this when value is 3. `3/2` is `1` and `1 + 1` is not `3`. A more obvious
sleep logic is:
```java
time.sleep(requestTimeoutMs - 1);
assertFalse(cache.hasRequestTimedOut(bootstrapNode1,
time.milliseconds()));
// Timeout the request
time.sleep(1);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]