From 7428262dcd8da85de0adca0ef82c57398cf411fc Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Mon, 29 Apr 2019 14:56:51 +0200 Subject: feat: Add testkit for testing behavior This change adds a testkit for synchronously testking Behavior implementations. --- .../com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'odcsim-engine-omega') diff --git a/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt b/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt index 881eb98d..7e58084d 100644 --- a/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt +++ b/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt @@ -30,6 +30,7 @@ import com.atlarge.odcsim.ActorRef import com.atlarge.odcsim.ActorSystem import com.atlarge.odcsim.Behavior import com.atlarge.odcsim.Duration +import com.atlarge.odcsim.Envelope import com.atlarge.odcsim.Instant import com.atlarge.odcsim.PostStop import com.atlarge.odcsim.PreStart @@ -68,9 +69,9 @@ class OmegaActorSystem(root: Behavior, override val name: String) /** * The event queue to process */ - private val queue: PriorityQueue = PriorityQueue(Comparator - .comparingDouble(Envelope::time) - .thenComparingLong(Envelope::id)) + private val queue: PriorityQueue = PriorityQueue(Comparator + .comparingDouble(EnvelopeImpl::time) + .thenComparingLong(EnvelopeImpl::id)) /** * The registry of actors in the system. @@ -258,12 +259,15 @@ class OmegaActorSystem(root: Behavior, override val name: String) /** * A wrapper around a message that has been scheduled for processing. * - * @property time The point in time to deliver the message. * @property id The identifier of the message to keep the priority queue stable. * @property destination The destination of the message. + * @property time The point in time to deliver the message. * @property message The message to wrap. */ - private class Envelope(val time: Instant, val id: Long, val destination: ActorPath, val message: Any) + private class EnvelopeImpl(val id: Long, + val destination: ActorPath, + override val time: Instant, + override val message: Any) : Envelope /** * Schedule a message to be processed by the engine. @@ -274,6 +278,6 @@ class OmegaActorSystem(root: Behavior, override val name: String) */ private fun schedule(destination: ActorRef<*>, message: Any, delay: Duration) { require(delay >= .0) { "The given delay must be a non-negative number" } - queue.add(Envelope(time + delay, nextId++, destination.path, message)) + queue.add(EnvelopeImpl(nextId++, destination.path, time + delay, message)) } } -- cgit v1.2.3