summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/test')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt12
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimChainWorkloadTest.kt43
2 files changed, 47 insertions, 8 deletions
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 cde6763c..2acf6ec7 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
@@ -177,6 +177,8 @@ class SimMachineTest {
}
override fun onStop(ctx: SimMachineContext) {}
+
+ override fun snapshot(): SimWorkload = TODO()
})
}
@@ -197,6 +199,8 @@ class SimMachineTest {
}
override fun onStop(ctx: SimMachineContext) {}
+
+ override fun snapshot(): SimWorkload = TODO()
})
}
@@ -217,6 +221,8 @@ class SimMachineTest {
}
override fun onStop(ctx: SimMachineContext) {}
+
+ override fun snapshot(): SimWorkload = TODO()
})
assertEquals(1000, clock.millis())
@@ -243,6 +249,8 @@ class SimMachineTest {
}
override fun onStop(ctx: SimMachineContext) {}
+
+ override fun snapshot(): SimWorkload = TODO()
})
assertEquals(40, clock.millis())
@@ -266,6 +274,8 @@ class SimMachineTest {
}
override fun onStop(ctx: SimMachineContext) {}
+
+ override fun snapshot(): SimWorkload = TODO()
})
assertEquals(4000, clock.millis())
@@ -289,6 +299,8 @@ class SimMachineTest {
}
override fun onStop(ctx: SimMachineContext) {}
+
+ override fun snapshot(): SimWorkload = TODO()
})
assertEquals(4000, clock.millis())
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimChainWorkloadTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimChainWorkloadTest.kt
index 2210374d..d0b0efaa 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimChainWorkloadTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimChainWorkloadTest.kt
@@ -25,6 +25,8 @@ package org.opendc.simulator.compute.workload
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -67,8 +69,8 @@ class SimChainWorkloadTest {
val workload =
SimWorkloads.chain(
- SimRuntimeWorkload(1000, 1.0),
- SimRuntimeWorkload(1000, 1.0)
+ SimWorkloads.runtime(1000, 1.0),
+ SimWorkloads.runtime(1000, 1.0)
)
machine.runWorkload(workload)
@@ -93,7 +95,7 @@ class SimChainWorkloadTest {
val workload =
SimWorkloads.chain(
workloadA,
- SimRuntimeWorkload(1000, 1.0)
+ SimWorkloads.runtime(1000, 1.0)
)
assertThrows<IllegalStateException> { machine.runWorkload(workload) }
@@ -117,9 +119,9 @@ class SimChainWorkloadTest {
val workload =
SimWorkloads.chain(
- SimRuntimeWorkload(1000, 1.0),
+ SimWorkloads.runtime(1000, 1.0),
workloadA,
- SimRuntimeWorkload(1000, 1.0)
+ SimWorkloads.runtime(1000, 1.0)
)
assertThrows<IllegalStateException> { machine.runWorkload(workload) }
@@ -143,7 +145,7 @@ class SimChainWorkloadTest {
val workload =
SimWorkloads.chain(
workloadA,
- SimRuntimeWorkload(1000, 1.0)
+ SimWorkloads.runtime(1000, 1.0)
)
assertThrows<IllegalStateException> { machine.runWorkload(workload) }
@@ -166,9 +168,9 @@ class SimChainWorkloadTest {
val workload =
SimWorkloads.chain(
- SimRuntimeWorkload(1000, 1.0),
+ SimWorkloads.runtime(1000, 1.0),
workloadA,
- SimRuntimeWorkload(1000, 1.0)
+ SimWorkloads.runtime(1000, 1.0)
)
assertThrows<IllegalStateException> { machine.runWorkload(workload) }
@@ -255,4 +257,29 @@ class SimChainWorkloadTest {
assertEquals(1, exc.cause!!.suppressedExceptions.size)
assertEquals(1000, clock.millis())
}
+
+ @Test
+ fun testSnapshot() = runSimulation {
+ val engine = FlowEngine.create(coroutineContext, clock)
+ val graph = engine.newGraph()
+
+ val machine = SimBareMetalMachine.create(graph, machineModel)
+ val workload =
+ SimWorkloads.chain(
+ SimWorkloads.runtime(1000, 1.0),
+ SimWorkloads.runtime(1000, 1.0)
+ )
+
+ val job = launch { machine.runWorkload(workload) }
+ delay(500L)
+ val snapshot = workload.snapshot()
+
+ job.join()
+
+ assertEquals(2000, clock.millis())
+
+ machine.runWorkload(snapshot)
+
+ assertEquals(3500, clock.millis())
+ }
}