|
30 | 30 | import java.util.concurrent.Executors; |
31 | 31 | import lombok.Getter; |
32 | 32 | import lombok.ToString; |
| 33 | +import org.awaitility.core.ConditionFactory; |
33 | 34 |
|
34 | 35 | /** @author Qingtian Wang */ |
35 | 36 | @ToString |
36 | 37 | @Getter |
37 | 38 | public class SpyingTask implements Runnable { |
38 | | - private static final long RUN_DURATION_MILLIS = 100; |
| 39 | + private static final Duration RUN_DURATION = Duration.ofMillis(50); |
| 40 | + private static final long RUN_DURATION_NANOS = RUN_DURATION.toNanos(); |
39 | 41 | private static final long UNSET_TIME_STAMP = Long.MIN_VALUE; |
40 | 42 | private static final long UNSET_THREAD_ID = Long.MIN_VALUE; |
41 | | - private static final Duration POLL_INTERVAL = Duration.ofMillis(10); |
| 43 | + private static final Duration POLL_INTERVAL = Duration.ofMillis(5); |
| 44 | + private static final ConditionFactory AWAIT = await().with().pollInterval(POLL_INTERVAL); |
42 | 45 | private final Integer scheduledSequenceIndex; |
43 | 46 | private String runThreadName; |
44 | 47 | private long runThreadId; |
@@ -67,10 +70,7 @@ public void run() { |
67 | 70 | this.runTimeStartNanos = System.nanoTime(); |
68 | 71 | this.runThreadName = Thread.currentThread().getName(); |
69 | 72 | this.runThreadId = Thread.currentThread().threadId(); |
70 | | - await() |
71 | | - .with() |
72 | | - .pollInterval(POLL_INTERVAL) |
73 | | - .until(() -> (System.nanoTime() - this.runTimeStartNanos) >= RUN_DURATION_MILLIS); |
| 73 | + AWAIT.until(() -> (System.nanoTime() - this.runTimeStartNanos) >= RUN_DURATION_NANOS); |
74 | 74 | this.runTimeEndNanos = System.nanoTime(); |
75 | 75 | System.out.printf( |
76 | 76 | "Task %s run by %s:%s completed in %s%n", |
|
0 commit comments