summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src/test
diff options
context:
space:
mode:
authorSacheendra Talluri <sacheendra.t@gmail.com>2025-03-20 10:16:46 +0100
committerGitHub <noreply@github.com>2025-03-20 10:16:46 +0100
commit1e35c61cd31b8bfb33a6ccbb46b08c0466518e6c (patch)
tree261c84148cd045246bdc2ad7aa3c41524356b699 /opendc-compute/opendc-compute-simulator/src/test
parent6211b887b68b3ebc9245fada1c0f36725955b052 (diff)
Adds load shifting over time (#319)
* Start time shifting * Existing experiments work with new columns * Remove unused traces dir * Update java to 21 LTS and jacoco to be compatible * Minimal working timeshifting * Timeshift scheduler linked as carbon receiver * Add basic tests for timeshift scheduler * Run spotless apply * Modify tarce format tests to support new fields * Change all mentions of java 19 to 21 * Add a deferAll option to workload to make all tasks deferrable * Run spotless apply * Copy traces from resources in web dockerfile
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/scheduler/TimeshiftSchedulerTest.kt89
1 files changed, 89 insertions, 0 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/scheduler/TimeshiftSchedulerTest.kt b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/scheduler/TimeshiftSchedulerTest.kt
new file mode 100644
index 00000000..b893c1aa
--- /dev/null
+++ b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/scheduler/TimeshiftSchedulerTest.kt
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2025 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.compute.simulator.scheduler
+
+import io.mockk.every
+import io.mockk.mockk
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+import org.opendc.compute.simulator.service.TaskNature
+import java.time.Duration
+import java.time.Instant
+import java.time.InstantSource
+
+class TimeshiftSchedulerTest {
+ @Test
+ fun testBasicDeferring() {
+ val clock = mockk<InstantSource>()
+ every { clock.instant() } returns Instant.ofEpochMilli(10)
+
+ val scheduler =
+ TimeshiftScheduler(
+ filters = emptyList(),
+ weighers = emptyList(),
+ windowSize = 2,
+ clock = clock,
+ )
+
+ val req = mockk<SchedulingRequest>()
+ every { req.task.flavor.coreCount } returns 2
+ every { req.task.flavor.memorySize } returns 1024
+ every { req.isCancelled } returns false
+ every { req.task.nature } returns TaskNature(true)
+ every { req.task.duration } returns Duration.ofMillis(10)
+ every { req.task.deadline } returns 50
+
+ scheduler.updateCarbonIntensity(100.0)
+ scheduler.updateCarbonIntensity(200.0)
+
+ assertEquals(SchedulingResultType.EMPTY, scheduler.select(mutableListOf(req).iterator()).resultType)
+ }
+
+ @Test
+ fun testRespectDeadline() {
+ val clock = mockk<InstantSource>()
+ every { clock.instant() } returns Instant.ofEpochMilli(10)
+
+ val scheduler =
+ TimeshiftScheduler(
+ filters = emptyList(),
+ weighers = emptyList(),
+ windowSize = 2,
+ clock = clock,
+ )
+
+ val req = mockk<SchedulingRequest>()
+ every { req.task.flavor.coreCount } returns 2
+ every { req.task.flavor.memorySize } returns 1024
+ every { req.isCancelled } returns false
+ every { req.task.nature } returns TaskNature(true)
+ every { req.task.duration } returns Duration.ofMillis(10)
+ every { req.task.deadline } returns 20
+
+ scheduler.updateCarbonIntensity(100.0)
+ scheduler.updateCarbonIntensity(200.0)
+
+ // The scheduler tries to schedule the task, but fails as there are no hosts.
+ assertEquals(SchedulingResultType.FAILURE, scheduler.select(mutableListOf(req).iterator()).resultType)
+ }
+}