summaryrefslogtreecommitdiff
path: root/simulator/opendc-compute
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-21 16:35:52 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-21 16:37:18 +0200
commit62678b2890a7f3640836b99ca2fec9efd7485929 (patch)
treedc6d6e8bb495c019990513511d7ff042afde0f05 /simulator/opendc-compute
parent1c0568c31d60d4e690b4b9aec2e14f660b72a5c8 (diff)
simulator: Migrate to SimulationCoroutineDispatcher
This change migrates the remainder of the codebase to the SimulationCoroutineDispatcher implementation.
Diffstat (limited to 'simulator/opendc-compute')
-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
-rw-r--r--simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt8
3 files changed, 36 insertions, 45 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 059f9cd9..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.core.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>()
diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
index cdbdd58b..5594fd59 100644
--- a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
+++ b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
@@ -29,7 +29,6 @@ import io.opentelemetry.sdk.metrics.data.MetricData
import io.opentelemetry.sdk.metrics.export.MetricExporter
import io.opentelemetry.sdk.metrics.export.MetricProducer
import kotlinx.coroutines.*
-import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -47,7 +46,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.workload.SimTraceWorkload
-import org.opendc.simulator.core.DelayControllerClockAdapter
+import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.telemetry.sdk.metrics.export.CoroutineMetricReader
import org.opendc.telemetry.sdk.toOtelClock
import java.util.UUID
@@ -74,8 +73,7 @@ internal class SimHostTest {
* Test overcommitting of resources by the hypervisor.
*/
@Test
- fun testOvercommitted() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testOvercommitted() = runBlockingSimulation {
var requestedWork = 0L
var grantedWork = 0L
var overcommittedWork = 0L
@@ -165,7 +163,7 @@ internal class SimHostTest {
{ assertEquals(4197600, requestedWork, "Requested work does not match") },
{ assertEquals(2157600, grantedWork, "Granted work does not match") },
{ assertEquals(2040000, overcommittedWork, "Overcommitted work does not match") },
- { assertEquals(1500001, currentTime) }
+ { assertEquals(1500001, clock.millis()) }
)
}