Github user HeartSaVioR commented on a diff in the pull request:
https://github.com/apache/storm/pull/2734#discussion_r197657251
--- Diff: storm-client/src/jvm/org/apache/storm/utils/Time.java ---
@@ -82,45 +66,49 @@ public static void sleepUntilNanos(long
targetTimeNanos) throws InterruptedExcep
private static void simulatedSleepUntilNanos(long targetTimeNanos)
throws InterruptedException {
try {
synchronized (SLEEP_TIMES_LOCK) {
- if (THREAD_SLEEP_TIMES_NANOS == null) {
+ if (!SIMULATING.get()) {
LOG.debug("{} is still sleeping after simulated time
disabled.", Thread.currentThread(),
- new RuntimeException("STACK TRACE"));
+ new RuntimeException("STACK TRACE"));
throw new InterruptedException();
}
THREAD_SLEEP_TIMES_NANOS.put(Thread.currentThread(), new
AtomicLong(targetTimeNanos));
}
while (SIMULATED_CURR_TIME_NANOS.get() < targetTimeNanos) {
synchronized (SLEEP_TIMES_LOCK) {
- if (THREAD_SLEEP_TIMES_NANOS == null) {
+ if (!SIMULATING.get()) {
LOG.debug("{} is still sleeping after simulated
time disabled.", Thread.currentThread(),
new RuntimeException("STACK TRACE"));
throw new InterruptedException();
}
- }
- long autoAdvance = AUTO_ADVANCE_NANOS_ON_SLEEP.get();
- if (autoAdvance > 0) {
- advanceTimeNanos(autoAdvance);
+ long autoAdvance = AUTO_ADVANCE_NANOS_ON_SLEEP.get();
+ if (autoAdvance > 0) {
+ advanceTimeNanos(autoAdvance);
+ }
}
Thread.sleep(10);
}
} finally {
- synchronized (SLEEP_TIMES_LOCK) {
- if (SIMULATING.get() && THREAD_SLEEP_TIMES_NANOS != null) {
-
THREAD_SLEEP_TIMES_NANOS.remove(Thread.currentThread());
- }
- }
+ THREAD_SLEEP_TIMES_NANOS.remove(Thread.currentThread());
}
}
-
+
public static void sleep(long ms) throws InterruptedException {
if (ms > 0) {
- sleepUntil(currentTimeMillis() + ms);
+ if (SIMULATING.get()) {
--- End diff --
Is there any reason to not use `sleepUntil`? If you think `sleepUntil` is
broken, the method must be fixed since the method is exposed to `public`. If
not, why not using `sleepUntil`?
---