Skip to content

Commit 4e592ea

Browse files
committed
+ housekeeping
1 parent c184784 commit 4e592ea

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/test/java/conseq4j/SpyingTask.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,44 @@ public class SpyingTask implements Runnable {
4242
private final Integer scheduledSequenceIndex;
4343
private String runThreadName;
4444
private long runThreadId;
45-
private long runTimeEndMillis;
46-
private long runTimeStartMillis;
45+
private long runTimeEndNanos;
46+
private long runTimeStartNanos;
4747

4848
public SpyingTask(Integer scheduledSequenceIndex) {
4949
this.scheduledSequenceIndex = scheduledSequenceIndex;
5050
reset();
5151
}
5252

53-
public Duration getActualRunDuration() {
53+
private Duration getActualRunDuration() {
5454
if (!isDone()) {
5555
throw new IllegalStateException("actual run duration not available until run completes");
5656
}
57-
return Duration.ofMillis(this.runTimeEndMillis - this.runTimeStartMillis);
57+
return Duration.ofNanos(this.runTimeEndNanos - this.runTimeStartNanos);
5858
}
5959

6060
public boolean isDone() {
61-
return this.runTimeStartMillis != UNSET_TIME_STAMP && this.runTimeEndMillis != UNSET_TIME_STAMP;
61+
return this.runTimeStartNanos != UNSET_TIME_STAMP && this.runTimeEndNanos != UNSET_TIME_STAMP;
6262
}
6363

6464
@Override
6565
public void run() {
6666
reset();
67-
this.runTimeStartMillis = System.nanoTime();
67+
this.runTimeStartNanos = System.nanoTime();
6868
this.runThreadName = Thread.currentThread().getName();
6969
this.runThreadId = Thread.currentThread().threadId();
7070
await()
7171
.with()
7272
.pollInterval(POLL_INTERVAL)
73-
.until(() -> (System.nanoTime() - this.runTimeStartMillis) >= RUN_DURATION_MILLIS);
74-
this.runTimeEndMillis = System.nanoTime();
73+
.until(() -> (System.nanoTime() - this.runTimeStartNanos) >= RUN_DURATION_MILLIS);
74+
this.runTimeEndNanos = System.nanoTime();
7575
System.out.printf(
7676
"Task %s run by %s:%s completed in %s%n",
77-
scheduledSequenceIndex,
78-
runThreadName,
79-
runThreadId,
80-
Duration.ofNanos(runTimeEndMillis - runTimeStartMillis));
77+
scheduledSequenceIndex, runThreadName, runThreadId, getActualRunDuration());
8178
}
8279

8380
private void reset() {
84-
this.runTimeStartMillis = UNSET_TIME_STAMP;
85-
this.runTimeEndMillis = UNSET_TIME_STAMP;
81+
this.runTimeStartNanos = UNSET_TIME_STAMP;
82+
this.runTimeEndNanos = UNSET_TIME_STAMP;
8683
this.runThreadName = null;
8784
this.runThreadId = UNSET_THREAD_ID;
8885
}

src/test/java/conseq4j/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static void assertConsecutiveRuntimes(@NonNull List<SpyingTask> tasks) {
5656
for (int i = 0; i < tasks.size() - 1; i++) {
5757
SpyingTask current = tasks.get(i);
5858
SpyingTask next = tasks.get(i + 1);
59-
assertTrue(current.getRunTimeEndMillis() <= next.getRunTimeStartMillis());
59+
assertTrue(current.getRunTimeEndNanos() <= next.getRunTimeStartNanos());
6060
}
6161
}
6262

0 commit comments

Comments
 (0)