jsancio commented on code in PR #14168:
URL: https://github.com/apache/kafka/pull/14168#discussion_r1287699245


##########
metadata/src/test/java/org/apache/kafka/controller/QuorumControllerTest.java:
##########
@@ -445,28 +444,24 @@ public void testBalancePartitionLeaders() throws 
Throwable {
             active.alterPartition(ANONYMOUS_CONTEXT, new AlterPartitionRequest
                 .Builder(alterPartitionRequest, false).build((short) 
0).data()).get();
 
-            AtomicLong lastHeartbeatMs = new 
AtomicLong(getMonotonicMs(active.time()));
+            AtomicLong lastHeartbeatNs = new 
AtomicLong(active.time().nanoseconds());
             sendBrokerHeartbeat(active, allBrokers, brokerEpochs);
             // Check that partitions are balanced
             TestUtils.waitForCondition(
                 () -> {
-                    long currentMonotonicMs = getMonotonicMs(active.time());
-                    if (currentMonotonicMs > lastHeartbeatMs.get() + 
(sessionTimeoutMillis / 2)) {
-                        lastHeartbeatMs.set(currentMonotonicMs);

Review Comment:
   If `active.time().nanoseconds()` overflows (wraps), `currentMonotonicMs > 
lastHeartbeatMs.get() + (sessionTimeoutMillis / 2)` will be false until roughly 
292 years (2^63 nanoseconds). The Java Doc recommends to not comparing 
`nanoTime()` and to instead compare elapsed time `nanoTime() - nanoTime()`. See 
the Java Doc for details: 
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#nanoTime--



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to