summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-network
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-network')
-rw-r--r--opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt165
-rw-r--r--opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt54
-rw-r--r--opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt5
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