summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-power/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-05 14:44:43 +0200
committerGitHub <noreply@github.com>2022-10-05 14:44:43 +0200
commitc2047d09b27b0c05f5c203509dde524e17d3b729 (patch)
tree3903d8aed5e87850c92e1b2dce8379ea99bdfa6d /opendc-simulator/opendc-simulator-power/src
parentec3b5b462c1b8296ba18a3872f56d569fa70e45b (diff)
parentbe176910eb870209576326ffaad8bf21241fccbd (diff)
merge: Extract scheduler from simulation coroutine dispatcher (#106)
This pull request extracts the scheduler from the `SimulationCoroutineDispatcher` into a separate `SimulationScheduler` class which allows users to re-use the scheduler between different coroutine dispatchers. We implement the `SimulationScheduler` in Java, removing the explicit dependency on Kotlin or `kotlinx-coroutines`. The scheduler uses a separate specialized priority queue implementation that eliminates allocation in the hot path of the simulator. ## Implementation Notes :hammer_and_pick: * Add Java-based simulator core * Use SimulationScheduler in coroutine dispatcher * Rename runBlockingSimulation to runSimulation ## External Dependencies :four_leaf_clover: * N/A ## Breaking API Changes :warning: * The Kotlin API for simulation has been moved to `org.opendc.simulator.kotlin`. * `runBlockingSImulation` renamed to `runSimulation`
Diffstat (limited to 'opendc-simulator/opendc-simulator-power/src')
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt14
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt16
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt10
3 files changed, 20 insertions, 20 deletions
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
index 7cc4b801..29c50d3f 100644
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
+++ b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
@@ -27,17 +27,17 @@ import io.mockk.verify
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
import org.opendc.simulator.flow.FlowSource
import org.opendc.simulator.flow.source.FixedFlowSource
+import org.opendc.simulator.kotlin.runSimulation
/**
* Test suite for the [SimPdu] class.
*/
internal class SimPduTest {
@Test
- fun testZeroOutlets() = runBlockingSimulation {
+ fun testZeroOutlets() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val pdu = SimPdu(engine)
@@ -47,7 +47,7 @@ internal class SimPduTest {
}
@Test
- fun testSingleOutlet() = runBlockingSimulation {
+ fun testSingleOutlet() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val pdu = SimPdu(engine)
@@ -58,7 +58,7 @@ internal class SimPduTest {
}
@Test
- fun testDoubleOutlet() = runBlockingSimulation {
+ fun testDoubleOutlet() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val pdu = SimPdu(engine)
@@ -71,7 +71,7 @@ internal class SimPduTest {
}
@Test
- fun testDisconnect() = runBlockingSimulation {
+ fun testDisconnect() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val pdu = SimPdu(engine)
@@ -89,7 +89,7 @@ internal class SimPduTest {
}
@Test
- fun testLoss() = runBlockingSimulation {
+ fun testLoss() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
// https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
@@ -100,7 +100,7 @@ internal class SimPduTest {
}
@Test
- fun testOutletClose() = runBlockingSimulation {
+ fun testOutletClose() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val pdu = SimPdu(engine)
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
index 4f319e65..b83b6ba7 100644
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
+++ b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
@@ -30,17 +30,17 @@ import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
import org.opendc.simulator.flow.FlowSource
import org.opendc.simulator.flow.source.FixedFlowSource
+import org.opendc.simulator.kotlin.runSimulation
/**
* Test suite for the [SimPowerSource]
*/
internal class SimPowerSourceTest {
@Test
- fun testInitialState() = runBlockingSimulation {
+ fun testInitialState() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
@@ -50,7 +50,7 @@ internal class SimPowerSourceTest {
}
@Test
- fun testDisconnectIdempotent() = runBlockingSimulation {
+ fun testDisconnectIdempotent() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
@@ -59,7 +59,7 @@ internal class SimPowerSourceTest {
}
@Test
- fun testConnect() = runBlockingSimulation {
+ fun testConnect() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val inlet = SimpleInlet()
@@ -74,7 +74,7 @@ internal class SimPowerSourceTest {
}
@Test
- fun testDisconnect() = runBlockingSimulation {
+ fun testDisconnect() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val consumer = spyk(FixedFlowSource(100.0, utilization = 1.0))
@@ -89,7 +89,7 @@ internal class SimPowerSourceTest {
}
@Test
- fun testDisconnectAssertion() = runBlockingSimulation {
+ fun testDisconnectAssertion() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
@@ -105,7 +105,7 @@ internal class SimPowerSourceTest {
}
@Test
- fun testOutletAlreadyConnected() = runBlockingSimulation {
+ fun testOutletAlreadyConnected() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val inlet = SimpleInlet()
@@ -119,7 +119,7 @@ internal class SimPowerSourceTest {
}
@Test
- fun testInletAlreadyConnected() = runBlockingSimulation {
+ fun testInletAlreadyConnected() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
index e19e72fa..2b2921d7 100644
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
+++ b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
@@ -27,17 +27,17 @@ import io.mockk.verify
import org.junit.jupiter.api.Assertions.assertAll
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
import org.opendc.simulator.flow.FlowSource
import org.opendc.simulator.flow.source.FixedFlowSource
+import org.opendc.simulator.kotlin.runSimulation
/**
* Test suite for the [SimUps] class.
*/
internal class SimUpsTest {
@Test
- fun testSingleInlet() = runBlockingSimulation {
+ fun testSingleInlet() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
val ups = SimUps(engine)
@@ -48,7 +48,7 @@ internal class SimUpsTest {
}
@Test
- fun testDoubleInlet() = runBlockingSimulation {
+ fun testDoubleInlet() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source1 = SimPowerSource(engine, capacity = 100.0)
val source2 = SimPowerSource(engine, capacity = 100.0)
@@ -65,7 +65,7 @@ internal class SimUpsTest {
}
@Test
- fun testLoss() = runBlockingSimulation {
+ fun testLoss() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source = SimPowerSource(engine, capacity = 100.0)
// https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
@@ -77,7 +77,7 @@ internal class SimUpsTest {
}
@Test
- fun testDisconnect() = runBlockingSimulation {
+ fun testDisconnect() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val source1 = SimPowerSource(engine, capacity = 100.0)
val source2 = SimPowerSource(engine, capacity = 100.0)