diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-03-25 10:16:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-25 10:16:49 +0100 |
| commit | 074dee1cbca7b3a024d45a3b9dd7d8b51acdd4ee (patch) | |
| tree | 62e154b6cc5b22f79f3aa67cf245c40c1332f7b4 /simulator/opendc-simulator/opendc-simulator-resources/src/test | |
| parent | 6de1ef7424e058603be9ae5a86f0568b40579e5f (diff) | |
| parent | 69598598be2c248acc49e40607b3dd0998ec1ca5 (diff) | |
Add advanced energy model to OpenDC (v1)
This pull request is a preparation for the adding an advanced energy model to OpenDC (#90):
* Add benchmarks for the `opendc-simulator-compute` module, which enables us to quantify the effect on future changes w.r.t. to the energy model on the performance.
* Add `SimResourceTransformer` which can transform resource consumptions. This is useful when transforming from CPU frequency to energy usage for instance.
* Move power models to `opendc-simulator-compute` to be able to be used more generically.
**Breaking API Changes**
* Power models have moved to `opendc-simulator-compute` and now implement the `MachinePowerModel` interface.
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-resources/src/test')
| -rw-r--r-- | simulator/opendc-simulator/opendc-simulator-resources/src/test/kotlin/org/opendc/simulator/resources/SimResourceTransformerTest.kt (renamed from simulator/opendc-simulator/opendc-simulator-resources/src/test/kotlin/org/opendc/simulator/resources/SimResourceForwarderTest.kt) | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-resources/src/test/kotlin/org/opendc/simulator/resources/SimResourceForwarderTest.kt b/simulator/opendc-simulator/opendc-simulator-resources/src/test/kotlin/org/opendc/simulator/resources/SimResourceTransformerTest.kt index 143dbca9..38598f6b 100644 --- a/simulator/opendc-simulator/opendc-simulator-resources/src/test/kotlin/org/opendc/simulator/resources/SimResourceForwarderTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-resources/src/test/kotlin/org/opendc/simulator/resources/SimResourceTransformerTest.kt @@ -36,10 +36,10 @@ import org.opendc.simulator.utils.DelayControllerClockAdapter import org.opendc.utils.TimerScheduler /** - * A test suite for the [SimResourceForwarder] class. + * A test suite for the [SimResourceTransformer] class. */ @OptIn(ExperimentalCoroutinesApi::class) -internal class SimResourceForwarderTest { +internal class SimResourceTransformerTest { @Test fun testExitImmediately() = runBlockingTest { val forwarder = SimResourceForwarder() @@ -165,6 +165,23 @@ internal class SimResourceForwarderTest { } @Test + fun testExitPropagation() = runBlockingTest { + val forwarder = SimResourceForwarder(isCoupled = true) + val clock = DelayControllerClockAdapter(this) + val scheduler = TimerScheduler<Any>(coroutineContext, clock) + val source = SimResourceSource(2000.0, clock, scheduler) + + val consumer = mockk<SimResourceConsumer>(relaxUnitFun = true) + every { consumer.onNext(any()) } returns SimResourceCommand.Exit + + source.startConsumer(forwarder) + forwarder.consume(consumer) + yield() + + assertEquals(SimResourceState.Pending, source.state) + } + + @Test fun testAdjustCapacity() = runBlockingTest { val forwarder = SimResourceForwarder() val clock = DelayControllerClockAdapter(this) @@ -183,4 +200,19 @@ internal class SimResourceForwarderTest { assertEquals(3000, currentTime) verify(exactly = 1) { consumer.onCapacityChanged(any(), true) } } + + @Test + fun testTransformExit() = runBlockingTest { + val forwarder = SimResourceTransformer { _, _ -> SimResourceCommand.Exit } + val clock = DelayControllerClockAdapter(this) + val scheduler = TimerScheduler<Any>(coroutineContext, clock) + val source = SimResourceSource(1.0, clock, scheduler) + + val consumer = spyk(SimWorkConsumer(2.0, 1.0)) + source.startConsumer(forwarder) + forwarder.consume(consumer) + + assertEquals(0, currentTime) + verify(exactly = 1) { consumer.onNext(any()) } + } } |
