summaryrefslogtreecommitdiff
path: root/odcsim-core
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-core
parent0f71f1e1c559bfebc20dad4ae979e7f6b58b7acf (diff)
feat: Add testkit for testing behavior
This change adds a testkit for synchronously testking Behavior implementations.
Diffstat (limited to 'odcsim-core')
-rw-r--r--odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt5
-rw-r--r--odcsim-core/src/main/kotlin/com/atlarge/odcsim/Envelope.kt57
-rw-r--r--odcsim-core/src/main/kotlin/com/atlarge/odcsim/coroutines/dsl/Timeout.kt2
-rw-r--r--odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt2
4 files changed, 64 insertions, 2 deletions
diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt
index 3ba5ce76..2fe97d59 100644
--- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt
+++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt
@@ -34,6 +34,11 @@ interface ActorRef<in T : Any> : Comparable<ActorRef<*>>, Serializable {
* The path for this actor (from this actor up to the root actor).
*/
val path: ActorPath
+
+ /**
+ * Compare this reference to another actor reference.
+ */
+ override fun compareTo(other: ActorRef<*>): Int = path.compareTo(other.path)
}
/**
diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/Envelope.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/Envelope.kt
new file mode 100644
index 00000000..3b73d52d
--- /dev/null
+++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/Envelope.kt
@@ -0,0 +1,57 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 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.odcsim
+
+import java.io.Serializable
+
+/**
+ * A timestamped wrapper for messages that will be delivered to an actor.
+ */
+interface Envelope<T : Any> : Comparable<Envelope<*>>, Serializable {
+ /**
+ * The time at which this message should be delivered.
+ */
+ val time: Instant
+
+ /**
+ * The message contained in this envelope, of type [T]
+ */
+ val message: T
+
+ /**
+ * Extract the delivery time from the envelope.
+ */
+ operator fun component1(): Instant = time
+
+ /**
+ * Extract the message from this envelope.
+ */
+ operator fun component2(): T = message
+
+ /**
+ * Compare this envelope to the [other] envelope, ordered increasingly in time.
+ */
+ override fun compareTo(other: Envelope<*>): Int = time.compareTo(other.time)
+}
diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/coroutines/dsl/Timeout.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/coroutines/dsl/Timeout.kt
index 45cbce69..1d91f5b8 100644
--- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/coroutines/dsl/Timeout.kt
+++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/coroutines/dsl/Timeout.kt
@@ -28,8 +28,8 @@ import com.atlarge.odcsim.Duration
import com.atlarge.odcsim.Timeout
import com.atlarge.odcsim.coroutines.SuspendingActorContext
import com.atlarge.odcsim.coroutines.suspendWithBehavior
-import com.atlarge.odcsim.setup
import com.atlarge.odcsim.receiveSignal
+import com.atlarge.odcsim.setup
import com.atlarge.odcsim.unhandled
import kotlin.coroutines.resume
diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt
index 1f040c5e..8d533e9e 100644
--- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt
+++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/internal/Coroutines.kt
@@ -34,9 +34,9 @@ import com.atlarge.odcsim.ReceivingBehavior
import com.atlarge.odcsim.Signal
import com.atlarge.odcsim.coroutines.SuspendingActorContext
import com.atlarge.odcsim.coroutines.SuspendingBehavior
-import com.atlarge.odcsim.receiveSignal
import com.atlarge.odcsim.coroutines.suspendWithBehavior
import com.atlarge.odcsim.receiveMessage
+import com.atlarge.odcsim.receiveSignal
import org.slf4j.Logger
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext