diff options
| author | Fabian Mastenbroek <fabianishere@outlook.com> | 2018-07-19 15:52:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-19 15:52:04 +0200 |
| commit | d37a139b357ded9ba048c10ccad320a0d8412f0b (patch) | |
| tree | 4ae1d87574e30862303947f9f78152f5524ef75f /opendc-kernel-omega | |
| parent | 28974348022dc7c339359ffb099ec55d2c76e457 (diff) | |
refactor: Improve exception handling in processes (#29)
This change will improve exception handling of processes.
At the moment, when a process throws an uncaught exception, the kernel will catch and log the exception, stop the offending process and then continue. This approach however might cause the user to overlook possible exceptions in processes and does not give any ability to the user for handling these exception.
This change modifies the kernel implementation and specification such that the `step()` method (and consequently `run()`) must propagate uncaught exceptions that occur in processes. This allows the caller to control the way exceptions are handled.
Diffstat (limited to 'opendc-kernel-omega')
| -rw-r--r-- | opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaSimulation.kt | 7 | ||||
| -rw-r--r-- | opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt | 5 |
2 files changed, 4 insertions, 8 deletions
diff --git a/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaSimulation.kt b/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaSimulation.kt index fbb4a270..03861864 100644 --- a/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaSimulation.kt +++ b/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaSimulation.kt @@ -430,11 +430,6 @@ internal class OmegaSimulation<M>(bootstrap: Bootstrap<M>) : Simulation<M>, Boot * * @param exception The exception to resume with. */ - override fun resumeWithException(exception: Throwable) { - // Deregister process from registry in order to have the GC collect this context:w - registry.remove(process) - - logger.error(exception) { "An exception occurred during the execution of a process" } - } + override fun resumeWithException(exception: Throwable) = throw exception } } diff --git a/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt b/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt index 74d6e2de..b056837c 100644 --- a/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt +++ b/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt @@ -34,6 +34,7 @@ import kotlinx.coroutines.experimental.async import kotlinx.coroutines.experimental.channels.consumeEach import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows /** * This test suite checks for smoke when running a large amount of simulations. @@ -98,7 +99,7 @@ internal class SmokeTest { object CrashProcess : Process<Unit, Unit> { override val initialState = Unit override suspend fun Context<Unit, Unit>.run() { - TODO("This process should crash") + throw RuntimeException("This process should crash") } } @@ -116,7 +117,7 @@ internal class SmokeTest { } val simulation = OmegaKernel.create(bootstrap) - simulation.run() + assertThrows<RuntimeException> { simulation.run() } } class ModelProcess(private val value: Int) : Process<Boolean, Int> { |
