From 5864cbcbfe2eb8c36ca05c3a39c7e5916aeecaec Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Tue, 5 Mar 2024 13:23:57 +0100 Subject: Updated package versions, updated web server tests. (#207) * Updated all package versions including kotlin. Updated all web-server tests to run. * Changed the java version of the tests. OpenDC now only supports java 19. * small update * test update * new update * updated docker version to 19 * updated docker version to 19 --- .../opendc/simulator/kotlin/SimulationBuilders.kt | 16 +++++---- .../simulator/kotlin/SimulationCoroutineScope.kt | 2 +- .../kotlin/org/opendc/simulator/TaskQueueTest.kt | 18 +++++----- .../simulator/kotlin/SimulationBuildersTest.kt | 42 +++++++++++----------- 4 files changed, 41 insertions(+), 37 deletions(-) (limited to 'opendc-simulator/opendc-simulator-core/src') diff --git a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt index 271b89e0..bc232ce0 100644 --- a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt +++ b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt @@ -66,14 +66,15 @@ import kotlin.coroutines.EmptyCoroutineContext public fun runSimulation( context: CoroutineContext = EmptyCoroutineContext, scheduler: SimulationDispatcher = SimulationDispatcher(), - body: suspend SimulationCoroutineScope.() -> Unit + body: suspend SimulationCoroutineScope.() -> Unit, ) { val (safeContext, job, dispatcher) = context.checkArguments(scheduler) val startingJobs = job.activeJobs() val scope = SimulationCoroutineScope(safeContext) - val deferred = scope.async { - body(scope) - } + val deferred = + scope.async { + body(scope) + } dispatcher.advanceUntilIdle() deferred.getCompletionExceptionOrNull()?.let { throw it @@ -105,9 +106,10 @@ private fun Job.activeJobs(): Set { * Convert a [ContinuationInterceptor] into a [SimulationDispatcher] if possible. */ internal fun ContinuationInterceptor.asSimulationDispatcher(): SimulationDispatcher { - val provider = this as? DispatcherProvider ?: throw IllegalArgumentException( - "DispatcherProvider such as SimulatorCoroutineDispatcher as the ContinuationInterceptor(Dispatcher) is required" - ) + val provider = + this as? DispatcherProvider ?: throw IllegalArgumentException( + "DispatcherProvider such as SimulatorCoroutineDispatcher as the ContinuationInterceptor(Dispatcher) is required", + ) return provider.dispatcher as? SimulationDispatcher ?: throw IllegalArgumentException("Active dispatcher is not a SimulationDispatcher") } diff --git a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt index ca49fc53..a29e9404 100644 --- a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt +++ b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineScope.kt @@ -43,7 +43,7 @@ public interface SimulationCoroutineScope : CoroutineScope, SimulationController */ public fun SimulationCoroutineScope( context: CoroutineContext = EmptyCoroutineContext, - scheduler: SimulationDispatcher = SimulationDispatcher() + scheduler: SimulationDispatcher = SimulationDispatcher(), ): SimulationCoroutineScope { var safeContext = context val simulationDispatcher: SimulationDispatcher diff --git a/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt b/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt index 56dd83aa..eaafedfd 100644 --- a/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt +++ b/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt @@ -47,7 +47,7 @@ class TaskQueueTest { fun testPollEmpty() { assertAll( { assertEquals(Long.MAX_VALUE, queue.peekDeadline()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -63,7 +63,7 @@ class TaskQueueTest { assertAll( { assertEquals(100, queue.peekDeadline()) }, { assertEquals(entry, queue.poll()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -86,7 +86,7 @@ class TaskQueueTest { { assertEquals(entryB, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -109,7 +109,7 @@ class TaskQueueTest { { assertEquals(entryA, queue.poll()) }, { assertEquals(entryB, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -136,7 +136,7 @@ class TaskQueueTest { { assertEquals(entryD, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -160,7 +160,7 @@ class TaskQueueTest { { assertEquals(20, queue.peekDeadline()) }, { assertEquals(entryB, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -184,7 +184,7 @@ class TaskQueueTest { { assertEquals(58, queue.peekDeadline()) }, { assertEquals(entryC, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -208,7 +208,7 @@ class TaskQueueTest { { assertEquals(20, queue.peekDeadline()) }, { assertEquals(entryB, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) } + { assertNull(queue.poll()) }, ) } @@ -228,7 +228,7 @@ class TaskQueueTest { assertAll( { assertFalse(queue.remove(10, 1)) }, - { assertFalse(queue.remove(58, 2)) } + { assertFalse(queue.remove(58, 2)) }, ) } } diff --git a/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/kotlin/SimulationBuildersTest.kt b/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/kotlin/SimulationBuildersTest.kt index 26419a50..b25025ef 100644 --- a/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/kotlin/SimulationBuildersTest.kt +++ b/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/kotlin/SimulationBuildersTest.kt @@ -38,31 +38,33 @@ import org.junit.jupiter.api.assertThrows */ class SimulationBuildersTest { @Test - fun testDelay() = runSimulation { - assertEquals(0, currentTime) - delay(100) - assertEquals(100, currentTime) - } + fun testDelay() = + runSimulation { + assertEquals(0, currentTime) + delay(100) + assertEquals(100, currentTime) + } @Test - fun testController() = runSimulation { - var completed = false + fun testController() = + runSimulation { + var completed = false - launch { - delay(20) - completed = true - } + launch { + delay(20) + completed = true + } - advanceBy(10) - assertFalse(completed) - advanceBy(11) - assertTrue(completed) + advanceBy(10) + assertFalse(completed) + advanceBy(11) + assertTrue(completed) - completed = false - launch { completed = true } - runCurrent() - assertTrue(completed) - } + completed = false + launch { completed = true } + runCurrent() + assertTrue(completed) + } @Test fun testFailOnActiveJobs() { -- cgit v1.2.3