diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2024-03-05 13:23:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-05 13:23:57 +0100 |
| commit | 5864cbcbfe2eb8c36ca05c3a39c7e5916aeecaec (patch) | |
| tree | 5b2773b8dc21c2e1b526fb70f829c376dd80532a /opendc-simulator/opendc-simulator-network/src/test | |
| parent | d28002a3c151d198298574312f32f1cb43f3a660 (diff) | |
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
Diffstat (limited to 'opendc-simulator/opendc-simulator-network/src/test')
3 files changed, 118 insertions, 106 deletions
diff --git a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt index 181d9a20..4655bfea 100644 --- a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt +++ b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt @@ -42,105 +42,112 @@ import org.opendc.simulator.kotlin.runSimulation */ class SimNetworkSinkTest { @Test - fun testInitialState() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - - assertAll( - { assertFalse(sink.isConnected) }, - { assertNull(sink.link) }, - { assertEquals(100.0f, sink.capacity) } - ) - } + fun testInitialState() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + + assertAll( + { assertFalse(sink.isConnected) }, + { assertNull(sink.link) }, + { assertEquals(100.0f, sink.capacity) }, + ) + } @Test - fun testDisconnectIdempotent() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - - assertDoesNotThrow { sink.disconnect() } - assertFalse(sink.isConnected) - } + fun testDisconnectIdempotent() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + + assertDoesNotThrow { sink.disconnect() } + assertFalse(sink.isConnected) + } @Test - fun testConnectCircular() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - - assertThrows<IllegalArgumentException> { - sink.connect(sink) + fun testConnectCircular() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + + assertThrows<IllegalArgumentException> { + sink.connect(sink) + } } - } @Test - fun testConnectAlreadyConnectedTarget() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - val source = mockk<SimNetworkPort>(relaxUnitFun = true) - every { source.isConnected } returns true - - assertThrows<IllegalStateException> { - sink.connect(source) + fun testConnectAlreadyConnectedTarget() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + val source = mockk<SimNetworkPort>(relaxUnitFun = true) + every { source.isConnected } returns true + + assertThrows<IllegalStateException> { + sink.connect(source) + } } - } @Test - fun testConnectAlreadyConnected() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - val source1 = TestSource(graph) + fun testConnectAlreadyConnected() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + val source1 = TestSource(graph) - val source2 = mockk<SimNetworkPort>(relaxUnitFun = true) + val source2 = mockk<SimNetworkPort>(relaxUnitFun = true) - every { source2.isConnected } returns false + every { source2.isConnected } returns false - sink.connect(source1) - assertThrows<IllegalStateException> { - sink.connect(source2) + sink.connect(source1) + assertThrows<IllegalStateException> { + sink.connect(source2) + } } - } @Test - fun testConnect() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - val source = TestSource(graph) + fun testConnect() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + val source = TestSource(graph) - sink.connect(source) + sink.connect(source) - yield() + yield() - assertAll( - { assertTrue(sink.isConnected) }, - { assertTrue(source.isConnected) }, - { assertEquals(100.0f, source.outlet.capacity) } - ) + assertAll( + { assertTrue(sink.isConnected) }, + { assertTrue(source.isConnected) }, + { assertEquals(100.0f, source.outlet.capacity) }, + ) - verify { source.logic.onUpdate(any(), any()) } - } + verify { source.logic.onUpdate(any(), any()) } + } @Test - fun testDisconnect() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - val source = TestSource(graph) - - sink.connect(source) - sink.disconnect() - - yield() - - assertAll( - { assertFalse(sink.isConnected) }, - { assertFalse(source.isConnected) }, - { assertEquals(0.0f, source.outlet.capacity) } - ) - } + fun testDisconnect() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + val source = TestSource(graph) + + sink.connect(source) + sink.disconnect() + + yield() + + assertAll( + { assertFalse(sink.isConnected) }, + { assertFalse(source.isConnected) }, + { assertEquals(0.0f, source.outlet.capacity) }, + ) + } } diff --git a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt index 4a489478..b5a00ffc 100644 --- a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt +++ b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt @@ -37,39 +37,41 @@ import org.opendc.simulator.kotlin.runSimulation */ class SimNetworkSwitchVirtualTest { @Test - fun testConnect() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - val source = TestSource(graph) - val switch = SimNetworkSwitchVirtual(graph) + fun testConnect() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + val source = TestSource(graph) + val switch = SimNetworkSwitchVirtual(graph) - switch.newPort().connect(sink) - switch.newPort().connect(source) + switch.newPort().connect(sink) + switch.newPort().connect(source) - yield() + yield() - assertAll( - { assertTrue(sink.isConnected) }, - { assertTrue(source.isConnected) }, - { assertEquals(100.0f, source.outlet.capacity) } - ) + assertAll( + { assertTrue(sink.isConnected) }, + { assertTrue(source.isConnected) }, + { assertEquals(100.0f, source.outlet.capacity) }, + ) - verify { source.logic.onUpdate(any(), any()) } - } + verify { source.logic.onUpdate(any(), any()) } + } @Test - fun testConnectClosedPort() = runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, /*capacity*/ 100.0f) - val switch = SimNetworkSwitchVirtual(graph) + fun testConnectClosedPort() = + runSimulation { + val engine = FlowEngine.create(dispatcher) + val graph = engine.newGraph() + val sink = SimNetworkSink(graph, 100.0f) + val switch = SimNetworkSwitchVirtual(graph) - val port = switch.newPort() - port.close() + val port = switch.newPort() + port.close() - assertThrows<IllegalStateException> { - port.connect(sink) + assertThrows<IllegalStateException> { + port.connect(sink) + } } - } } diff --git a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt index f69db7a2..298a5d48 100644 --- a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt +++ b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt @@ -45,7 +45,10 @@ class TestSource(graph: FlowGraph) : SimNetworkPort(), FlowStageLogic { outlet.push(80.0f) } - override fun onUpdate(ctx: FlowStage, now: Long): Long = Long.MAX_VALUE + override fun onUpdate( + ctx: FlowStage, + now: Long, + ): Long = Long.MAX_VALUE override fun getOutlet(): Outlet = outlet |
