summaryrefslogtreecommitdiff
path: root/odcsim-engine-omega
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2019-04-29 14:56:51 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2019-05-14 12:55:55 +0200
commit7428262dcd8da85de0adca0ef82c57398cf411fc (patch)
treec38e8bcaf2a47fda8d57bbb402608e9462041e0d /odcsim-engine-omega
parent0f71f1e1c559bfebc20dad4ae979e7f6b58b7acf (diff)
feat: Add testkit for testing behavior
This change adds a testkit for synchronously testking Behavior implementations.
Diffstat (limited to 'odcsim-engine-omega')
-rw-r--r--odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt16
1 files changed, 10 insertions, 6 deletions
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<in T : Any>(root: Behavior<T>, override val name: String)
/**
* The event queue to process
*/
- private val queue: PriorityQueue<Envelope> = PriorityQueue(Comparator
- .comparingDouble(Envelope::time)
- .thenComparingLong(Envelope::id))
+ private val queue: PriorityQueue<EnvelopeImpl> = PriorityQueue(Comparator
+ .comparingDouble(EnvelopeImpl::time)
+ .thenComparingLong(EnvelopeImpl::id))
/**
* The registry of actors in the system.
@@ -258,12 +259,15 @@ class OmegaActorSystem<in T : Any>(root: Behavior<T>, 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<Any>
/**
* Schedule a message to be processed by the engine.
@@ -274,6 +278,6 @@ class OmegaActorSystem<in T : Any>(root: Behavior<T>, 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))
}
}