Github user srdo commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2734#discussion_r197686035
  
    --- 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 --
    
    `sleepUntil` works fine. It's just a little silly in the case where we 
aren't simulating, because this method would calculate `currentTimeMillis() + 
ms`, and `sleepUntil` would then do the reverse to calculate how many ms to 
pass to `Thread.sleep`.


---

Reply via email to