summaryrefslogtreecommitdiff
path: root/opendc-faas/opendc-faas-service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-faas/opendc-faas-service/src/test')
-rw-r--r--opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt179
1 files changed, 94 insertions, 85 deletions
diff --git a/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt b/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt
index 9676744b..72a5f2c8 100644
--- a/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt
+++ b/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt
@@ -41,136 +41,145 @@ import java.util.UUID
* Test suite for the [FaaSService] implementation.
*/
internal class FaaSServiceTest {
-
@Test
- fun testClientState() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
-
- val client = assertDoesNotThrow { service.newClient() }
- assertDoesNotThrow { client.close() }
-
- assertThrows<IllegalStateException> { client.queryFunctions() }
- assertThrows<IllegalStateException> { client.newFunction("test", 128) }
- assertThrows<IllegalStateException> { client.invoke("test") }
- assertThrows<IllegalStateException> { client.findFunction(UUID.randomUUID()) }
- assertThrows<IllegalStateException> { client.findFunction("name") }
- }
+ fun testClientState() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+
+ val client = assertDoesNotThrow { service.newClient() }
+ assertDoesNotThrow { client.close() }
+
+ assertThrows<IllegalStateException> { client.queryFunctions() }
+ assertThrows<IllegalStateException> { client.newFunction("test", 128) }
+ assertThrows<IllegalStateException> { client.invoke("test") }
+ assertThrows<IllegalStateException> { client.findFunction(UUID.randomUUID()) }
+ assertThrows<IllegalStateException> { client.findFunction("name") }
+ }
@Test
- fun testClientInvokeUnknown() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+ fun testClientInvokeUnknown() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
- val client = service.newClient()
+ val client = service.newClient()
- assertThrows<IllegalArgumentException> { client.invoke("test") }
- }
+ assertThrows<IllegalArgumentException> { client.invoke("test") }
+ }
@Test
- fun testClientFunctionCreation() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+ fun testClientFunctionCreation() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
- val client = service.newClient()
+ val client = service.newClient()
- val function = client.newFunction("test", 128)
+ val function = client.newFunction("test", 128)
- assertEquals("test", function.name)
- }
+ assertEquals("test", function.name)
+ }
@Test
- fun testClientFunctionQuery() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+ fun testClientFunctionQuery() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
- val client = service.newClient()
+ val client = service.newClient()
- assertEquals(emptyList<FaaSFunction>(), client.queryFunctions())
+ assertEquals(emptyList<FaaSFunction>(), client.queryFunctions())
- val function = client.newFunction("test", 128)
+ val function = client.newFunction("test", 128)
- assertEquals(listOf(function), client.queryFunctions())
- }
+ assertEquals(listOf(function), client.queryFunctions())
+ }
@Test
- fun testClientFunctionFindById() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+ fun testClientFunctionFindById() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
- val client = service.newClient()
+ val client = service.newClient()
- assertEquals(emptyList<FaaSFunction>(), client.queryFunctions())
+ assertEquals(emptyList<FaaSFunction>(), client.queryFunctions())
- val function = client.newFunction("test", 128)
+ val function = client.newFunction("test", 128)
- assertNotNull(client.findFunction(function.uid))
- }
+ assertNotNull(client.findFunction(function.uid))
+ }
@Test
- fun testClientFunctionFindByName() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+ fun testClientFunctionFindByName() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
- val client = service.newClient()
+ val client = service.newClient()
- assertEquals(emptyList<FaaSFunction>(), client.queryFunctions())
+ assertEquals(emptyList<FaaSFunction>(), client.queryFunctions())
- val function = client.newFunction("test", 128)
+ val function = client.newFunction("test", 128)
- assertNotNull(client.findFunction(function.name))
- }
+ assertNotNull(client.findFunction(function.name))
+ }
@Test
- fun testClientFunctionDuplicateName() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+ fun testClientFunctionDuplicateName() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
- val client = service.newClient()
+ val client = service.newClient()
- client.newFunction("test", 128)
+ client.newFunction("test", 128)
- assertThrows<IllegalArgumentException> { client.newFunction("test", 128) }
- }
+ assertThrows<IllegalArgumentException> { client.newFunction("test", 128) }
+ }
@Test
- fun testClientFunctionDelete() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
-
- val client = service.newClient()
- val function = client.newFunction("test", 128)
- assertNotNull(client.findFunction(function.uid))
- function.delete()
- assertNull(client.findFunction(function.uid))
-
- // Delete should be idempotent
- function.delete()
- }
+ fun testClientFunctionDelete() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+
+ val client = service.newClient()
+ val function = client.newFunction("test", 128)
+ assertNotNull(client.findFunction(function.uid))
+ function.delete()
+ assertNull(client.findFunction(function.uid))
+
+ // Delete should be idempotent
+ function.delete()
+ }
@Test
- fun testClientFunctionCannotInvokeDeleted() = runSimulation {
- val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
+ fun testClientFunctionCannotInvokeDeleted() =
+ runSimulation {
+ val service = FaaSService(dispatcher, mockk(), mockk(), mockk())
- val client = service.newClient()
- val function = client.newFunction("test", 128)
- assertNotNull(client.findFunction(function.uid))
- function.delete()
+ val client = service.newClient()
+ val function = client.newFunction("test", 128)
+ assertNotNull(client.findFunction(function.uid))
+ function.delete()
- assertThrows<IllegalStateException> { function.invoke() }
- }
+ assertThrows<IllegalStateException> { function.invoke() }
+ }
@Test
- fun testClientFunctionInvoke() = runSimulation {
- val deployer = mockk<FunctionDeployer>()
- val service = FaaSService(dispatcher, deployer, mockk(), mockk(relaxUnitFun = true))
+ fun testClientFunctionInvoke() =
+ runSimulation {
+ val deployer = mockk<FunctionDeployer>()
+ val service = FaaSService(dispatcher, deployer, mockk(), mockk(relaxUnitFun = true))
- every { deployer.deploy(any(), any()) } answers {
- object : FunctionInstance {
- override val state: FunctionInstanceState = FunctionInstanceState.Idle
- override val function: FunctionObject = it.invocation.args[0] as FunctionObject
+ every { deployer.deploy(any(), any()) } answers {
+ object : FunctionInstance {
+ override val state: FunctionInstanceState = FunctionInstanceState.Idle
+ override val function: FunctionObject = it.invocation.args[0] as FunctionObject
- override suspend fun invoke() {}
+ override suspend fun invoke() {}
- override fun close() {}
+ override fun close() {}
+ }
}
- }
- val client = service.newClient()
- val function = client.newFunction("test", 128)
+ val client = service.newClient()
+ val function = client.newFunction("test", 128)
- function.invoke()
- }
+ function.invoke()
+ }
}