summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-11-13 18:16:19 +0000
committerGitHub <noreply@github.com>2022-11-13 18:16:19 +0000
commit52eed48441693149993db79b63431b99e0973027 (patch)
treeba267db531bc3d81409ddfe9caeb6d3b5a65e8c8 /opendc-compute/opendc-compute-simulator/src/test
parent183cfa96910ebb74c668dea7ef98071966f8fcb9 (diff)
parent33d91ef30ad7bcb73365934fe536461210d1082a (diff)
merge: Increase minimum Java version to 17 (#115)
This pull request increases the minimum version of Java required by OpenDC to 17. This new version of Java introduces several new features compared to our old minimum version (11), which we attempt to apply in this conversion. ## Implementation Notes :hammer_and_pick: * Increase minimum Java version to Java 17 * Use RandomGenerator as randomness source * Add common dispatcher interface * Add compatibility with Kotlin coroutines * Use InstantSource as time source * Re-implement SimulationScheduler as Dispatcher * Replace use of CoroutineContext by Dispatcher ## External Dependencies :four_leaf_clover: * Java 17 ## Breaking API Changes :warning: * The use of `CoroutineContext` and `Clock` as parameters of classes has been replaced by the `Dispatcher` interface. * The use of `Clock` has been replaced by `InstantSource` which does not carry time zone info. * The use of `Random` and `SplittableRandom` as parameter type has been replaced by `RandomGenerator`
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/test')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt16
-rw-r--r--opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/failure/HostFaultInjectorTest.kt12
2 files changed, 14 insertions, 14 deletions
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 fc581d3e..a496cc99 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
@@ -75,7 +75,7 @@ internal class SimHostTest {
fun testSingle() = runSimulation {
val duration = 5 * 60L
- val engine = FlowEngine.create(coroutineContext, clock)
+ val engine = FlowEngine.create(dispatcher)
val graph = engine.newGraph()
val machine = SimBareMetalMachine.create(graph, machineModel)
@@ -85,7 +85,7 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- clock,
+ timeSource,
machine,
hypervisor
)
@@ -131,7 +131,7 @@ internal class SimHostTest {
{ assertEquals(639, cpuStats.activeTime, "Active time does not match") },
{ assertEquals(2360, cpuStats.idleTime, "Idle time does not match") },
{ assertEquals(56, cpuStats.stealTime, "Steal time does not match") },
- { assertEquals(1500001, clock.millis()) }
+ { assertEquals(1500001, timeSource.millis()) }
)
}
@@ -142,7 +142,7 @@ internal class SimHostTest {
fun testOvercommitted() = runSimulation {
val duration = 5 * 60L
- val engine = FlowEngine.create(coroutineContext, clock)
+ val engine = FlowEngine.create(dispatcher)
val graph = engine.newGraph()
val machine = SimBareMetalMachine.create(graph, machineModel)
@@ -152,7 +152,7 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- clock,
+ timeSource,
machine,
hypervisor
)
@@ -218,7 +218,7 @@ internal class SimHostTest {
{ assertEquals(658, cpuStats.activeTime, "Active time does not match") },
{ assertEquals(2341, cpuStats.idleTime, "Idle time does not match") },
{ assertEquals(637, cpuStats.stealTime, "Steal time does not match") },
- { assertEquals(1500001, clock.millis()) }
+ { assertEquals(1500001, timeSource.millis()) }
)
}
@@ -229,7 +229,7 @@ internal class SimHostTest {
fun testFailure() = runSimulation {
val duration = 5 * 60L
- val engine = FlowEngine.create(coroutineContext, clock)
+ val engine = FlowEngine.create(dispatcher)
val graph = engine.newGraph()
val machine = SimBareMetalMachine.create(graph, machineModel)
@@ -238,7 +238,7 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- clock,
+ timeSource,
machine,
hypervisor
)
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 90f534e6..29d0b5e7 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
@@ -30,15 +30,15 @@ import org.apache.commons.math3.random.Well19937c
import org.junit.jupiter.api.Test
import org.opendc.compute.simulator.SimHost
import org.opendc.simulator.kotlin.runSimulation
-import java.time.Clock
import java.time.Duration
+import java.time.InstantSource
import kotlin.coroutines.CoroutineContext
import kotlin.math.ln
/**
* Test suite for [HostFaultInjector] class.
*/
-internal class HostFaultInjectorTest {
+class HostFaultInjectorTest {
/**
* Simple test case to test that nothing happens when the injector is not started.
*/
@@ -46,7 +46,7 @@ internal class HostFaultInjectorTest {
fun testInjectorNotStarted() = runSimulation {
val host = mockk<SimHost>(relaxUnitFun = true)
- val injector = createSimpleInjector(coroutineContext, clock, setOf(host))
+ val injector = createSimpleInjector(coroutineContext, timeSource, setOf(host))
coVerify(exactly = 0) { host.fail() }
coVerify(exactly = 0) { host.recover() }
@@ -61,7 +61,7 @@ internal class HostFaultInjectorTest {
fun testInjectorStopsMachine() = runSimulation {
val host = mockk<SimHost>(relaxUnitFun = true)
- val injector = createSimpleInjector(coroutineContext, clock, setOf(host))
+ val injector = createSimpleInjector(coroutineContext, timeSource, setOf(host))
injector.start()
@@ -83,7 +83,7 @@ internal class HostFaultInjectorTest {
mockk(relaxUnitFun = true)
)
- val injector = createSimpleInjector(coroutineContext, clock, hosts.toSet())
+ val injector = createSimpleInjector(coroutineContext, timeSource, hosts.toSet())
injector.start()
@@ -100,7 +100,7 @@ internal class HostFaultInjectorTest {
/**
* Create a simple start stop fault injector.
*/
- private fun createSimpleInjector(context: CoroutineContext, clock: Clock, hosts: Set<SimHost>): HostFaultInjector {
+ private fun createSimpleInjector(context: CoroutineContext, clock: InstantSource, hosts: Set<SimHost>): HostFaultInjector {
val rng = Well19937c(0)
val iat = LogNormalDistribution(rng, ln(24 * 7.0), 1.03)
val selector = StochasticVictimSelector(LogNormalDistribution(rng, 1.88, 1.25))