summaryrefslogtreecommitdiff
path: root/simulator/opendc-workflows/src/test/kotlin/com
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-10-01 00:49:53 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-10-01 10:19:13 +0200
commit8a9f5573bef3f68316add17c04a47cc4e5fe75fa (patch)
tree8dff00c904d5db65e9baf0e7ca2d18a8a61800c1 /simulator/opendc-workflows/src/test/kotlin/com
parent27ddd462d148d70760e45f967387905054e21d20 (diff)
Move OpenDC modules into simulator root
This change moves the OpenDC modules previously living in the simulator/opendc directory to the simulator directory itself given that we do not make a distinction between OpenDC and odcsim anymore.
Diffstat (limited to 'simulator/opendc-workflows/src/test/kotlin/com')
-rw-r--r--simulator/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt118
1 files changed, 118 insertions, 0 deletions
diff --git a/simulator/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt b/simulator/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt
new file mode 100644
index 00000000..114003a3
--- /dev/null
+++ b/simulator/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt
@@ -0,0 +1,118 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020 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 com.atlarge.opendc.workflows.service
+
+import com.atlarge.opendc.compute.metal.service.ProvisioningService
+import com.atlarge.opendc.format.environment.sc18.Sc18EnvironmentReader
+import com.atlarge.opendc.format.trace.gwf.GwfTraceReader
+import com.atlarge.opendc.workflows.service.stage.job.NullJobAdmissionPolicy
+import com.atlarge.opendc.workflows.service.stage.job.SubmissionTimeJobOrderPolicy
+import com.atlarge.opendc.workflows.service.stage.resource.FirstFitResourceSelectionPolicy
+import com.atlarge.opendc.workflows.service.stage.resource.FunctionalResourceFilterPolicy
+import com.atlarge.opendc.workflows.service.stage.task.NullTaskEligibilityPolicy
+import com.atlarge.opendc.workflows.service.stage.task.SubmissionTimeTaskOrderPolicy
+import kotlinx.coroutines.*
+import kotlinx.coroutines.flow.collect
+import kotlinx.coroutines.flow.onEach
+import kotlinx.coroutines.test.TestCoroutineScope
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertNotEquals
+import org.junit.jupiter.api.DisplayName
+import org.junit.jupiter.api.Test
+import org.opendc.simulator.utils.DelayControllerClockAdapter
+import kotlin.math.max
+
+/**
+ * Integration test suite for the [StageWorkflowService].
+ */
+@DisplayName("StageWorkflowService")
+@OptIn(ExperimentalCoroutinesApi::class)
+internal class StageWorkflowSchedulerIntegrationTest {
+ /**
+ * A large integration test where we check whether all tasks in some trace are executed correctly.
+ */
+ @Test
+ fun `should execute all tasks in trace`() {
+ var jobsSubmitted = 0L
+ var jobsStarted = 0L
+ var jobsFinished = 0L
+ var tasksStarted = 0L
+ var tasksFinished = 0L
+
+ val testScope = TestCoroutineScope()
+ val clock = DelayControllerClockAdapter(testScope)
+
+ val schedulerAsync = testScope.async {
+ val environment = Sc18EnvironmentReader(object {}.javaClass.getResourceAsStream("/environment.json"))
+ .use { it.construct(testScope, clock) }
+
+ StageWorkflowService(
+ testScope,
+ clock,
+ environment.platforms[0].zones[0].services[ProvisioningService],
+ mode = WorkflowSchedulerMode.Batch(100),
+ jobAdmissionPolicy = NullJobAdmissionPolicy,
+ jobOrderPolicy = SubmissionTimeJobOrderPolicy(),
+ taskEligibilityPolicy = NullTaskEligibilityPolicy,
+ taskOrderPolicy = SubmissionTimeTaskOrderPolicy(),
+ resourceFilterPolicy = FunctionalResourceFilterPolicy,
+ resourceSelectionPolicy = FirstFitResourceSelectionPolicy
+ )
+ }
+
+ testScope.launch {
+ val scheduler = schedulerAsync.await()
+ scheduler.events
+ .onEach { event ->
+ when (event) {
+ is WorkflowEvent.JobStarted -> jobsStarted++
+ is WorkflowEvent.JobFinished -> jobsFinished++
+ is WorkflowEvent.TaskStarted -> tasksStarted++
+ is WorkflowEvent.TaskFinished -> tasksFinished++
+ }
+ }
+ .collect()
+ }
+
+ testScope.launch {
+ val reader = GwfTraceReader(object {}.javaClass.getResourceAsStream("/trace.gwf"))
+ val scheduler = schedulerAsync.await()
+
+ while (reader.hasNext()) {
+ val (time, job) = reader.next()
+ jobsSubmitted++
+ delay(max(0, time * 1000 - clock.millis()))
+ scheduler.submit(job)
+ }
+ }
+
+ testScope.advanceUntilIdle()
+
+ assertNotEquals(0, jobsSubmitted, "No jobs submitted")
+ assertEquals(jobsSubmitted, jobsStarted, "Not all submitted jobs started")
+ assertEquals(jobsSubmitted, jobsFinished, "Not all started jobs finished")
+ assertEquals(tasksStarted, tasksFinished, "Not all started tasks finished")
+ }
+}