Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test ingress attach/getOutput with idempotency key #362

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -177,7 +178,52 @@ 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
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)
@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()

// Output is not ready yet
assertThat(invocationHandle.output.isReady).isFalse()

// Blocked fut should still be blocked
Expand Down