From 1c0568c31d60d4e690b4b9aec2e14f660b72a5c8 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 21 Apr 2021 14:30:55 +0200 Subject: simulator: Introduce SimulationCoroutineDispatcher This change introduces the SimulationCoroutineDispatcher implementation which replaces the TestCoroutineDispatcher for running single-threaded simulations. Previously, we used the TestCoroutineDispatcher from the kotlinx-coroutines-test modules for running simulations. However, this module is aimed at coroutine tests and not at simulations. In particular, having to construct a Clock object each time for the TestCoroutineDispatcher caused a lot of unnecessary lines. With the new approach, the SimulationCoroutineDispatcher automatically exposes a usable Clock object. In addition to ergonomic benefits, the SimulationCoroutineDispatcher is much faster than the TestCoroutineDispatcher due to the assumption that simulations run in only a single thread. As a result, the dispatcher does not need to perform synchronization and can use the fast PriorityQueue implementation. --- .../test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'simulator/opendc-serverless/opendc-serverless-service/src') diff --git a/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt b/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt index bf99d0e7..1ab2d033 100644 --- a/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt +++ b/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt @@ -34,7 +34,7 @@ import org.opendc.serverless.api.ServerlessFunction import org.opendc.serverless.service.deployer.FunctionDeployer import org.opendc.serverless.service.deployer.FunctionInstance import org.opendc.serverless.service.deployer.FunctionInstanceState -import org.opendc.simulator.utils.DelayControllerClockAdapter +import org.opendc.simulator.core.DelayControllerClockAdapter import java.util.* /** -- cgit v1.2.3 From 62678b2890a7f3640836b99ca2fec9efd7485929 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 21 Apr 2021 16:35:52 +0200 Subject: simulator: Migrate to SimulationCoroutineDispatcher This change migrates the remainder of the codebase to the SimulationCoroutineDispatcher implementation. --- .../serverless/service/ServerlessServiceTest.kt | 33 ++++++++-------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'simulator/opendc-serverless/opendc-serverless-service/src') diff --git a/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt b/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt index 1ab2d033..d9f5ee81 100644 --- a/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt +++ b/simulator/opendc-serverless/opendc-serverless-service/src/test/kotlin/org/opendc/serverless/service/ServerlessServiceTest.kt @@ -25,7 +25,6 @@ package org.opendc.serverless.service import io.mockk.* import io.opentelemetry.api.metrics.MeterProvider import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertDoesNotThrow @@ -34,7 +33,7 @@ import org.opendc.serverless.api.ServerlessFunction import org.opendc.serverless.service.deployer.FunctionDeployer import org.opendc.serverless.service.deployer.FunctionInstance import org.opendc.serverless.service.deployer.FunctionInstanceState -import org.opendc.simulator.core.DelayControllerClockAdapter +import org.opendc.simulator.core.runBlockingSimulation import java.util.* /** @@ -44,9 +43,8 @@ import java.util.* internal class ServerlessServiceTest { @Test - fun testClientState() = runBlockingTest { + fun testClientState() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = assertDoesNotThrow { service.newClient() } @@ -60,9 +58,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientInvokeUnknown() = runBlockingTest { + fun testClientInvokeUnknown() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -71,9 +68,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionCreation() = runBlockingTest { + fun testClientFunctionCreation() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -84,9 +80,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionQuery() = runBlockingTest { + fun testClientFunctionQuery() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -99,9 +94,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionFindById() = runBlockingTest { + fun testClientFunctionFindById() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -114,9 +108,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionFindByName() = runBlockingTest { + fun testClientFunctionFindByName() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -129,9 +122,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionDuplicateName() = runBlockingTest { + fun testClientFunctionDuplicateName() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -142,9 +134,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionDelete() = runBlockingTest { + fun testClientFunctionDelete() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -158,9 +149,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionCannotInvokeDeleted() = runBlockingTest { + fun testClientFunctionCannotInvokeDeleted() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val service = ServerlessService(coroutineContext, clock, meter, mockk(), mockk()) val client = service.newClient() @@ -172,9 +162,8 @@ internal class ServerlessServiceTest { } @Test - fun testClientFunctionInvoke() = runBlockingTest { + fun testClientFunctionInvoke() = runBlockingSimulation { val meter = MeterProvider.noop().get("opendc-serverless") - val clock = DelayControllerClockAdapter(this) val deployer = mockk() val service = ServerlessService(coroutineContext, clock, meter, deployer, mockk()) -- cgit v1.2.3