Github user HeartSaVioR commented on a diff in the pull request:
https://github.com/apache/storm/pull/2734#discussion_r197657288
--- 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()) {
+ simulatedSleepUntilNanos(millisToNanos(currentTimeMillis()
+ ms));
+ } else {
+ Thread.sleep(ms);
+ }
}
}
- public static void sleepNanos(long nanos) throws InterruptedException {
+ public static void parkNanos(long nanos) throws InterruptedException {
if (nanos > 0) {
- sleepUntilNanos(nanoTime() + nanos);
+ if (SIMULATING.get()) {
--- End diff --
Same here, and we may note that we're renaming public method, though Time
class is more likely internal class though.
---