From be176910eb870209576326ffaad8bf21241fccbd Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 5 Oct 2022 14:10:11 +0200 Subject: refactor(sim/core): Rename runBlockingSimulation to runSimulation This change renames the method `runBlockingSimulation` to `runSimulation` to put more emphasis on the simulation part of the method. The blocking part is not that important, but this behavior is still described in the method documentation. --- .../kotlin/org/opendc/common/util/PacerTest.kt | 12 +++---- .../org/opendc/common/util/TimerSchedulerTest.kt | 16 ++++----- .../opendc/compute/service/ComputeServiceTest.kt | 32 +++++++++--------- .../opendc/compute/service/InternalServerTest.kt | 26 +++++++-------- .../org/opendc/compute/simulator/SimHostTest.kt | 6 ++-- .../simulator/failure/HostFaultInjectorTest.kt | 8 ++--- .../experiments/capelin/CapelinBenchmarks.kt | 4 +-- .../opendc/experiments/capelin/CapelinRunner.kt | 4 +-- .../experiments/capelin/CapelinIntegrationTest.kt | 10 +++--- .../org/opendc/experiments/faas/FaaSExperiment.kt | 4 +-- .../org/opendc/experiments/tf20/TensorFlowTest.kt | 8 ++--- .../experiments/tf20/core/SimTFDeviceTest.kt | 4 +-- .../org/opendc/faas/service/FaaSServiceTest.kt | 22 ++++++------- .../opendc/faas/simulator/SimFaaSServiceTest.kt | 4 +-- .../simulator/compute/SimMachineBenchmarks.kt | 16 ++++----- .../org/opendc/simulator/compute/SimMachineTest.kt | 24 +++++++------- .../opendc/simulator/compute/device/SimPsuTest.kt | 6 ++-- .../compute/kernel/SimFairShareHypervisorTest.kt | 10 +++--- .../compute/kernel/SimSpaceSharedHypervisorTest.kt | 14 ++++---- .../compute/workload/SimTraceWorkloadTest.kt | 10 +++--- .../opendc/simulator/kotlin/SimulationBuilders.kt | 38 +++++++++++++++++----- .../org/opendc/simulator/flow/FlowBenchmarks.kt | 22 ++++++------- .../simulator/flow/FlowConsumerContextTest.kt | 8 ++--- .../org/opendc/simulator/flow/FlowForwarderTest.kt | 28 ++++++++-------- .../org/opendc/simulator/flow/FlowSinkTest.kt | 22 ++++++------- .../flow/mux/ForwardingFlowMultiplexerTest.kt | 10 +++--- .../flow/mux/MaxMinFlowMultiplexerTest.kt | 8 ++--- .../simulator/flow/source/FixedFlowSourceTest.kt | 6 ++-- .../opendc/simulator/network/SimNetworkSinkTest.kt | 16 ++++----- .../network/SimNetworkSwitchVirtualTest.kt | 6 ++-- .../org/opendc/simulator/power/SimPduTest.kt | 14 ++++---- .../opendc/simulator/power/SimPowerSourceTest.kt | 16 ++++----- .../org/opendc/simulator/power/SimUpsTest.kt | 10 +++--- .../kotlin/org/opendc/web/runner/OpenDCRunner.kt | 4 +-- .../opendc/workflow/service/WorkflowServiceTest.kt | 4 +-- 35 files changed, 237 insertions(+), 215 deletions(-) diff --git a/opendc-common/src/test/kotlin/org/opendc/common/util/PacerTest.kt b/opendc-common/src/test/kotlin/org/opendc/common/util/PacerTest.kt index 066bc13b..de9fd472 100644 --- a/opendc-common/src/test/kotlin/org/opendc/common/util/PacerTest.kt +++ b/opendc-common/src/test/kotlin/org/opendc/common/util/PacerTest.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.delay import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.time.Clock import kotlin.coroutines.EmptyCoroutineContext @@ -43,7 +43,7 @@ class PacerTest { fun testSingleEnqueue() { var count = 0 - runBlockingSimulation { + runSimulation { val pacer = Pacer(coroutineContext, clock, quantum = 100) { count++ } @@ -58,7 +58,7 @@ class PacerTest { fun testCascade() { var count = 0 - runBlockingSimulation { + runSimulation { val pacer = Pacer(coroutineContext, clock, quantum = 100) { count++ } @@ -76,7 +76,7 @@ class PacerTest { fun testCancel() { var count = 0 - runBlockingSimulation { + runSimulation { val pacer = Pacer(coroutineContext, clock, quantum = 100) { count++ } @@ -94,7 +94,7 @@ class PacerTest { fun testCancelWithoutPending() { var count = 0 - runBlockingSimulation { + runSimulation { val pacer = Pacer(coroutineContext, clock, quantum = 100) { count++ } @@ -112,7 +112,7 @@ class PacerTest { fun testSubsequent() { var count = 0 - runBlockingSimulation { + runSimulation { val pacer = Pacer(coroutineContext, clock, quantum = 100) { count++ } diff --git a/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt b/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt index 93da5646..183ab66a 100644 --- a/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt +++ b/opendc-common/src/test/kotlin/org/opendc/common/util/TimerSchedulerTest.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.time.Clock import kotlin.coroutines.EmptyCoroutineContext @@ -42,7 +42,7 @@ internal class TimerSchedulerTest { @Test fun testBasicTimer() { - runBlockingSimulation { + runSimulation { val scheduler = TimerScheduler(coroutineContext, clock) scheduler.startSingleTimer(0, 1000) { @@ -56,7 +56,7 @@ internal class TimerSchedulerTest { @Test fun testCancelNonExisting() { - runBlockingSimulation { + runSimulation { val scheduler = TimerScheduler(coroutineContext, clock) scheduler.cancel(1) @@ -65,7 +65,7 @@ internal class TimerSchedulerTest { @Test fun testCancelExisting() { - runBlockingSimulation { + runSimulation { val scheduler = TimerScheduler(coroutineContext, clock) scheduler.startSingleTimer(0, 1000) { @@ -82,7 +82,7 @@ internal class TimerSchedulerTest { @Test fun testCancelAll() { - runBlockingSimulation { + runSimulation { val scheduler = TimerScheduler(coroutineContext, clock) scheduler.startSingleTimer(0, 1000) { fail() } @@ -93,7 +93,7 @@ internal class TimerSchedulerTest { @Test fun testOverride() { - runBlockingSimulation { + runSimulation { val scheduler = TimerScheduler(coroutineContext, clock) scheduler.startSingleTimer(0, 1000) { fail() } @@ -107,7 +107,7 @@ internal class TimerSchedulerTest { @Test fun testOverrideBlock() { - runBlockingSimulation { + runSimulation { val scheduler = TimerScheduler(coroutineContext, clock) scheduler.startSingleTimer(0, 1000) { fail() } @@ -120,7 +120,7 @@ internal class TimerSchedulerTest { @Test fun testNegativeDelay() { - runBlockingSimulation { + runSimulation { val scheduler = TimerScheduler(coroutineContext, clock) assertThrows { diff --git a/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt b/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt index 6c251516..4f4008bc 100644 --- a/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt +++ b/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt @@ -40,7 +40,7 @@ import org.opendc.compute.service.scheduler.filters.RamFilter import org.opendc.compute.service.scheduler.filters.VCpuFilter import org.opendc.compute.service.scheduler.weights.RamWeigher import org.opendc.simulator.kotlin.SimulationCoroutineScope -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.util.* /** @@ -62,7 +62,7 @@ internal class ComputeServiceTest { } @Test - fun testClientClose() = scope.runBlockingSimulation { + fun testClientClose() = scope.runSimulation { val client = service.newClient() assertEquals(emptyList(), client.queryFlavors()) @@ -85,7 +85,7 @@ internal class ComputeServiceTest { } @Test - fun testClientCreate() = scope.runBlockingSimulation { + fun testClientCreate() = scope.runSimulation { val client = service.newClient() val flavor = client.newFlavor("test", 1, 1024) @@ -111,7 +111,7 @@ internal class ComputeServiceTest { } @Test - fun testClientOnClose() = scope.runBlockingSimulation { + fun testClientOnClose() = scope.runSimulation { service.close() assertThrows { service.newClient() @@ -119,7 +119,7 @@ internal class ComputeServiceTest { } @Test - fun testAddHost() = scope.runBlockingSimulation { + fun testAddHost() = scope.runSimulation { val host = mockk(relaxUnitFun = true) every { host.model } returns HostModel(4 * 2600.0, 4, 2048) @@ -139,7 +139,7 @@ internal class ComputeServiceTest { } @Test - fun testAddHostDouble() = scope.runBlockingSimulation { + fun testAddHostDouble() = scope.runSimulation { val host = mockk(relaxUnitFun = true) every { host.model } returns HostModel(4 * 2600.0, 4, 2048) @@ -154,7 +154,7 @@ internal class ComputeServiceTest { } @Test - fun testServerStartWithoutEnoughCpus() = scope.runBlockingSimulation { + fun testServerStartWithoutEnoughCpus() = scope.runSimulation { val client = service.newClient() val flavor = client.newFlavor("test", 1, 0) val image = client.newImage("test") @@ -167,7 +167,7 @@ internal class ComputeServiceTest { } @Test - fun testServerStartWithoutEnoughMemory() = scope.runBlockingSimulation { + fun testServerStartWithoutEnoughMemory() = scope.runSimulation { val client = service.newClient() val flavor = client.newFlavor("test", 0, 1024) val image = client.newImage("test") @@ -180,7 +180,7 @@ internal class ComputeServiceTest { } @Test - fun testServerStartWithoutEnoughResources() = scope.runBlockingSimulation { + fun testServerStartWithoutEnoughResources() = scope.runSimulation { val client = service.newClient() val flavor = client.newFlavor("test", 1, 1024) val image = client.newImage("test") @@ -193,7 +193,7 @@ internal class ComputeServiceTest { } @Test - fun testServerCancelRequest() = scope.runBlockingSimulation { + fun testServerCancelRequest() = scope.runSimulation { val client = service.newClient() val flavor = client.newFlavor("test", 1, 1024) val image = client.newImage("test") @@ -207,7 +207,7 @@ internal class ComputeServiceTest { } @Test - fun testServerCannotFitOnHost() = scope.runBlockingSimulation { + fun testServerCannotFitOnHost() = scope.runSimulation { val host = mockk(relaxUnitFun = true) every { host.model } returns HostModel(4 * 2600.0, 4, 2048) @@ -230,7 +230,7 @@ internal class ComputeServiceTest { } @Test - fun testHostAvailableAfterSomeTime() = scope.runBlockingSimulation { + fun testHostAvailableAfterSomeTime() = scope.runSimulation { val host = mockk(relaxUnitFun = true) val listeners = mutableListOf() @@ -261,7 +261,7 @@ internal class ComputeServiceTest { } @Test - fun testHostUnavailableAfterSomeTime() = scope.runBlockingSimulation { + fun testHostUnavailableAfterSomeTime() = scope.runSimulation { val host = mockk(relaxUnitFun = true) val listeners = mutableListOf() @@ -292,7 +292,7 @@ internal class ComputeServiceTest { } @Test - fun testServerInvalidType() = scope.runBlockingSimulation { + fun testServerInvalidType() = scope.runSimulation { val host = mockk(relaxUnitFun = true) val listeners = mutableListOf() @@ -315,7 +315,7 @@ internal class ComputeServiceTest { } @Test - fun testServerDeploy() = scope.runBlockingSimulation { + fun testServerDeploy() = scope.runSimulation { val host = mockk(relaxUnitFun = true) val listeners = mutableListOf() @@ -358,7 +358,7 @@ internal class ComputeServiceTest { } @Test - fun testServerDeployFailure() = scope.runBlockingSimulation { + fun testServerDeployFailure() = scope.runSimulation { val host = mockk(relaxUnitFun = true) val listeners = mutableListOf() diff --git a/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt b/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt index 0d44722b..9e59949f 100644 --- a/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt +++ b/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt @@ -34,7 +34,7 @@ import org.opendc.compute.service.internal.ComputeServiceImpl import org.opendc.compute.service.internal.InternalFlavor import org.opendc.compute.service.internal.InternalImage import org.opendc.compute.service.internal.InternalServer -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.util.* /** @@ -94,7 +94,7 @@ class InternalServerTest { } @Test - fun testStartTerminatedServer() = runBlockingSimulation { + fun testStartTerminatedServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -110,7 +110,7 @@ class InternalServerTest { } @Test - fun testStartDeletedServer() = runBlockingSimulation { + fun testStartDeletedServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -123,7 +123,7 @@ class InternalServerTest { } @Test - fun testStartProvisioningServer() = runBlockingSimulation { + fun testStartProvisioningServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -138,7 +138,7 @@ class InternalServerTest { } @Test - fun testStartRunningServer() = runBlockingSimulation { + fun testStartRunningServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -153,7 +153,7 @@ class InternalServerTest { } @Test - fun testStopProvisioningServer() = runBlockingSimulation { + fun testStopProvisioningServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -171,7 +171,7 @@ class InternalServerTest { } @Test - fun testStopTerminatedServer() = runBlockingSimulation { + fun testStopTerminatedServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -185,7 +185,7 @@ class InternalServerTest { } @Test - fun testStopDeletedServer() = runBlockingSimulation { + fun testStopDeletedServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -199,7 +199,7 @@ class InternalServerTest { } @Test - fun testStopRunningServer() = runBlockingSimulation { + fun testStopRunningServer() = runSimulation { val service = mockk() val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -216,7 +216,7 @@ class InternalServerTest { } @Test - fun testDeleteProvisioningServer() = runBlockingSimulation { + fun testDeleteProvisioningServer() = runSimulation { val service = mockk(relaxUnitFun = true) val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -235,7 +235,7 @@ class InternalServerTest { } @Test - fun testDeleteTerminatedServer() = runBlockingSimulation { + fun testDeleteTerminatedServer() = runSimulation { val service = mockk(relaxUnitFun = true) val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -251,7 +251,7 @@ class InternalServerTest { } @Test - fun testDeleteDeletedServer() = runBlockingSimulation { + fun testDeleteDeletedServer() = runSimulation { val service = mockk(relaxUnitFun = true) val uid = UUID.randomUUID() val flavor = mockFlavor() @@ -265,7 +265,7 @@ class InternalServerTest { } @Test - fun testDeleteRunningServer() = runBlockingSimulation { + fun testDeleteRunningServer() = runSimulation { val service = mockk(relaxUnitFun = true) val uid = UUID.randomUUID() val flavor = mockFlavor() diff --git a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt index 1634473e..f63d4c6f 100644 --- a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt +++ b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt @@ -43,7 +43,7 @@ import org.opendc.simulator.compute.workload.SimTraceFragment import org.opendc.simulator.compute.workload.SimTraceWorkload import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.mux.FlowMultiplexerFactory -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.time.Instant import java.util.* import kotlin.coroutines.resume @@ -68,7 +68,7 @@ internal class SimHostTest { * Test overcommitting of resources by the hypervisor. */ @Test - fun testOvercommitted() = runBlockingSimulation { + fun testOvercommitted() = runSimulation { val duration = 5 * 60L val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) @@ -152,7 +152,7 @@ internal class SimHostTest { * Test failure of the host. */ @Test - fun testFailure() = runBlockingSimulation { + fun testFailure() = runSimulation { val duration = 5 * 60L val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) diff --git a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/failure/HostFaultInjectorTest.kt b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/failure/HostFaultInjectorTest.kt index 5b71e716..90f534e6 100644 --- a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/failure/HostFaultInjectorTest.kt +++ b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/failure/HostFaultInjectorTest.kt @@ -29,7 +29,7 @@ import org.apache.commons.math3.distribution.LogNormalDistribution import org.apache.commons.math3.random.Well19937c import org.junit.jupiter.api.Test import org.opendc.compute.simulator.SimHost -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.time.Clock import java.time.Duration import kotlin.coroutines.CoroutineContext @@ -43,7 +43,7 @@ internal class HostFaultInjectorTest { * Simple test case to test that nothing happens when the injector is not started. */ @Test - fun testInjectorNotStarted() = runBlockingSimulation { + fun testInjectorNotStarted() = runSimulation { val host = mockk(relaxUnitFun = true) val injector = createSimpleInjector(coroutineContext, clock, setOf(host)) @@ -58,7 +58,7 @@ internal class HostFaultInjectorTest { * Simple test case to test a start stop fault where the machine is stopped and started after some time. */ @Test - fun testInjectorStopsMachine() = runBlockingSimulation { + fun testInjectorStopsMachine() = runSimulation { val host = mockk(relaxUnitFun = true) val injector = createSimpleInjector(coroutineContext, clock, setOf(host)) @@ -77,7 +77,7 @@ internal class HostFaultInjectorTest { * Simple test case to test a start stop fault where multiple machines are stopped. */ @Test - fun testInjectorStopsMultipleMachines() = runBlockingSimulation { + fun testInjectorStopsMultipleMachines() = runSimulation { val hosts = listOf( mockk(relaxUnitFun = true), mockk(relaxUnitFun = true) diff --git a/opendc-experiments/opendc-experiments-capelin/src/jmh/kotlin/org/opendc/experiments/capelin/CapelinBenchmarks.kt b/opendc-experiments/opendc-experiments-capelin/src/jmh/kotlin/org/opendc/experiments/capelin/CapelinBenchmarks.kt index ea3d9b0d..ef3deeb2 100644 --- a/opendc-experiments/opendc-experiments-capelin/src/jmh/kotlin/org/opendc/experiments/capelin/CapelinBenchmarks.kt +++ b/opendc-experiments/opendc-experiments-capelin/src/jmh/kotlin/org/opendc/experiments/capelin/CapelinBenchmarks.kt @@ -32,7 +32,7 @@ import org.opendc.experiments.capelin.topology.clusterTopology import org.opendc.experiments.compute.* import org.opendc.experiments.compute.topology.HostSpec import org.opendc.experiments.provisioner.Provisioner -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import org.openjdk.jmh.annotations.* import java.io.File import java.util.* @@ -60,7 +60,7 @@ class CapelinBenchmarks { } @Benchmark - fun benchmarkCapelin() = runBlockingSimulation { + fun benchmarkCapelin() = runSimulation { val serviceDomain = "compute.opendc.org" Provisioner(coroutineContext, clock, seed = 0).use { provisioner -> diff --git a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt index 669fd3b1..7461038d 100644 --- a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt +++ b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt @@ -28,7 +28,7 @@ import org.opendc.experiments.capelin.topology.clusterTopology import org.opendc.experiments.compute.* import org.opendc.experiments.compute.export.parquet.ParquetComputeMonitor import org.opendc.experiments.provisioner.Provisioner -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.io.File import java.time.Duration import java.util.* @@ -54,7 +54,7 @@ public class CapelinRunner( /** * Run a single [scenario] with the specified seed. */ - fun runScenario(scenario: Scenario, seed: Long) = runBlockingSimulation { + fun runScenario(scenario: Scenario, seed: Long) = runSimulation { val serviceDomain = "compute.opendc.org" val topology = clusterTopology(File(envPath, "${scenario.topology.name}.txt")) diff --git a/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt b/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt index 3214a0bd..238a5f87 100644 --- a/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt +++ b/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt @@ -39,7 +39,7 @@ import org.opendc.experiments.compute.telemetry.table.HostTableReader import org.opendc.experiments.compute.telemetry.table.ServiceTableReader import org.opendc.experiments.compute.topology.HostSpec import org.opendc.experiments.provisioner.Provisioner -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.io.File import java.time.Duration import java.util.* @@ -80,7 +80,7 @@ class CapelinIntegrationTest { * Test a large simulation setup. */ @Test - fun testLarge() = runBlockingSimulation { + fun testLarge() = runSimulation { val seed = 0L val workload = createTestWorkload(1.0, seed) val topology = createTopology() @@ -124,7 +124,7 @@ class CapelinIntegrationTest { * Test a small simulation setup. */ @Test - fun testSmall() = runBlockingSimulation { + fun testSmall() = runSimulation { val seed = 1L val workload = createTestWorkload(0.25, seed) val topology = createTopology("single") @@ -164,7 +164,7 @@ class CapelinIntegrationTest { * Test a small simulation setup with interference. */ @Test - fun testInterference() = runBlockingSimulation { + fun testInterference() = runSimulation { val seed = 0L val workload = createTestWorkload(1.0, seed) val topology = createTopology("single") @@ -202,7 +202,7 @@ class CapelinIntegrationTest { * Test a small simulation setup with failures. */ @Test - fun testFailures() = runBlockingSimulation { + fun testFailures() = runSimulation { val seed = 0L val topology = createTopology("single") val workload = createTestWorkload(0.25, seed) diff --git a/opendc-experiments/opendc-experiments-faas/src/test/kotlin/org/opendc/experiments/faas/FaaSExperiment.kt b/opendc-experiments/opendc-experiments-faas/src/test/kotlin/org/opendc/experiments/faas/FaaSExperiment.kt index c558a3e3..6f212825 100644 --- a/opendc-experiments/opendc-experiments-faas/src/test/kotlin/org/opendc/experiments/faas/FaaSExperiment.kt +++ b/opendc-experiments/opendc-experiments-faas/src/test/kotlin/org/opendc/experiments/faas/FaaSExperiment.kt @@ -34,7 +34,7 @@ import org.opendc.simulator.compute.model.MachineModel import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.io.File import java.time.Duration @@ -46,7 +46,7 @@ class FaaSExperiment { * Smoke test that simulates a small trace. */ @Test - fun testSmoke() = runBlockingSimulation { + fun testSmoke() = runSimulation { val faasService = "faas.opendc.org" Provisioner(coroutineContext, clock, seed = 0L).use { provisioner -> diff --git a/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/TensorFlowTest.kt b/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/TensorFlowTest.kt index 119ead46..eee8b730 100644 --- a/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/TensorFlowTest.kt +++ b/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/TensorFlowTest.kt @@ -30,7 +30,7 @@ import org.opendc.experiments.tf20.distribute.MirroredStrategy import org.opendc.experiments.tf20.distribute.OneDeviceStrategy import org.opendc.experiments.tf20.util.MLEnvironmentReader import org.opendc.simulator.compute.power.LinearPowerModel -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.util.* /** @@ -41,7 +41,7 @@ class TensorFlowTest { * Smoke test that tests the capabilities of the TensorFlow application model in OpenDC. */ @Test - fun testSmokeAlexNet() = runBlockingSimulation { + fun testSmokeAlexNet() = runSimulation { val envInput = checkNotNull(TensorFlowTest::class.java.getResourceAsStream("/kth.json")) val def = MLEnvironmentReader().readEnvironment(envInput).first() @@ -71,7 +71,7 @@ class TensorFlowTest { * Smoke test that tests the capabilities of the TensorFlow application model in OpenDC. */ @Test - fun testSmokeVGG() = runBlockingSimulation { + fun testSmokeVGG() = runSimulation { val envInput = checkNotNull(TensorFlowTest::class.java.getResourceAsStream("/kth.json")) val def = MLEnvironmentReader().readEnvironment(envInput).first() @@ -101,7 +101,7 @@ class TensorFlowTest { * Smoke test that tests the capabilities of the TensorFlow application model in OpenDC. */ @Test - fun testSmokeDistribute() = runBlockingSimulation { + fun testSmokeDistribute() = runSimulation { val envInput = checkNotNull(TensorFlowTest::class.java.getResourceAsStream("/kth.json")) val def = MLEnvironmentReader().readEnvironment(envInput).first() diff --git a/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/core/SimTFDeviceTest.kt b/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/core/SimTFDeviceTest.kt index bc561721..966ca5ef 100644 --- a/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/core/SimTFDeviceTest.kt +++ b/opendc-experiments/opendc-experiments-tf20/src/test/kotlin/org/opendc/experiments/tf20/core/SimTFDeviceTest.kt @@ -31,7 +31,7 @@ import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit import org.opendc.simulator.compute.power.LinearPowerModel -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.util.* /** @@ -39,7 +39,7 @@ import java.util.* */ internal class SimTFDeviceTest { @Test - fun testSmoke() = runBlockingSimulation { + fun testSmoke() = runSimulation { val puNode = ProcessingNode("NVIDIA", "Tesla V100", "unknown", 1) val pu = ProcessingUnit(puNode, 0, 960 * 1230.0) val memory = MemoryUnit("NVIDIA", "Tesla V100", 877.0, 32_000) diff --git a/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt b/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt index dc296c20..28234cf4 100644 --- a/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt +++ b/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt @@ -31,7 +31,7 @@ import org.opendc.faas.api.FaaSFunction import org.opendc.faas.service.deployer.FunctionDeployer import org.opendc.faas.service.deployer.FunctionInstance import org.opendc.faas.service.deployer.FunctionInstanceState -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.util.* /** @@ -40,7 +40,7 @@ import java.util.* internal class FaaSServiceTest { @Test - fun testClientState() = runBlockingSimulation { + fun testClientState() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = assertDoesNotThrow { service.newClient() } @@ -54,7 +54,7 @@ internal class FaaSServiceTest { } @Test - fun testClientInvokeUnknown() = runBlockingSimulation { + fun testClientInvokeUnknown() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -63,7 +63,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionCreation() = runBlockingSimulation { + fun testClientFunctionCreation() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -74,7 +74,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionQuery() = runBlockingSimulation { + fun testClientFunctionQuery() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -87,7 +87,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionFindById() = runBlockingSimulation { + fun testClientFunctionFindById() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -100,7 +100,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionFindByName() = runBlockingSimulation { + fun testClientFunctionFindByName() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -113,7 +113,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionDuplicateName() = runBlockingSimulation { + fun testClientFunctionDuplicateName() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -124,7 +124,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionDelete() = runBlockingSimulation { + fun testClientFunctionDelete() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -138,7 +138,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionCannotInvokeDeleted() = runBlockingSimulation { + fun testClientFunctionCannotInvokeDeleted() = runSimulation { val service = FaaSService(coroutineContext, clock, mockk(), mockk(), mockk()) val client = service.newClient() @@ -150,7 +150,7 @@ internal class FaaSServiceTest { } @Test - fun testClientFunctionInvoke() = runBlockingSimulation { + fun testClientFunctionInvoke() = runSimulation { val deployer = mockk() val service = FaaSService(coroutineContext, clock, deployer, mockk(), mockk(relaxUnitFun = true)) diff --git a/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt b/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt index 0f3bb87f..317eb0aa 100644 --- a/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt +++ b/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt @@ -42,7 +42,7 @@ import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit import org.opendc.simulator.compute.workload.SimRuntimeWorkload import org.opendc.simulator.compute.workload.SimWorkload -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.time.Duration import java.util.* @@ -64,7 +64,7 @@ internal class SimFaaSServiceTest { } @Test - fun testSmoke() = runBlockingSimulation { + fun testSmoke() = runSimulation { val random = Random(0) val workload = spyk(object : SimFaaSWorkload, SimWorkload by SimRuntimeWorkload(1000) { override suspend fun invoke() { diff --git a/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt b/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt index a2dc9a0f..b319a677 100644 --- a/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt +++ b/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt @@ -35,7 +35,7 @@ import org.opendc.simulator.compute.workload.SimTrace import org.opendc.simulator.compute.workload.SimTraceWorkload import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.mux.FlowMultiplexerFactory -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import org.openjdk.jmh.annotations.* import java.util.SplittableRandom import java.util.concurrent.ThreadLocalRandom @@ -70,18 +70,18 @@ class SimMachineBenchmarks { @Benchmark fun benchmarkBareMetal() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine( engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0)) ) - return@runBlockingSimulation machine.runWorkload(SimTraceWorkload(trace)) + return@runSimulation machine.runWorkload(SimTraceWorkload(trace)) } } @Benchmark fun benchmarkSpaceSharedHypervisor() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) val hypervisor = SimHypervisor(engine, FlowMultiplexerFactory.forwardingMultiplexer(), SplittableRandom(1), null) @@ -91,7 +91,7 @@ class SimMachineBenchmarks { val vm = hypervisor.newMachine(machineModel) try { - return@runBlockingSimulation vm.runWorkload(SimTraceWorkload(trace)) + return@runSimulation vm.runWorkload(SimTraceWorkload(trace)) } finally { vm.cancel() machine.cancel() @@ -101,7 +101,7 @@ class SimMachineBenchmarks { @Benchmark fun benchmarkFairShareHypervisorSingle() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) val hypervisor = SimHypervisor(engine, FlowMultiplexerFactory.maxMinMultiplexer(), SplittableRandom(1), null) @@ -111,7 +111,7 @@ class SimMachineBenchmarks { val vm = hypervisor.newMachine(machineModel) try { - return@runBlockingSimulation vm.runWorkload(SimTraceWorkload(trace)) + return@runSimulation vm.runWorkload(SimTraceWorkload(trace)) } finally { vm.cancel() machine.cancel() @@ -121,7 +121,7 @@ class SimMachineBenchmarks { @Benchmark fun benchmarkFairShareHypervisorDouble() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) val hypervisor = SimHypervisor(engine, FlowMultiplexerFactory.maxMinMultiplexer(), SplittableRandom(1), null) diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt index b0175917..b7af6803 100644 --- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt +++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt @@ -35,7 +35,7 @@ import org.opendc.simulator.compute.workload.SimWorkload import org.opendc.simulator.compute.workload.SimWorkloadLifecycle import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.source.FixedFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import org.opendc.simulator.network.SimNetworkSink import org.opendc.simulator.power.SimPowerSource @@ -58,7 +58,7 @@ class SimMachineTest { } @Test - fun testFlopsWorkload() = runBlockingSimulation { + fun testFlopsWorkload() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -72,7 +72,7 @@ class SimMachineTest { } @Test - fun testDualSocketMachine() = runBlockingSimulation { + fun testDualSocketMachine() = runSimulation { val cpuNode = machineModel.cpus[0].node val machineModel = MachineModel( cpus = List(cpuNode.coreCount * 2) { ProcessingUnit(cpuNode, it % 2, 1000.0) }, @@ -91,7 +91,7 @@ class SimMachineTest { } @Test - fun testPower() = runBlockingSimulation { + fun testPower() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine( engine, @@ -111,7 +111,7 @@ class SimMachineTest { } @Test - fun testCapacityClamp() = runBlockingSimulation { + fun testCapacityClamp() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -135,7 +135,7 @@ class SimMachineTest { } @Test - fun testMemory() = runBlockingSimulation { + fun testMemory() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -153,7 +153,7 @@ class SimMachineTest { } @Test - fun testMemoryUsage() = runBlockingSimulation { + fun testMemoryUsage() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -173,7 +173,7 @@ class SimMachineTest { } @Test - fun testNetUsage() = runBlockingSimulation { + fun testNetUsage() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine( engine, @@ -198,7 +198,7 @@ class SimMachineTest { } @Test - fun testDiskReadUsage() = runBlockingSimulation { + fun testDiskReadUsage() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine( engine, @@ -220,7 +220,7 @@ class SimMachineTest { } @Test - fun testDiskWriteUsage() = runBlockingSimulation { + fun testDiskWriteUsage() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine( engine, @@ -242,7 +242,7 @@ class SimMachineTest { } @Test - fun testCancellation() = runBlockingSimulation { + fun testCancellation() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -262,7 +262,7 @@ class SimMachineTest { } @Test - fun testConcurrentRuns() = runBlockingSimulation { + fun testConcurrentRuns() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt index 82ceeecd..5481cad2 100644 --- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt +++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt @@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.opendc.simulator.compute.power.PowerDriver import org.opendc.simulator.flow.FlowEngine -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import org.opendc.simulator.power.SimPowerSource /** @@ -51,7 +51,7 @@ internal class SimPsuTest { } @Test - fun testPsuIdle() = runBlockingSimulation { + fun testPsuIdle() = runSimulation { val ratedOutputPower = 240.0 val energyEfficiency = mapOf(0.0 to 1.0) @@ -69,7 +69,7 @@ internal class SimPsuTest { } @Test - fun testPsuPowerLoss() = runBlockingSimulation { + fun testPsuPowerLoss() = runSimulation { val ratedOutputPower = 240.0 // Efficiency of 80 Plus Titanium PSU val energyEfficiency = sortedMapOf( diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt index 35e14864..aae8d139 100644 --- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt +++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt @@ -43,7 +43,7 @@ import org.opendc.simulator.compute.workload.SimTraceFragment import org.opendc.simulator.compute.workload.SimTraceWorkload import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.mux.FlowMultiplexerFactory -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.util.* /** @@ -65,7 +65,7 @@ internal class SimFairShareHypervisorTest { * Test overcommitting of resources via the hypervisor with a single VM. */ @Test - fun testOvercommittedSingle() = runBlockingSimulation { + fun testOvercommittedSingle() = runSimulation { val duration = 5 * 60L val workloadA = SimTraceWorkload( @@ -105,7 +105,7 @@ internal class SimFairShareHypervisorTest { * Test overcommitting of resources via the hypervisor with two VMs. */ @Test - fun testOvercommittedDual() = runBlockingSimulation { + fun testOvercommittedDual() = runSimulation { val duration = 5 * 60L val workloadA = SimTraceWorkload( @@ -158,7 +158,7 @@ internal class SimFairShareHypervisorTest { } @Test - fun testMultipleCPUs() = runBlockingSimulation { + fun testMultipleCPUs() = runSimulation { val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2) val model = MachineModel( cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) }, @@ -179,7 +179,7 @@ internal class SimFairShareHypervisorTest { } @Test - fun testInterference() = runBlockingSimulation { + fun testInterference() = runSimulation { val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2) val model = MachineModel( cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) }, diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt index 96eabf5c..664bb2da 100644 --- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt +++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt @@ -39,7 +39,7 @@ import org.opendc.simulator.compute.runWorkload import org.opendc.simulator.compute.workload.* import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.mux.FlowMultiplexerFactory -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import java.util.* /** @@ -61,7 +61,7 @@ internal class SimSpaceSharedHypervisorTest { * Test a trace workload. */ @Test - fun testTrace() = runBlockingSimulation { + fun testTrace() = runSimulation { val duration = 5 * 60L val workloadA = SimTraceWorkload( @@ -92,7 +92,7 @@ internal class SimSpaceSharedHypervisorTest { * Test runtime workload on hypervisor. */ @Test - fun testRuntimeWorkload() = runBlockingSimulation { + fun testRuntimeWorkload() = runSimulation { val duration = 5 * 60L * 1000 val workload = SimRuntimeWorkload(duration) val engine = FlowEngine(coroutineContext, clock) @@ -114,7 +114,7 @@ internal class SimSpaceSharedHypervisorTest { * Test FLOPs workload on hypervisor. */ @Test - fun testFlopsWorkload() = runBlockingSimulation { + fun testFlopsWorkload() = runSimulation { val duration = 5 * 60L * 1000 val workload = SimFlopsWorkload((duration * 3.2).toLong(), 1.0) val engine = FlowEngine(coroutineContext, clock) @@ -134,7 +134,7 @@ internal class SimSpaceSharedHypervisorTest { * Test two workloads running sequentially. */ @Test - fun testTwoWorkloads() = runBlockingSimulation { + fun testTwoWorkloads() = runSimulation { val duration = 5 * 60L * 1000 val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) @@ -162,7 +162,7 @@ internal class SimSpaceSharedHypervisorTest { * Test concurrent workloads on the machine. */ @Test - fun testConcurrentWorkloadFails() = runBlockingSimulation { + fun testConcurrentWorkloadFails() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) val hypervisor = SimHypervisor(engine, FlowMultiplexerFactory.forwardingMultiplexer(), SplittableRandom(1), null) @@ -184,7 +184,7 @@ internal class SimSpaceSharedHypervisorTest { * Test concurrent workloads on the machine. */ @Test - fun testConcurrentWorkloadSucceeds() = runBlockingSimulation { + fun testConcurrentWorkloadSucceeds() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0))) val hypervisor = SimHypervisor(engine, FlowMultiplexerFactory.forwardingMultiplexer(), SplittableRandom(1), null) diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt index bf4e7622..70aea3f4 100644 --- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt +++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt @@ -32,7 +32,7 @@ import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.power.SimplePowerDriver import org.opendc.simulator.compute.runWorkload import org.opendc.simulator.flow.FlowEngine -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * Test suite for the [SimTraceWorkloadTest] class. @@ -51,7 +51,7 @@ class SimTraceWorkloadTest { } @Test - fun testSmoke() = runBlockingSimulation { + fun testSmoke() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -74,7 +74,7 @@ class SimTraceWorkloadTest { } @Test - fun testOffset() = runBlockingSimulation { + fun testOffset() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -97,7 +97,7 @@ class SimTraceWorkloadTest { } @Test - fun testSkipFragment() = runBlockingSimulation { + fun testSkipFragment() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, @@ -121,7 +121,7 @@ class SimTraceWorkloadTest { } @Test - fun testZeroCores() = runBlockingSimulation { + fun testZeroCores() = runSimulation { val machine = SimBareMetalMachine( FlowEngine(coroutineContext, clock), machineModel, 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 a291b4e2..c4cc0171 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 @@ -29,10 +29,32 @@ import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext /** - * Executes a [body] inside an immediate execution dispatcher. + * Executes [body] as a simulation in a new coroutine. + * + * This function behaves similarly to [runBlocking], with the difference that the code that it runs will skip delays. + * This allows to use [delay] in without causing the simulation to take more time than necessary. + * + * ``` + * @Test + * fun exampleSimulation() = runSimulation { + * val deferred = async { + * delay(1_000) + * async { + * delay(1_000) + * }.await() + * } + * + * deferred.await() // result available immediately + * } + * ``` + * + * The simulation is run in a single thread, unless other [CoroutineDispatcher] are used for child coroutines. + * Because of this, child coroutines are not executed in parallel to [body]. + * In order for the spawned-off asynchronous code to actually be executed, one must either [yield] or suspend the + * body some other way, or use commands that control scheduling (see [SimulationScheduler]). */ @OptIn(ExperimentalCoroutinesApi::class) -public fun runBlockingSimulation( +public fun runSimulation( context: CoroutineContext = EmptyCoroutineContext, scheduler: SimulationScheduler = SimulationScheduler(), body: suspend SimulationCoroutineScope.() -> Unit @@ -54,16 +76,16 @@ public fun runBlockingSimulation( } /** - * Convenience method for calling [runBlockingSimulation] on an existing [SimulationCoroutineScope]. + * Convenience method for calling [runSimulation] on an existing [SimulationCoroutineScope]. */ -public fun SimulationCoroutineScope.runBlockingSimulation(block: suspend SimulationCoroutineScope.() -> Unit): Unit = - runBlockingSimulation(coroutineContext, scheduler, block) +public fun SimulationCoroutineScope.runSimulation(block: suspend SimulationCoroutineScope.() -> Unit): Unit = + runSimulation(coroutineContext, scheduler, block) /** - * Convenience method for calling [runBlockingSimulation] on an existing [SimulationCoroutineDispatcher]. + * Convenience method for calling [runSimulation] on an existing [SimulationCoroutineDispatcher]. */ -public fun SimulationCoroutineDispatcher.runBlockingSimulation(block: suspend SimulationCoroutineScope.() -> Unit): Unit = - runBlockingSimulation(this, scheduler, block) +public fun SimulationCoroutineDispatcher.runSimulation(block: suspend SimulationCoroutineScope.() -> Unit): Unit = + runSimulation(this, scheduler, block) private fun CoroutineContext.checkArguments(scheduler: SimulationScheduler): Pair { val dispatcher = get(ContinuationInterceptor).run { diff --git a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt b/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt index e3cde1d2..86fbe8e4 100644 --- a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt +++ b/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt @@ -27,7 +27,7 @@ import kotlinx.coroutines.launch import org.opendc.simulator.flow.mux.ForwardingFlowMultiplexer import org.opendc.simulator.flow.mux.MaxMinFlowMultiplexer import org.opendc.simulator.flow.source.TraceFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import org.openjdk.jmh.annotations.* import java.util.concurrent.ThreadLocalRandom import java.util.concurrent.TimeUnit @@ -49,27 +49,27 @@ class FlowBenchmarks { @Benchmark fun benchmarkSink() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val provider = FlowSink(engine, 4200.0) - return@runBlockingSimulation provider.consume(TraceFlowSource(trace)) + return@runSimulation provider.consume(TraceFlowSource(trace)) } } @Benchmark fun benchmarkForward() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val provider = FlowSink(engine, 4200.0) val forwarder = FlowForwarder(engine) provider.startConsumer(forwarder) - return@runBlockingSimulation forwarder.consume(TraceFlowSource(trace)) + return@runSimulation forwarder.consume(TraceFlowSource(trace)) } } @Benchmark fun benchmarkMuxMaxMinSingleSource() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val switch = MaxMinFlowMultiplexer(engine) @@ -77,13 +77,13 @@ class FlowBenchmarks { FlowSink(engine, 3000.0).startConsumer(switch.newOutput()) val provider = switch.newInput() - return@runBlockingSimulation provider.consume(TraceFlowSource(trace)) + return@runSimulation provider.consume(TraceFlowSource(trace)) } } @Benchmark fun benchmarkMuxMaxMinTripleSource() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val switch = MaxMinFlowMultiplexer(engine) @@ -101,7 +101,7 @@ class FlowBenchmarks { @Benchmark fun benchmarkMuxExclusiveSingleSource() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val switch = ForwardingFlowMultiplexer(engine) @@ -109,13 +109,13 @@ class FlowBenchmarks { FlowSink(engine, 3000.0).startConsumer(switch.newOutput()) val provider = switch.newInput() - return@runBlockingSimulation provider.consume(TraceFlowSource(trace)) + return@runSimulation provider.consume(TraceFlowSource(trace)) } } @Benchmark fun benchmarkMuxExclusiveTripleSource() { - return runBlockingSimulation { + return runSimulation { val engine = FlowEngine(coroutineContext, clock) val switch = ForwardingFlowMultiplexer(engine) diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt index 220b247f..d782d036 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt @@ -26,14 +26,14 @@ import io.mockk.* import org.junit.jupiter.api.* import org.opendc.simulator.flow.internal.FlowConsumerContextImpl import org.opendc.simulator.flow.internal.FlowEngineImpl -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * A test suite for the [FlowConsumerContextImpl] class. */ class FlowConsumerContextTest { @Test - fun testFlushWithoutCommand() = runBlockingSimulation { + fun testFlushWithoutCommand() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val consumer = object : FlowSource { override fun onPull(conn: FlowConnection, now: Long): Long { @@ -54,7 +54,7 @@ class FlowConsumerContextTest { } @Test - fun testDoubleStart() = runBlockingSimulation { + fun testDoubleStart() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val consumer = object : FlowSource { override fun onPull(conn: FlowConnection, now: Long): Long { @@ -79,7 +79,7 @@ class FlowConsumerContextTest { } @Test - fun testIdempotentCapacityChange() = runBlockingSimulation { + fun testIdempotentCapacityChange() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val consumer = spyk(object : FlowSource { override fun onPull(conn: FlowConnection, now: Long): Long { diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt index cd183ae2..2025dd52 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt @@ -30,14 +30,14 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.opendc.simulator.flow.internal.FlowEngineImpl import org.opendc.simulator.flow.source.FixedFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * A test suite for the [FlowForwarder] class. */ internal class FlowForwarderTest { @Test - fun testCancelImmediately() = runBlockingSimulation { + fun testCancelImmediately() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val source = FlowSink(engine, 2000.0) @@ -56,7 +56,7 @@ internal class FlowForwarderTest { } @Test - fun testCancel() = runBlockingSimulation { + fun testCancel() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val source = FlowSink(engine, 2000.0) @@ -83,7 +83,7 @@ internal class FlowForwarderTest { } @Test - fun testState() = runBlockingSimulation { + fun testState() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val consumer = object : FlowSource { @@ -108,7 +108,7 @@ internal class FlowForwarderTest { } @Test - fun testCancelPendingDelegate() = runBlockingSimulation { + fun testCancelPendingDelegate() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) @@ -126,7 +126,7 @@ internal class FlowForwarderTest { } @Test - fun testCancelStartedDelegate() = runBlockingSimulation { + fun testCancelStartedDelegate() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val source = FlowSink(engine, 2000.0) @@ -144,7 +144,7 @@ internal class FlowForwarderTest { } @Test - fun testCancelPropagation() = runBlockingSimulation { + fun testCancelPropagation() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val source = FlowSink(engine, 2000.0) @@ -162,7 +162,7 @@ internal class FlowForwarderTest { } @Test - fun testExitPropagation() = runBlockingSimulation { + fun testExitPropagation() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine, isCoupled = true) val source = FlowSink(engine, 2000.0) @@ -183,7 +183,7 @@ internal class FlowForwarderTest { @Test @Disabled // Due to Kotlin bug: https://github.com/mockk/mockk/issues/368 - fun testAdjustCapacity() = runBlockingSimulation { + fun testAdjustCapacity() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val sink = FlowSink(engine, 1.0) @@ -202,7 +202,7 @@ internal class FlowForwarderTest { } @Test - fun testCounters() = runBlockingSimulation { + fun testCounters() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val source = FlowSink(engine, 1.0) @@ -224,7 +224,7 @@ internal class FlowForwarderTest { } @Test - fun testCoupledExit() = runBlockingSimulation { + fun testCoupledExit() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine, isCoupled = true) val source = FlowSink(engine, 2000.0) @@ -239,7 +239,7 @@ internal class FlowForwarderTest { } @Test - fun testPullFailureCoupled() = runBlockingSimulation { + fun testPullFailureCoupled() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine, isCoupled = true) val source = FlowSink(engine, 2000.0) @@ -262,7 +262,7 @@ internal class FlowForwarderTest { } @Test - fun testStartFailure() = runBlockingSimulation { + fun testStartFailure() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val source = FlowSink(engine, 2000.0) @@ -290,7 +290,7 @@ internal class FlowForwarderTest { } @Test - fun testConvergeFailure() = runBlockingSimulation { + fun testConvergeFailure() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val forwarder = FlowForwarder(engine) val source = FlowSink(engine, 2000.0) diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt index 95cb8123..22a84edb 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt @@ -30,14 +30,14 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.opendc.simulator.flow.internal.FlowEngineImpl import org.opendc.simulator.flow.source.FixedFlowSource import org.opendc.simulator.flow.source.FlowSourceRateAdapter -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * A test suite for the [FlowSink] class. */ internal class FlowSinkTest { @Test - fun testSpeed() = runBlockingSimulation { + fun testSpeed() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -53,7 +53,7 @@ internal class FlowSinkTest { } @Test - fun testAdjustCapacity() = runBlockingSimulation { + fun testAdjustCapacity() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val provider = FlowSink(engine, 1.0) @@ -69,7 +69,7 @@ internal class FlowSinkTest { } @Test - fun testSpeedLimit() = runBlockingSimulation { + fun testSpeedLimit() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -89,7 +89,7 @@ internal class FlowSinkTest { * [FlowSource.onPull]. */ @Test - fun testIntermediateInterrupt() = runBlockingSimulation { + fun testIntermediateInterrupt() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -109,7 +109,7 @@ internal class FlowSinkTest { } @Test - fun testInterrupt() = runBlockingSimulation { + fun testInterrupt() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -144,7 +144,7 @@ internal class FlowSinkTest { } @Test - fun testFailure() = runBlockingSimulation { + fun testFailure() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -165,7 +165,7 @@ internal class FlowSinkTest { } @Test - fun testExceptionPropagationOnNext() = runBlockingSimulation { + fun testExceptionPropagationOnNext() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -190,7 +190,7 @@ internal class FlowSinkTest { } @Test - fun testConcurrentConsumption() = runBlockingSimulation { + fun testConcurrentConsumption() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -206,7 +206,7 @@ internal class FlowSinkTest { } @Test - fun testCancelDuringConsumption() = runBlockingSimulation { + fun testCancelDuringConsumption() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) @@ -225,7 +225,7 @@ internal class FlowSinkTest { @Test fun testInfiniteSleep() { assertThrows { - runBlockingSimulation { + runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val capacity = 4200.0 val provider = FlowSink(engine, capacity) diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt index 523dac3a..cfd2bdf0 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt @@ -32,7 +32,7 @@ import org.opendc.simulator.flow.internal.FlowEngineImpl import org.opendc.simulator.flow.source.FixedFlowSource import org.opendc.simulator.flow.source.FlowSourceRateAdapter import org.opendc.simulator.flow.source.TraceFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * Test suite for the [ForwardingFlowMultiplexer] class. @@ -42,7 +42,7 @@ internal class ForwardingFlowMultiplexerTest { * Test a trace workload. */ @Test - fun testTrace() = runBlockingSimulation { + fun testTrace() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val speed = mutableListOf() @@ -79,7 +79,7 @@ internal class ForwardingFlowMultiplexerTest { * Test runtime workload on hypervisor. */ @Test - fun testRuntimeWorkload() = runBlockingSimulation { + fun testRuntimeWorkload() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val duration = 5 * 60L * 1000 @@ -101,7 +101,7 @@ internal class ForwardingFlowMultiplexerTest { * Test two workloads running sequentially. */ @Test - fun testTwoWorkloads() = runBlockingSimulation { + fun testTwoWorkloads() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val duration = 5 * 60L * 1000 @@ -140,7 +140,7 @@ internal class ForwardingFlowMultiplexerTest { * Test concurrent workloads on the machine. */ @Test - fun testConcurrentWorkloadFails() = runBlockingSimulation { + fun testConcurrentWorkloadFails() = runSimulation { val engine = FlowEngineImpl(coroutineContext, clock) val switch = ForwardingFlowMultiplexer(engine) diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt index adfc265a..4e242292 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt @@ -32,14 +32,14 @@ import org.opendc.simulator.flow.consume import org.opendc.simulator.flow.internal.FlowEngineImpl import org.opendc.simulator.flow.source.FixedFlowSource import org.opendc.simulator.flow.source.TraceFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * Test suite for the [FlowMultiplexer] implementations */ internal class MaxMinFlowMultiplexerTest { @Test - fun testSmoke() = runBlockingSimulation { + fun testSmoke() = runSimulation { val scheduler = FlowEngineImpl(coroutineContext, clock) val switch = MaxMinFlowMultiplexer(scheduler) @@ -61,7 +61,7 @@ internal class MaxMinFlowMultiplexerTest { * Test overcommitting of resources via the hypervisor with a single VM. */ @Test - fun testOvercommittedSingle() = runBlockingSimulation { + fun testOvercommittedSingle() = runSimulation { val scheduler = FlowEngineImpl(coroutineContext, clock) val duration = 5 * 60L @@ -99,7 +99,7 @@ internal class MaxMinFlowMultiplexerTest { * Test overcommitting of resources via the hypervisor with two VMs. */ @Test - fun testOvercommittedDual() = runBlockingSimulation { + fun testOvercommittedDual() = runSimulation { val scheduler = FlowEngineImpl(coroutineContext, clock) val duration = 5 * 60L diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/source/FixedFlowSourceTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/source/FixedFlowSourceTest.kt index 99630d32..552579ff 100644 --- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/source/FixedFlowSourceTest.kt +++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/source/FixedFlowSourceTest.kt @@ -27,14 +27,14 @@ import org.junit.jupiter.api.Test import org.opendc.simulator.flow.FlowSink import org.opendc.simulator.flow.consume import org.opendc.simulator.flow.internal.FlowEngineImpl -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * A test suite for the [FixedFlowSource] class. */ internal class FixedFlowSourceTest { @Test - fun testSmoke() = runBlockingSimulation { + fun testSmoke() = runSimulation { val scheduler = FlowEngineImpl(coroutineContext, clock) val provider = FlowSink(scheduler, 1.0) @@ -45,7 +45,7 @@ internal class FixedFlowSourceTest { } @Test - fun testUtilization() = runBlockingSimulation { + fun testUtilization() = runSimulation { val scheduler = FlowEngineImpl(coroutineContext, clock) val provider = FlowSink(scheduler, 1.0) 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 8e95f2b0..944c4d6a 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 @@ -32,14 +32,14 @@ import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertThrows import org.opendc.simulator.flow.* import org.opendc.simulator.flow.source.FixedFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * Test suite for the [SimNetworkSink] class. */ class SimNetworkSinkTest { @Test - fun testInitialState() = runBlockingSimulation { + fun testInitialState() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) @@ -49,7 +49,7 @@ class SimNetworkSinkTest { } @Test - fun testDisconnectIdempotent() = runBlockingSimulation { + fun testDisconnectIdempotent() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) @@ -58,7 +58,7 @@ class SimNetworkSinkTest { } @Test - fun testConnectCircular() = runBlockingSimulation { + fun testConnectCircular() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) @@ -68,7 +68,7 @@ class SimNetworkSinkTest { } @Test - fun testConnectAlreadyConnectedTarget() = runBlockingSimulation { + fun testConnectAlreadyConnectedTarget() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) val source = mockk(relaxUnitFun = true) @@ -80,7 +80,7 @@ class SimNetworkSinkTest { } @Test - fun testConnectAlreadyConnected() = runBlockingSimulation { + fun testConnectAlreadyConnected() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) val source1 = Source(engine) @@ -96,7 +96,7 @@ class SimNetworkSinkTest { } @Test - fun testConnect() = runBlockingSimulation { + fun testConnect() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) val source = spyk(Source(engine)) @@ -112,7 +112,7 @@ class SimNetworkSinkTest { } @Test - fun testDisconnect() = runBlockingSimulation { + fun testDisconnect() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) val source = spyk(Source(engine)) 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 b45b150d..ff6cb66e 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 @@ -29,14 +29,14 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.opendc.simulator.flow.* import org.opendc.simulator.flow.source.FixedFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation /** * Test suite for the [SimNetworkSwitchVirtual] class. */ class SimNetworkSwitchVirtualTest { @Test - fun testConnect() = runBlockingSimulation { + fun testConnect() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) val source = spyk(Source(engine)) @@ -54,7 +54,7 @@ class SimNetworkSwitchVirtualTest { } @Test - fun testConnectClosedPort() = runBlockingSimulation { + fun testConnectClosedPort() = runSimulation { val engine = FlowEngine(coroutineContext, clock) val sink = SimNetworkSink(engine, capacity = 100.0) val switch = SimNetworkSwitchVirtual(engine) 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 2177a374..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 @@ -30,14 +30,14 @@ import org.junit.jupiter.api.assertThrows import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.FlowSource import org.opendc.simulator.flow.source.FixedFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +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 832b9d09..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 @@ -33,14 +33,14 @@ import org.junit.jupiter.api.assertThrows import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.FlowSource import org.opendc.simulator.flow.source.FixedFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +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(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(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 e3e9dbff..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 @@ -30,14 +30,14 @@ import org.junit.jupiter.api.Test import org.opendc.simulator.flow.FlowEngine import org.opendc.simulator.flow.FlowSource import org.opendc.simulator.flow.source.FixedFlowSource -import org.opendc.simulator.kotlin.runBlockingSimulation +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) diff --git a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt index e2193cf1..d340d31c 100644 --- a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt +++ b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt @@ -33,7 +33,7 @@ import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit import org.opendc.simulator.compute.power.LinearPowerModel import org.opendc.simulator.compute.power.SimplePowerDriver -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import org.opendc.web.proto.runner.Job import org.opendc.web.proto.runner.Scenario import org.opendc.web.proto.runner.Topology @@ -222,7 +222,7 @@ public class OpenDCRunner( /** * Run a single simulation of the scenario. */ - private fun runSimulation(monitor: WebComputeMonitor) = runBlockingSimulation { + private fun runSimulation(monitor: WebComputeMonitor) = runSimulation { val serviceDomain = "compute.opendc.org" val seed = repeat.toLong() diff --git a/opendc-workflow/opendc-workflow-service/src/test/kotlin/org/opendc/workflow/service/WorkflowServiceTest.kt b/opendc-workflow/opendc-workflow-service/src/test/kotlin/org/opendc/workflow/service/WorkflowServiceTest.kt index 4dc4e196..e37f489d 100644 --- a/opendc-workflow/opendc-workflow-service/src/test/kotlin/org/opendc/workflow/service/WorkflowServiceTest.kt +++ b/opendc-workflow/opendc-workflow-service/src/test/kotlin/org/opendc/workflow/service/WorkflowServiceTest.kt @@ -45,7 +45,7 @@ import org.opendc.simulator.compute.model.ProcessingUnit import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.power.SimplePowerDriver import org.opendc.simulator.flow.mux.FlowMultiplexerFactory -import org.opendc.simulator.kotlin.runBlockingSimulation +import org.opendc.simulator.kotlin.runSimulation import org.opendc.trace.Trace import org.opendc.workflow.service.scheduler.job.NullJobAdmissionPolicy import org.opendc.workflow.service.scheduler.job.SubmissionTimeJobOrderPolicy @@ -64,7 +64,7 @@ internal class WorkflowServiceTest { * A large integration test where we check whether all tasks in some trace are executed correctly. */ @Test - fun testTrace() = runBlockingSimulation { + fun testTrace() = runSimulation { val computeService = "compute.opendc.org" val workflowService = "workflow.opendc.org" -- cgit v1.2.3