diff options
Diffstat (limited to 'opendc-simulator/opendc-simulator-core/src')
5 files changed, 31 insertions, 18 deletions
diff --git a/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/SimulationScheduler.java b/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/SimulationScheduler.java index a70c1cda..305bdf5e 100644 --- a/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/SimulationScheduler.java +++ b/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/SimulationScheduler.java @@ -67,7 +67,7 @@ public final class SimulationScheduler implements Executor { * @param initialTimeMs The initial virtual time of the scheduler in milliseconds since epoch. */ public SimulationScheduler(long initialTimeMs) { - this.currentTime = initialTimeMs; + this.currentTime = initialTimeMs; } /** @@ -104,7 +104,8 @@ public final class SimulationScheduler implements Executor { */ public int schedule(long delayMs, Runnable task) { if (delayMs < 0) { - throw new IllegalArgumentException("Attempted scheduling an event earlier in time (delay " + delayMs + " ms)"); + throw new IllegalArgumentException( + "Attempted scheduling an event earlier in time (delay " + delayMs + " ms)"); } long target = currentTime + delayMs; diff --git a/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/TaskQueue.java b/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/TaskQueue.java index 7d867b5d..f677e74e 100644 --- a/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/TaskQueue.java +++ b/opendc-simulator/opendc-simulator-core/src/main/java/org/opendc/simulator/TaskQueue.java @@ -193,7 +193,8 @@ final class TaskQueue { /** * Sift up an entry in the heap. */ - private static void siftUp(long[] deadlines, int[] ids, Runnable[] tasks, int k, long deadline, int id, Runnable task) { + private static void siftUp( + long[] deadlines, int[] ids, Runnable[] tasks, int k, long deadline, int id, Runnable task) { while (k > 0) { int parent = (k - 1) >>> 1; long parentDeadline = deadlines[parent]; @@ -218,11 +219,12 @@ final class TaskQueue { /** * Sift down an entry in the heap. */ - private static void siftDown(long[] deadlines, int[] ids, Runnable[] tasks, int k, int n, long deadline, int id, Runnable task) { - int half = n >>> 1; // loop while a non-leaf + private static void siftDown( + long[] deadlines, int[] ids, Runnable[] tasks, int k, int n, long deadline, int id, Runnable task) { + int half = n >>> 1; // loop while a non-leaf while (k < half) { - int child = (k << 1) + 1; // assume left child is least + int child = (k << 1) + 1; // assume left child is least long childDeadline = deadlines[child]; int childId = ids[child]; diff --git a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt index c4cc0171..882a0fc5 100644 --- a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt +++ b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationBuilders.kt @@ -22,7 +22,10 @@ package org.opendc.simulator.kotlin -import kotlinx.coroutines.* +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.async import org.opendc.simulator.SimulationScheduler import kotlin.coroutines.ContinuationInterceptor import kotlin.coroutines.CoroutineContext diff --git a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineDispatcher.kt b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineDispatcher.kt index 21ad1a86..cacbbbf7 100644 --- a/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineDispatcher.kt +++ b/opendc-simulator/opendc-simulator-core/src/main/kotlin/org/opendc/simulator/kotlin/SimulationCoroutineDispatcher.kt @@ -22,11 +22,15 @@ package org.opendc.simulator.kotlin -import kotlinx.coroutines.* +import kotlinx.coroutines.CancellableContinuation +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Delay +import kotlinx.coroutines.DisposableHandle +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.InternalCoroutinesApi import org.opendc.simulator.SimulationScheduler import java.lang.Runnable import java.time.Clock -import java.util.* import kotlin.coroutines.CoroutineContext /** diff --git a/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt b/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt index a4d779cb..56dd83aa 100644 --- a/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt +++ b/opendc-simulator/opendc-simulator-core/src/test/kotlin/org/opendc/simulator/TaskQueueTest.kt @@ -22,7 +22,10 @@ package org.opendc.simulator -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertAll +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -44,7 +47,7 @@ class TaskQueueTest { fun testPollEmpty() { assertAll( { assertEquals(Long.MAX_VALUE, queue.peekDeadline()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } @@ -60,7 +63,7 @@ class TaskQueueTest { assertAll( { assertEquals(100, queue.peekDeadline()) }, { assertEquals(entry, queue.poll()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } @@ -83,7 +86,7 @@ class TaskQueueTest { { assertEquals(entryB, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } @@ -106,7 +109,7 @@ class TaskQueueTest { { assertEquals(entryA, queue.poll()) }, { assertEquals(entryB, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } @@ -133,7 +136,7 @@ class TaskQueueTest { { assertEquals(entryD, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } @@ -157,7 +160,7 @@ class TaskQueueTest { { assertEquals(20, queue.peekDeadline()) }, { assertEquals(entryB, queue.poll()) }, { assertEquals(entryC, queue.poll()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } @@ -181,7 +184,7 @@ class TaskQueueTest { { assertEquals(58, queue.peekDeadline()) }, { assertEquals(entryC, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } @@ -205,7 +208,7 @@ class TaskQueueTest { { assertEquals(20, queue.peekDeadline()) }, { assertEquals(entryB, queue.poll()) }, { assertEquals(entryA, queue.poll()) }, - { assertNull(queue.poll()) }, + { assertNull(queue.poll()) } ) } |
