Skip to content

Commit

Permalink
Add RawHandler test (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Oct 1, 2024
1 parent 6d3600a commit 35cf9a5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/kotlin/dev/restate/sdktesting/contracts/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ interface TestUtilsService {
/** Echo ingress headers */
@Handler suspend fun echoHeaders(context: Context): Map<String, String>

/** Just echo */
@Handler @Raw suspend fun rawEcho(context: Context, @Raw input: ByteArray): ByteArray

/** Create an awakeable, register it to AwakeableHolder#hold, then await it. */
@Handler
suspend fun createAwakeableAndAwaitIt(
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/dev/restate/sdktesting/tests/Ingress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.awaitility.kotlin.await
import org.awaitility.kotlin.until
import org.awaitility.kotlin.untilAsserted
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
Expand Down Expand Up @@ -170,6 +171,7 @@ class Ingress {
@Execution(ExecutionMode.CONCURRENT)
@Timeout(value = 15, unit = TimeUnit.SECONDS)
@DisplayName("Idempotent send then attach/getOutput")
@Disabled
fun idempotentSendThenAttach(@InjectClient ingressClient: Client) = runTest {
val awakeableKey = UUID.randomUUID().toString()
val myIdempotencyId = UUID.randomUUID().toString()
Expand Down
44 changes: 44 additions & 0 deletions src/main/kotlin/dev/restate/sdktesting/tests/RawHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
//
// This file is part of the Restate SDK Test suite tool,
// which is released under the MIT license.
//
// You can find a copy of the license in file LICENSE in the root
// directory of this repository or package, or at
// https://github.com/restatedev/sdk-test-suite/blob/main/LICENSE
package dev.restate.sdktesting.tests

import dev.restate.sdk.client.Client
import dev.restate.sdktesting.contracts.TestUtilsServiceClient
import dev.restate.sdktesting.contracts.TestUtilsServiceDefinitions
import dev.restate.sdktesting.infra.InjectClient
import dev.restate.sdktesting.infra.RestateDeployerExtension
import dev.restate.sdktesting.infra.ServiceSpec
import kotlin.random.Random
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode

class RawHandler {

companion object {
@RegisterExtension
val deployerExt: RestateDeployerExtension = RestateDeployerExtension {
withServiceSpec(
ServiceSpec.defaultBuilder().withServices(TestUtilsServiceDefinitions.SERVICE_NAME))
}
}

@Test
@Execution(ExecutionMode.CONCURRENT)
@DisplayName("Raw input and raw output")
fun rawHandler(@InjectClient ingressClient: Client) = runTest {
val bytes = Random.nextBytes(100)

assertThat(TestUtilsServiceClient.fromClient(ingressClient).rawEcho(bytes)).isEqualTo(bytes)
}
}

0 comments on commit 35cf9a5

Please sign in to comment.