|
|
|
|
@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
@@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
import org.springframework.util.StopWatch.TaskInfo; |
|
|
|
|
|
|
|
|
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
|
|
|
|
@ -78,18 +77,21 @@ class StopWatchTests {
@@ -78,18 +77,21 @@ class StopWatchTests {
|
|
|
|
|
assertThat(stopWatch.currentTaskName()).isEqualTo(name1); |
|
|
|
|
stopWatch.stop(); |
|
|
|
|
assertThat(stopWatch.isRunning()).isFalse(); |
|
|
|
|
|
|
|
|
|
/* Flaky StopWatch time assertions... |
|
|
|
|
assertThat(stopWatch.getLastTaskTimeNanos()) |
|
|
|
|
.as("last task time in nanoseconds for task #1") |
|
|
|
|
.isGreaterThanOrEqualTo(millisToNanos(duration1 - fudgeFactor)) |
|
|
|
|
.isLessThanOrEqualTo(millisToNanos(duration1 + fudgeFactor)); |
|
|
|
|
.as("last task time in nanoseconds for task #1") |
|
|
|
|
.isGreaterThanOrEqualTo(TimeUnit.MILLISECONDS.toNanos(duration1 - fudgeFactor)) |
|
|
|
|
.isLessThanOrEqualTo(TimeUnit.MILLISECONDS.toNanos(duration1 + fudgeFactor)); |
|
|
|
|
assertThat(stopWatch.getTotalTimeMillis()) |
|
|
|
|
.as("total time in milliseconds for task #1") |
|
|
|
|
.isGreaterThanOrEqualTo(duration1 - fudgeFactor) |
|
|
|
|
.isLessThanOrEqualTo(duration1 + fudgeFactor); |
|
|
|
|
.as("total time in milliseconds for task #1") |
|
|
|
|
.isGreaterThanOrEqualTo(duration1 - fudgeFactor) |
|
|
|
|
.isLessThanOrEqualTo(duration1 + fudgeFactor); |
|
|
|
|
assertThat(stopWatch.getTotalTimeSeconds()) |
|
|
|
|
.as("total time in seconds for task #1") |
|
|
|
|
.isGreaterThanOrEqualTo((duration1 - fudgeFactor) / 1000.0) |
|
|
|
|
.isLessThanOrEqualTo((duration1 + fudgeFactor) / 1000.0); |
|
|
|
|
.as("total time in seconds for task #1") |
|
|
|
|
.isGreaterThanOrEqualTo((duration1 - fudgeFactor) / 1000.0) |
|
|
|
|
.isLessThanOrEqualTo((duration1 + fudgeFactor) / 1000.0); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
stopWatch.start(name2); |
|
|
|
|
Thread.sleep(duration2); |
|
|
|
|
@ -100,17 +102,17 @@ class StopWatchTests {
@@ -100,17 +102,17 @@ class StopWatchTests {
|
|
|
|
|
|
|
|
|
|
/* Flaky StopWatch time assertions... |
|
|
|
|
assertThat(stopWatch.getLastTaskTimeNanos()) |
|
|
|
|
.as("last task time in nanoseconds for task #2") |
|
|
|
|
.isGreaterThanOrEqualTo(millisToNanos(duration2)) |
|
|
|
|
.isLessThanOrEqualTo(millisToNanos(duration2 + fudgeFactor)); |
|
|
|
|
.as("last task time in nanoseconds for task #2") |
|
|
|
|
.isGreaterThanOrEqualTo(TimeUnit.MILLISECONDS.toNanos(duration2)) |
|
|
|
|
.isLessThanOrEqualTo(TimeUnit.MILLISECONDS.toNanos(duration2 + fudgeFactor)); |
|
|
|
|
assertThat(stopWatch.getTotalTimeMillis()) |
|
|
|
|
.as("total time in milliseconds for tasks #1 and #2") |
|
|
|
|
.isGreaterThanOrEqualTo(duration1 + duration2 - fudgeFactor) |
|
|
|
|
.isLessThanOrEqualTo(duration1 + duration2 + fudgeFactor); |
|
|
|
|
.as("total time in milliseconds for tasks #1 and #2") |
|
|
|
|
.isGreaterThanOrEqualTo(duration1 + duration2 - fudgeFactor) |
|
|
|
|
.isLessThanOrEqualTo(duration1 + duration2 + fudgeFactor); |
|
|
|
|
assertThat(stopWatch.getTotalTimeSeconds()) |
|
|
|
|
.as("total time in seconds for task #2") |
|
|
|
|
.isGreaterThanOrEqualTo((duration1 + duration2 - fudgeFactor) / 1000.0) |
|
|
|
|
.isLessThanOrEqualTo((duration1 + duration2 + fudgeFactor) / 1000.0); |
|
|
|
|
.as("total time in seconds for task #2") |
|
|
|
|
.isGreaterThanOrEqualTo((duration1 + duration2 - fudgeFactor) / 1000.0) |
|
|
|
|
.isLessThanOrEqualTo((duration1 + duration2 + fudgeFactor) / 1000.0); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
assertThat(stopWatch.getTaskCount()).isEqualTo(2); |
|
|
|
|
@ -138,12 +140,8 @@ class StopWatchTests {
@@ -138,12 +140,8 @@ class StopWatchTests {
|
|
|
|
|
assertThat(stopWatch.prettyPrint()).contains("No task info kept"); |
|
|
|
|
assertThat(stopWatch.toString()).doesNotContain(name1, name2); |
|
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class) |
|
|
|
|
.isThrownBy(stopWatch::getTaskInfo) |
|
|
|
|
.withMessage("Task info is not being kept!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static long millisToNanos(long duration) { |
|
|
|
|
return MILLISECONDS.toNanos(duration); |
|
|
|
|
.isThrownBy(stopWatch::getTaskInfo) |
|
|
|
|
.withMessage("Task info is not being kept!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|