From 0c1a4680bea79530fe8199c9ca6d98e4de996297 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Thu, 18 Jul 2024 14:05:12 +0200 Subject: [PATCH 1/2] Test ingress attach/getOutput with idempotency key --- .../dev/restate/e2e/runtime/IngressTest.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt b/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt index 5a50e9fa..121a294d 100644 --- a/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt +++ b/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt @@ -21,6 +21,7 @@ import dev.restate.sdk.JsonSerdes import dev.restate.sdk.client.CallRequestOptions import dev.restate.sdk.client.Client import dev.restate.sdk.client.SendResponse.SendStatus +import dev.restate.sdk.common.Target import java.net.URL import java.util.* import java.util.concurrent.TimeUnit @@ -195,6 +196,51 @@ class IngressTest { assertThat(invocationHandle.output.value).isEqualTo(response) } + @Test + @Execution(ExecutionMode.CONCURRENT) + @Timeout(value = 15, unit = TimeUnit.SECONDS) + @DisplayName("Idempotent send then attach/getOutput") + fun idempotentSendThenAttachWIthIdempotencyKey(@InjectClient ingressClient: Client) { + val awakeableKey = UUID.randomUUID().toString() + val myIdempotencyId = UUID.randomUUID().toString() + val response = "response" + + // Send request + val echoClient = EchoClient.fromClient(ingressClient) + assertThat( + echoClient + .send() + .blockThenEcho(awakeableKey, CallRequestOptions().withIdempotency(myIdempotencyId)) + .status) + .isEqualTo(SendStatus.ACCEPTED) + + val invocationHandle = + ingressClient.idempotentInvocationHandle( + Target.service(EchoDefinitions.SERVICE_NAME, "blockThenEcho"), + myIdempotencyId, + JsonSerdes.STRING) + + // Attach to request + val blockedFut = invocationHandle.attachAsync() + + // Get output throws exception + assertThat(invocationHandle.output.isReady).isFalse() + + // Blocked fut should still be blocked + assertThat(blockedFut).isNotDone + + // Unblock + val awakeableHolderClient = AwakeableHolderClient.fromClient(ingressClient, awakeableKey) + await until { awakeableHolderClient.hasAwakeable() } + awakeableHolderClient.unlock(response) + + // Attach should be completed + assertThat(blockedFut.get()).isEqualTo(response) + + // Invoke get output + assertThat(invocationHandle.output.value).isEqualTo(response) + } + @Test @Execution(ExecutionMode.CONCURRENT) @Timeout(value = 15, unit = TimeUnit.SECONDS) From c761d9ae3534e732595aa435e99cd9c179f91bd4 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Mon, 22 Jul 2024 14:44:56 +0200 Subject: [PATCH 2/2] Little comment --- tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt b/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt index 121a294d..205856f0 100644 --- a/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt +++ b/tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt @@ -178,7 +178,7 @@ class IngressTest { // Attach to request val blockedFut = invocationHandle.attachAsync() - // Get output throws exception + // Output is not ready yet assertThat(invocationHandle.output.isReady).isFalse() // Blocked fut should still be blocked @@ -223,7 +223,7 @@ class IngressTest { // Attach to request val blockedFut = invocationHandle.attachAsync() - // Get output throws exception + // Output is not ready yet assertThat(invocationHandle.output.isReady).isFalse() // Blocked fut should still be blocked