|
| 1 | +package at.ac.uibk.dps.cirrina.runtime |
| 2 | + |
| 3 | +import at.ac.uibk.dps.cirrina.cirrina.Runtime |
| 4 | +import at.ac.uibk.dps.cirrina.data.DefaultDescriptions |
| 5 | +import at.ac.uibk.dps.cirrina.execution.`object`.event.Event |
| 6 | +import at.ac.uibk.dps.cirrina.execution.`object`.event.EventHandler |
| 7 | +import at.ac.uibk.dps.cirrina.execution.service.RandomServiceImplementationSelector |
| 8 | +import at.ac.uibk.dps.cirrina.execution.service.ServiceImplementationBuilder |
| 9 | +import at.ac.uibk.dps.cirrina.utils.TestUtils.loggingOpenTelemetry |
| 10 | +import at.ac.uibk.dps.cirrina.utils.TestUtils.mockPersistentContext |
| 11 | +import java.time.Duration |
| 12 | +import org.junit.jupiter.api.Test |
| 13 | +import org.junit.jupiter.api.assertDoesNotThrow |
| 14 | +import org.junit.jupiter.api.assertTimeout |
| 15 | + |
| 16 | +class NoopTest { |
| 17 | + |
| 18 | + @Test |
| 19 | + fun testNoopExecute() { |
| 20 | + // Must finish within five seconds |
| 21 | + assertTimeout(Duration.ofSeconds(5)) { |
| 22 | + // Should not throw any exception |
| 23 | + assertDoesNotThrow { |
| 24 | + // Mock the event handler |
| 25 | + val mockEventHandler = |
| 26 | + object : EventHandler() { |
| 27 | + override fun close() {} |
| 28 | + |
| 29 | + override fun sendEvent(event: Event, source: String) = propagateEvent(event) |
| 30 | + |
| 31 | + override fun subscribe(topic: String) {} |
| 32 | + |
| 33 | + override fun unsubscribe(topic: String) {} |
| 34 | + |
| 35 | + override fun subscribe(source: String, subject: String) {} |
| 36 | + |
| 37 | + override fun unsubscribe(source: String, subject: String) {} |
| 38 | + } |
| 39 | + |
| 40 | + // Mock the persistent context |
| 41 | + val mockPersistentContext = mockPersistentContext() |
| 42 | + |
| 43 | + // Create a map from service types to service implementations |
| 44 | + val services = ServiceImplementationBuilder.from(listOf()).build() |
| 45 | + val serviceImplementationSelector = RandomServiceImplementationSelector(services) |
| 46 | + |
| 47 | + // Create and run the runtime using a single state machine. |
| 48 | + Runtime( |
| 49 | + loggingOpenTelemetry(), |
| 50 | + serviceImplementationSelector, |
| 51 | + mockEventHandler, |
| 52 | + mockPersistentContext, |
| 53 | + ) |
| 54 | + .run(DefaultDescriptions.noop, listOf("stateMachine")) |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments