summaryrefslogtreecommitdiff
path: root/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-11-13 18:16:19 +0000
committerGitHub <noreply@github.com>2022-11-13 18:16:19 +0000
commit52eed48441693149993db79b63431b99e0973027 (patch)
treeba267db531bc3d81409ddfe9caeb6d3b5a65e8c8 /opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt
parent183cfa96910ebb74c668dea7ef98071966f8fcb9 (diff)
parent33d91ef30ad7bcb73365934fe536461210d1082a (diff)
merge: Increase minimum Java version to 17 (#115)
This pull request increases the minimum version of Java required by OpenDC to 17. This new version of Java introduces several new features compared to our old minimum version (11), which we attempt to apply in this conversion. ## Implementation Notes :hammer_and_pick: * Increase minimum Java version to Java 17 * Use RandomGenerator as randomness source * Add common dispatcher interface * Add compatibility with Kotlin coroutines * Use InstantSource as time source * Re-implement SimulationScheduler as Dispatcher * Replace use of CoroutineContext by Dispatcher ## External Dependencies :four_leaf_clover: * Java 17 ## Breaking API Changes :warning: * The use of `CoroutineContext` and `Clock` as parameters of classes has been replaced by the `Dispatcher` interface. * The use of `Clock` has been replaced by `InstantSource` which does not carry time zone info. * The use of `Random` and `SplittableRandom` as parameter type has been replaced by `RandomGenerator`
Diffstat (limited to 'opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt')
-rw-r--r--opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt31
1 files changed, 12 insertions, 19 deletions
diff --git a/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt b/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt
index 22a26111..3947fa2e 100644
--- a/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt
+++ b/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt
@@ -29,25 +29,18 @@ import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.opendc.simulator.kotlin.runSimulation
-import java.time.Clock
-import kotlin.coroutines.EmptyCoroutineContext
/**
* A test suite for the [TimerScheduler] class.
*/
-internal class TimerSchedulerTest {
- @Test
- fun testEmptyContext() {
- assertThrows<IllegalArgumentException> { TimerScheduler<Unit>(EmptyCoroutineContext, Clock.systemUTC()) }
- }
-
+class TimerSchedulerTest {
@Test
fun testBasicTimer() {
runSimulation {
- val scheduler = TimerScheduler<Int>(coroutineContext, clock)
+ val scheduler = TimerScheduler<Int>(dispatcher)
scheduler.startSingleTimer(0, 1000) {
- assertEquals(1000, clock.millis())
+ assertEquals(1000, timeSource.millis())
}
assertTrue(scheduler.isTimerActive(0))
@@ -58,7 +51,7 @@ internal class TimerSchedulerTest {
@Test
fun testCancelNonExisting() {
runSimulation {
- val scheduler = TimerScheduler<Int>(coroutineContext, clock)
+ val scheduler = TimerScheduler<Int>(dispatcher)
scheduler.cancel(1)
}
@@ -67,7 +60,7 @@ internal class TimerSchedulerTest {
@Test
fun testCancelExisting() {
runSimulation {
- val scheduler = TimerScheduler<Int>(coroutineContext, clock)
+ val scheduler = TimerScheduler<Int>(dispatcher)
scheduler.startSingleTimer(0, 1000) {
fail()
@@ -76,7 +69,7 @@ internal class TimerSchedulerTest {
scheduler.startSingleTimer(1, 100) {
scheduler.cancel(0)
- assertEquals(100, clock.millis())
+ assertEquals(100, timeSource.millis())
}
}
}
@@ -84,7 +77,7 @@ internal class TimerSchedulerTest {
@Test
fun testCancelAll() {
runSimulation {
- val scheduler = TimerScheduler<Int>(coroutineContext, clock)
+ val scheduler = TimerScheduler<Int>(dispatcher)
scheduler.startSingleTimer(0, 1000) { fail() }
scheduler.startSingleTimer(1, 100) { fail() }
@@ -95,12 +88,12 @@ internal class TimerSchedulerTest {
@Test
fun testOverride() {
runSimulation {
- val scheduler = TimerScheduler<Int>(coroutineContext, clock)
+ val scheduler = TimerScheduler<Int>(dispatcher)
scheduler.startSingleTimer(0, 1000) { fail() }
scheduler.startSingleTimer(0, 200) {
- assertEquals(200, clock.millis())
+ assertEquals(200, timeSource.millis())
}
}
}
@@ -108,12 +101,12 @@ internal class TimerSchedulerTest {
@Test
fun testOverrideBlock() {
runSimulation {
- val scheduler = TimerScheduler<Int>(coroutineContext, clock)
+ val scheduler = TimerScheduler<Int>(dispatcher)
scheduler.startSingleTimer(0, 1000) { fail() }
scheduler.startSingleTimer(0, 1000) {
- assertEquals(1000, clock.millis())
+ assertEquals(1000, timeSource.millis())
}
}
}
@@ -121,7 +114,7 @@ internal class TimerSchedulerTest {
@Test
fun testNegativeDelay() {
runSimulation {
- val scheduler = TimerScheduler<Int>(coroutineContext, clock)
+ val scheduler = TimerScheduler<Int>(dispatcher)
assertThrows<IllegalArgumentException> {
scheduler.startSingleTimer(1, -1) {