forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReactiveServiceTest.java
49 lines (37 loc) · 1.5 KB
/
ReactiveServiceTest.java
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
package com.example.reactive;
import static org.awaitility.Awaitility.await;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import io.quarkus.grpc.GrpcClient;
import io.quarkus.test.junit.QuarkusTest;
import io.smallrye.mutiny.subscription.Cancellable;
@QuarkusTest
public class ReactiveServiceTest {
public static final int TIMEOUT = 60;
@GrpcClient
ReactiveTest client;
@Test
@Timeout(TIMEOUT)
void shouldWatchAndAddMultipleTimes() {
List<String> collected = new CopyOnWriteArrayList<>();
Cancellable watch = client.watch(com.example.reactive.Test.Empty.getDefaultInstance())
.onFailure().invoke(Throwable::printStackTrace)
.subscribe().with(item -> collected.add(item.getText()));
List<String> expected = Collections.synchronizedList(new ArrayList<>());
for (int i = 0; i < 10; i++) {
String text = "hello world" + i;
expected.add(text);
client.add(com.example.reactive.Test.Item.newBuilder().setText(text).build())
.onFailure().invoke(Throwable::printStackTrace)
.await().atMost(Duration.ofSeconds(TIMEOUT / 6));
}
await().atMost(Duration.ofSeconds(TIMEOUT / 2))
.until(() -> collected.containsAll(expected));
watch.cancel();
}
}