summaryrefslogtreecommitdiff
path: root/simulator/opendc-compute/opendc-compute-service
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-21 17:00:09 +0200
committerGitHub <noreply@github.com>2021-04-21 17:00:09 +0200
commit10dfc257de65cbbd1e25d1d7f5833bfb687d85ed (patch)
tree48b102c4d45b366abd8d0d368c31d6c0596ac30f /simulator/opendc-compute/opendc-compute-service
parentb4d1289bbd9539c041e8aeb39bb8962628399809 (diff)
parent62678b2890a7f3640836b99ca2fec9efd7485929 (diff)
simulator: Introduce SimulationCoroutineDispatcher (#120)
This change introduces the SimulationCoroutineDispatcher implementation which replaces the TestCoroutineDispatcher for running single-threaded simulations.
Diffstat (limited to 'simulator/opendc-compute/opendc-compute-service')
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt47
-rw-r--r--simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt26
2 files changed, 33 insertions, 40 deletions
diff --git a/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt b/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt
index c6e24346..a6258845 100644
--- a/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt
+++ b/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/ComputeServiceTest.kt
@@ -26,9 +26,6 @@ import io.mockk.*
import io.opentelemetry.api.metrics.MeterProvider
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
-import kotlinx.coroutines.test.TestCoroutineScope
-import kotlinx.coroutines.test.runBlockingTest
-import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.BeforeEach
@@ -43,7 +40,8 @@ import org.opendc.compute.service.scheduler.FilterScheduler
import org.opendc.compute.service.scheduler.filters.ComputeCapabilitiesFilter
import org.opendc.compute.service.scheduler.filters.ComputeFilter
import org.opendc.compute.service.scheduler.weights.MemoryWeigher
-import org.opendc.simulator.utils.DelayControllerClockAdapter
+import org.opendc.simulator.core.SimulationCoroutineScope
+import org.opendc.simulator.core.runBlockingSimulation
import java.util.*
/**
@@ -51,13 +49,13 @@ import java.util.*
*/
@OptIn(ExperimentalCoroutinesApi::class)
internal class ComputeServiceTest {
- lateinit var scope: TestCoroutineScope
+ lateinit var scope: SimulationCoroutineScope
lateinit var service: ComputeService
@BeforeEach
fun setUp() {
- scope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(scope)
+ scope = SimulationCoroutineScope()
+ val clock = scope.clock
val computeScheduler = FilterScheduler(
filters = listOf(ComputeFilter(), ComputeCapabilitiesFilter()),
weighers = listOf(MemoryWeigher() to -1.0)
@@ -66,13 +64,8 @@ internal class ComputeServiceTest {
service = ComputeService(scope.coroutineContext, clock, meter, computeScheduler)
}
- @AfterEach
- fun tearDown() {
- scope.cleanupTestCoroutines()
- }
-
@Test
- fun testClientClose() = scope.runBlockingTest {
+ fun testClientClose() = scope.runBlockingSimulation {
val client = service.newClient()
assertEquals(emptyList<Flavor>(), client.queryFlavors())
@@ -95,7 +88,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testClientCreate() = scope.runBlockingTest {
+ fun testClientCreate() = scope.runBlockingSimulation {
val client = service.newClient()
val flavor = client.newFlavor("test", 1, 1024)
@@ -121,7 +114,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testClientOnClose() = scope.runBlockingTest {
+ fun testClientOnClose() = scope.runBlockingSimulation {
service.close()
assertThrows<IllegalStateException> {
service.newClient()
@@ -129,7 +122,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testAddHost() = scope.runBlockingTest {
+ fun testAddHost() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
every { host.model } returns HostModel(4, 2048)
@@ -151,7 +144,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testAddHostDouble() = scope.runBlockingTest {
+ fun testAddHostDouble() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
every { host.model } returns HostModel(4, 2048)
@@ -167,7 +160,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerStartWithoutEnoughCpus() = scope.runBlockingTest {
+ fun testServerStartWithoutEnoughCpus() = scope.runBlockingSimulation {
val client = service.newClient()
val flavor = client.newFlavor("test", 1, 0)
val image = client.newImage("test")
@@ -180,7 +173,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerStartWithoutEnoughMemory() = scope.runBlockingTest {
+ fun testServerStartWithoutEnoughMemory() = scope.runBlockingSimulation {
val client = service.newClient()
val flavor = client.newFlavor("test", 0, 1024)
val image = client.newImage("test")
@@ -193,7 +186,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerStartWithoutEnoughResources() = scope.runBlockingTest {
+ fun testServerStartWithoutEnoughResources() = scope.runBlockingSimulation {
val client = service.newClient()
val flavor = client.newFlavor("test", 1, 1024)
val image = client.newImage("test")
@@ -206,7 +199,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerCancelRequest() = scope.runBlockingTest {
+ fun testServerCancelRequest() = scope.runBlockingSimulation {
val client = service.newClient()
val flavor = client.newFlavor("test", 1, 1024)
val image = client.newImage("test")
@@ -220,7 +213,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerCannotFitOnHost() = scope.runBlockingTest {
+ fun testServerCannotFitOnHost() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
every { host.model } returns HostModel(4, 2048)
@@ -243,7 +236,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testHostAvailableAfterSomeTime() = scope.runBlockingTest {
+ fun testHostAvailableAfterSomeTime() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
val listeners = mutableListOf<HostListener>()
@@ -274,7 +267,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testHostUnavailableAfterSomeTime() = scope.runBlockingTest {
+ fun testHostUnavailableAfterSomeTime() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
val listeners = mutableListOf<HostListener>()
@@ -305,7 +298,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerInvalidType() = scope.runBlockingTest {
+ fun testServerInvalidType() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
val listeners = mutableListOf<HostListener>()
@@ -328,7 +321,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerDeploy() = scope.runBlockingTest {
+ fun testServerDeploy() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
val listeners = mutableListOf<HostListener>()
@@ -371,7 +364,7 @@ internal class ComputeServiceTest {
}
@Test
- fun testServerDeployFailure() = scope.runBlockingTest {
+ fun testServerDeployFailure() = scope.runBlockingSimulation {
val host = mockk<Host>(relaxUnitFun = true)
val listeners = mutableListOf<HostListener>()
diff --git a/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt b/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt
index 81cb45df..20ea8d20 100644
--- a/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt
+++ b/simulator/opendc-compute/opendc-compute-service/src/test/kotlin/org/opendc/compute/service/InternalServerTest.kt
@@ -24,7 +24,6 @@ package org.opendc.compute.service
import io.mockk.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.yield
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
@@ -36,6 +35,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.core.runBlockingSimulation
import java.util.*
/**
@@ -95,7 +95,7 @@ class InternalServerTest {
}
@Test
- fun testStartTerminatedServer() = runBlockingTest {
+ fun testStartTerminatedServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -111,7 +111,7 @@ class InternalServerTest {
}
@Test
- fun testStartDeletedServer() = runBlockingTest {
+ fun testStartDeletedServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -124,7 +124,7 @@ class InternalServerTest {
}
@Test
- fun testStartProvisioningServer() = runBlockingTest {
+ fun testStartProvisioningServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -139,7 +139,7 @@ class InternalServerTest {
}
@Test
- fun testStartRunningServer() = runBlockingTest {
+ fun testStartRunningServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -154,7 +154,7 @@ class InternalServerTest {
}
@Test
- fun testStopProvisioningServer() = runBlockingTest {
+ fun testStopProvisioningServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -172,7 +172,7 @@ class InternalServerTest {
}
@Test
- fun testStopTerminatedServer() = runBlockingTest {
+ fun testStopTerminatedServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -186,7 +186,7 @@ class InternalServerTest {
}
@Test
- fun testStopDeletedServer() = runBlockingTest {
+ fun testStopDeletedServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -200,7 +200,7 @@ class InternalServerTest {
}
@Test
- fun testStopRunningServer() = runBlockingTest {
+ fun testStopRunningServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>()
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -217,7 +217,7 @@ class InternalServerTest {
}
@Test
- fun testDeleteProvisioningServer() = runBlockingTest {
+ fun testDeleteProvisioningServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>(relaxUnitFun = true)
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -236,7 +236,7 @@ class InternalServerTest {
}
@Test
- fun testDeleteTerminatedServer() = runBlockingTest {
+ fun testDeleteTerminatedServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>(relaxUnitFun = true)
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -252,7 +252,7 @@ class InternalServerTest {
}
@Test
- fun testDeleteDeletedServer() = runBlockingTest {
+ fun testDeleteDeletedServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>(relaxUnitFun = true)
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()
@@ -266,7 +266,7 @@ class InternalServerTest {
}
@Test
- fun testDeleteRunningServer() = runBlockingTest {
+ fun testDeleteRunningServer() = runBlockingSimulation {
val service = mockk<ComputeServiceImpl>(relaxUnitFun = true)
val uid = UUID.randomUUID()
val flavor = mockk<InternalFlavor>()