-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKillRuntime.kt
59 lines (52 loc) · 2.08 KB
/
KillRuntime.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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.CounterClient
import dev.restate.sdktesting.contracts.CounterDefinitions
import dev.restate.sdktesting.infra.*
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.extension.RegisterExtension
@Tag("always-suspending")
@Tag("only-single-node")
class KillRuntime {
companion object {
@JvmStatic
@RegisterExtension
val deployerExt: RestateDeployerExtension = RestateDeployerExtension {
withServiceSpec(ServiceSpec.defaultBuilder().withServices(CounterDefinitions.SERVICE_NAME))
}
}
@Timeout(value = 60, unit = TimeUnit.SECONDS)
@Test
fun startAndKillRuntimeRetainsTheState(
@InjectClient ingressClient: Client,
@InjectContainerHandle(RESTATE_RUNTIME) runtimeHandle: ContainerHandle
) = runTest {
var counterClient = CounterClient.fromClient(ingressClient, "my-key")
val res1 = counterClient.add(1, idempotentCallOptions())
assertThat(res1.oldValue).isEqualTo(0)
assertThat(res1.newValue).isEqualTo(1)
// Stop and start the runtime
runtimeHandle.killAndRestart()
// We need a new client, because on restarts docker might mess up the exposed ports. NotFunky
// but true...
counterClient =
CounterClient.fromClient(
Client.connect("http://127.0.0.1:${runtimeHandle.getMappedPort(8080)!!}"), "my-key")
val res2 = counterClient.add(2, idempotentCallOptions())
assertThat(res2.oldValue).isEqualTo(1)
assertThat(res2.newValue).isEqualTo(3)
}
}