From 4e6920d5c128b49750408a11850dfa6a7abb1e9e Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 25 Apr 2019 21:28:10 +0200 Subject: feat: Add support for ActorSystem termination This change adds support for terminating an ActorSystem. --- .../odcsim/engine/tests/ActorSystemContract.kt | 33 ++++++++++++++-------- .../engine/tests/ActorSystemFactoryContract.kt | 14 +++++++-- 2 files changed, 33 insertions(+), 14 deletions(-) (limited to 'odcsim-engine-tests/src/main') diff --git a/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemContract.kt b/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemContract.kt index eb6d38f6..bdcfad55 100644 --- a/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemContract.kt +++ b/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemContract.kt @@ -60,6 +60,7 @@ abstract class ActorSystemContract { val system = factory(empty(), name) assertEquals(name, system.name) + system.terminate() } /** @@ -70,6 +71,7 @@ abstract class ActorSystemContract { val system = factory(empty(), "test") assertTrue(system.path is ActorPath.Root) + system.terminate() } /** @@ -80,6 +82,7 @@ abstract class ActorSystemContract { val system = factory(empty(), name = "test") assertEquals(.0, system.time, DELTA) + system.terminate() } /** @@ -89,6 +92,7 @@ abstract class ActorSystemContract { fun `should not accept negative instants for running`() { val system = factory(empty(), name = "test") assertThrows { system.run(-10.0) } + system.terminate() } /** @@ -103,6 +107,7 @@ abstract class ActorSystemContract { system.run(until = until) system.run(until = until - 0.5) assertEquals(until, system.time, DELTA) + system.terminate() } /** @@ -115,6 +120,7 @@ abstract class ActorSystemContract { system.run(until = until) assertEquals(until, system.time, DELTA) + system.terminate() } /** @@ -133,6 +139,7 @@ abstract class ActorSystemContract { system.send(1, after = 1.0) system.send(2, after = 1.0) system.run(until = 10.0) + system.terminate() } /** @@ -150,6 +157,7 @@ abstract class ActorSystemContract { system.send(Unit, after = 1.0) system.run(until = 2.0) assertEquals(1, counter) + system.terminate() } /** @@ -157,7 +165,8 @@ abstract class ActorSystemContract { */ @Test fun `should not initialize root actor if not run`() { - factory(setup { TODO() }, name = "test") + val system = factory(setup { TODO() }, name = "test") + system.terminate() } @@ -171,6 +180,7 @@ abstract class ActorSystemContract { fun `should disallow messages in the past`() { val system = factory(empty(), name = "test") assertThrows { system.send(Unit, after = -1.0) } + system.terminate() } } @@ -189,6 +199,7 @@ abstract class ActorSystemContract { val system = factory(behavior, "test") system.run() + system.terminate() } /** @@ -207,6 +218,7 @@ abstract class ActorSystemContract { system.run(until = 10.0) assertTrue(spawned) + system.terminate() } /** @@ -223,6 +235,7 @@ abstract class ActorSystemContract { }, name = "test") system.run(until = 10.0) + system.terminate() } /** @@ -240,6 +253,7 @@ abstract class ActorSystemContract { ignore() }, name = "test") system.run() + system.terminate() } /** @@ -254,6 +268,7 @@ abstract class ActorSystemContract { ignore() }, name = "test") system.run() + system.terminate() } /** @@ -279,6 +294,7 @@ abstract class ActorSystemContract { }, name = "test") system.run() + system.terminate() } /** @@ -300,6 +316,7 @@ abstract class ActorSystemContract { val system = factory(behavior, "test") system.run() assertEquals(2, counter) + system.terminate() } /** @@ -316,24 +333,17 @@ abstract class ActorSystemContract { val system = factory(behavior, "test") system.run() assertTrue(flag) + system.terminate() } /** - * Test whether we cannot start an actor with the [Behavior.Companion.same] behavior. - */ - @Test - fun `should not start with same behavior`() { - val system = factory(same(), "test") - assertThrows { system.run() } - } - - /** - * Test whether we can start an actor with the [Behavior.Companion.stopped] behavior. + * Test whether we can start an actor with the [stopped] behavior. */ @Test fun `should start with stopped behavior`() { val system = factory(stopped(), "test") system.run() + system.terminate() } @@ -353,6 +363,7 @@ abstract class ActorSystemContract { system.run() assertEquals(1, counter) + system.terminate() } } diff --git a/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemFactoryContract.kt b/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemFactoryContract.kt index 55d70a84..565f4f4c 100644 --- a/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemFactoryContract.kt +++ b/odcsim-engine-tests/src/main/kotlin/com/atlarge/odcsim/engine/tests/ActorSystemFactoryContract.kt @@ -27,9 +27,10 @@ package com.atlarge.odcsim.engine.tests import com.atlarge.odcsim.ActorSystemFactory import com.atlarge.odcsim.empty import com.atlarge.odcsim.setup +import com.atlarge.odcsim.stopped import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows /** * A conformance test suite for implementors of the [ActorSystemFactory] interface. @@ -50,6 +51,7 @@ abstract class ActorSystemFactoryContract { val system = factory(empty(), name) assertEquals(name, system.name) + system.terminate() } /** @@ -57,9 +59,15 @@ abstract class ActorSystemFactoryContract { */ @Test fun `should create a system with correct root behavior`() { + var flag = false val factory = createFactory() - val system = factory(setup { throw UnsupportedOperationException() }, "test") + val system = factory(setup { + flag = true + stopped() + }, "test") - assertThrows { system.run(until = 10.0) } + system.run(until = 10.0) + system.terminate() + assertTrue(flag) } } -- cgit v1.2.3