summaryrefslogtreecommitdiff
path: root/odcsim-testkit/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'odcsim-testkit/src/main/kotlin')
-rw-r--r--odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorContextStub.kt19
-rw-r--r--odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorSystemStub.kt6
-rw-r--r--odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/BehaviorTestKitImpl.kt2
3 files changed, 17 insertions, 10 deletions
diff --git a/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorContextStub.kt b/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorContextStub.kt
index 7035b908..79873141 100644
--- a/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorContextStub.kt
+++ b/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorContextStub.kt
@@ -43,11 +43,14 @@ internal class ActorContextStub<T : Any>(private val owner: BehaviorTestKitImpl<
/**
* The children of this context.
*/
- val children = HashMap<String, BehaviorTestKitImpl<*>>()
+ val childActors = HashMap<String, BehaviorTestKitImpl<*>>()
override val self: ActorRef<T>
get() = owner.ref
+ override val children: List<ActorRef<*>>
+ get() = childActors.values.map { it.ref }
+
override val time: Instant
get() = owner.time
@@ -59,6 +62,8 @@ internal class ActorContextStub<T : Any>(private val owner: BehaviorTestKitImpl<
LoggerImpl(this)
}
+ override fun getChild(name: String): ActorRef<*>? = childActors[name]?.ref
+
override fun <U : Any> send(ref: ActorRef<U>, msg: U, after: Duration) {
if (ref !is TestInboxImpl.ActorRefImpl) {
throw IllegalArgumentException("The referenced ActorRef is not part of the test kit")
@@ -69,7 +74,7 @@ internal class ActorContextStub<T : Any>(private val owner: BehaviorTestKitImpl<
override fun <U : Any> spawn(behavior: Behavior<U>, name: String): ActorRef<U> {
val btk = BehaviorTestKitImpl(behavior, self.path.child(name))
- children[name] = btk
+ childActors[name] = btk
return btk.ref
}
@@ -77,13 +82,9 @@ internal class ActorContextStub<T : Any>(private val owner: BehaviorTestKitImpl<
return spawn(behavior, "$" + UUID.randomUUID())
}
- override fun stop(child: ActorRef<*>): Boolean {
- if (child.path.parent != self.path) {
- // This is not a child of this actor
- return false
- }
- children -= child.path.name
- return true
+ override fun stop(child: ActorRef<*>) {
+ require(child.path.parent == self.path) { "Only direct children of an actor may be stopped through the actor context." }
+ childActors -= child.path.name
}
override fun watch(target: ActorRef<*>) {}
diff --git a/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorSystemStub.kt b/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorSystemStub.kt
index f61c1d76..fee34a48 100644
--- a/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorSystemStub.kt
+++ b/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/ActorSystemStub.kt
@@ -25,7 +25,9 @@
package com.atlarge.odcsim.testkit.internal
import com.atlarge.odcsim.ActorPath
+import com.atlarge.odcsim.ActorRef
import com.atlarge.odcsim.ActorSystem
+import com.atlarge.odcsim.Behavior
import com.atlarge.odcsim.Duration
import com.atlarge.odcsim.Instant
@@ -49,4 +51,8 @@ internal class ActorSystemStub<T : Any>(private val owner: BehaviorTestKitImpl<T
override val path: ActorPath
get() = owner.ref.path
+
+ override suspend fun <U : Any> spawnSystem(behavior: Behavior<U>, name: String): ActorRef<U> {
+ throw IllegalStateException("Cannot spawn system actor")
+ }
}
diff --git a/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/BehaviorTestKitImpl.kt b/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/BehaviorTestKitImpl.kt
index cb216614..2bd5b973 100644
--- a/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/BehaviorTestKitImpl.kt
+++ b/odcsim-testkit/src/main/kotlin/com/atlarge/odcsim/testkit/internal/BehaviorTestKitImpl.kt
@@ -97,7 +97,7 @@ internal class BehaviorTestKitImpl<T : Any>(
override fun <U : Any> childTestKit(name: String): BehaviorTestKit<U> {
@Suppress("UNCHECKED_CAST")
- return context.children[ref.path.name] as BehaviorTestKitImpl<U>? ?: throw IllegalArgumentException("$ref is not a child of $this")
+ return context.childActors[ref.path.name] as BehaviorTestKitImpl<U>? ?: throw IllegalArgumentException("$ref is not a child of $this")
}
override fun <U : Any> childTestKit(ref: ActorRef<U>): BehaviorTestKit<U> {