diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-06-29 16:04:57 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 16:18:13 +0200 |
| commit | 46b06fb446e79c390c01953d31d700b8e73da24d (patch) | |
| tree | b2329630ebf2c90d297ba0d3046ccd558d12d042 /simulator/opendc/opendc-workflows/src/test/kotlin/com | |
| parent | ebcacf96fbc1cd16a91523f95dd01db046fb7f90 (diff) | |
Prepare simulator repository for monorepo
This change prepares the simulator Git repository for the monorepo residing at
https://github.com/atlarge-research.com/opendc. To accomodate for this, we
move all files into a simulator subdirectory.
Diffstat (limited to 'simulator/opendc/opendc-workflows/src/test/kotlin/com')
| -rw-r--r-- | simulator/opendc/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/simulator/opendc/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt b/simulator/opendc/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt new file mode 100644 index 00000000..5ee6d5e6 --- /dev/null +++ b/simulator/opendc/opendc-workflows/src/test/kotlin/com/atlarge/opendc/workflows/service/StageWorkflowSchedulerIntegrationTest.kt @@ -0,0 +1,125 @@ +/* + * 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.odcsim.SimulationEngineProvider +import com.atlarge.odcsim.simulationContext +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.async +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import java.util.ServiceLoader +import kotlin.math.max + +/** + * Integration test suite for the [StageWorkflowService]. + */ +@DisplayName("StageWorkflowService") +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 provider = ServiceLoader.load(SimulationEngineProvider::class.java).first() + val system = provider(name = "sim") + + val schedulerDomain = system.newDomain(name = "scheduler") + val schedulerAsync = schedulerDomain.async { + val environment = Sc18EnvironmentReader(object {}.javaClass.getResourceAsStream("/environment.json")) + .use { it.construct(system.newDomain("topology")) } + + StageWorkflowService( + schedulerDomain, + environment.platforms[0].zones[0].services[ProvisioningService], + mode = WorkflowSchedulerMode.Batch(100), + jobAdmissionPolicy = NullJobAdmissionPolicy, + jobOrderPolicy = SubmissionTimeJobOrderPolicy(), + taskEligibilityPolicy = NullTaskEligibilityPolicy, + taskOrderPolicy = SubmissionTimeTaskOrderPolicy(), + resourceFilterPolicy = FunctionalResourceFilterPolicy, + resourceSelectionPolicy = FirstFitResourceSelectionPolicy + ) + } + + val broker = system.newDomain(name = "broker") + + broker.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() + } + + broker.launch { + val ctx = simulationContext + 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 - ctx.clock.millis())) + scheduler.submit(job) + } + } + + runBlocking { + system.run() + system.terminate() + } + + assertEquals(jobsSubmitted, jobsStarted, "Not all submitted jobs started") + assertEquals(jobsSubmitted, jobsFinished, "Not all started jobs finished") + assertEquals(tasksStarted, tasksFinished, "Not all started tasks finished") + } +} |
