-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
MultipleStubsInjectionTest.java
102 lines (77 loc) · 3.63 KB
/
MultipleStubsInjectionTest.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package io.quarkus.grpc.client;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.Duration;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import io.grpc.Channel;
import io.grpc.examples.goodbyeworld.*;
import io.grpc.examples.helloworld.*;
import io.quarkus.grpc.GrpcClient;
import io.quarkus.grpc.server.services.GoodbyeService;
import io.quarkus.grpc.server.services.HelloService;
import io.quarkus.test.QuarkusUnitTest;
public class MultipleStubsInjectionTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer(
() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(MyConsumer.class,
MutinyGreeterGrpc.class, GreeterGrpc.class,
MutinyGreeterGrpc.MutinyGreeterStub.class,
HelloService.class, HelloRequest.class, HelloReply.class,
HelloReplyOrBuilder.class, HelloRequestOrBuilder.class,
MutinyFarewellGrpc.class, FarewellGrpc.class,
MutinyFarewellGrpc.MutinyFarewellStub.class,
GoodbyeService.class, GoodbyeRequest.class, GoodbyeReply.class,
GoodbyeReplyOrBuilder.class, GoodbyeRequestOrBuilder.class))
.withConfigurationResource("hello-config.properties");
@Inject
MyConsumer service;
@Test
public void test() {
String neo = service.invokeMutinyGreeter("neo-mutiny");
assertThat(neo).isEqualTo("Hello neo-mutiny");
neo = service.invokeBlockingGreeter("neo-blocking");
assertThat(neo).isEqualTo("Hello neo-blocking");
neo = service.invokeMutinyFarewell("neo-mutiny");
assertThat(neo).isEqualTo("Goodbye neo-mutiny");
neo = service.invokeBlockingFarewell("neo-blocking");
assertThat(neo).isEqualTo("Goodbye neo-blocking");
service.validateChannel();
}
@ApplicationScoped
static class MyConsumer {
@GrpcClient("hello-service")
MutinyGreeterGrpc.MutinyGreeterStub mutinyGreeter;
@GrpcClient("hello-service")
GreeterGrpc.GreeterBlockingStub blockingGreeter;
@GrpcClient("hello-service")
MutinyFarewellGrpc.MutinyFarewellStub mutinyFarewell;
@GrpcClient("hello-service")
FarewellGrpc.FarewellBlockingStub blockingFarewell;
@GrpcClient("hello-service-2")
Channel channel;
public String invokeMutinyGreeter(String s) {
return mutinyGreeter.sayHello(HelloRequest.newBuilder().setName(s).build())
.map(HelloReply::getMessage)
.await().atMost(Duration.ofSeconds(5));
}
public String invokeBlockingGreeter(String s) {
return blockingGreeter.sayHello(HelloRequest.newBuilder().setName(s).build()).getMessage();
}
public String invokeMutinyFarewell(String s) {
return mutinyFarewell.sayGoodbye(GoodbyeRequest.newBuilder().setName(s).build())
.map(GoodbyeReply::getMessage)
.await().atMost(Duration.ofSeconds(5));
}
public String invokeBlockingFarewell(String s) {
return blockingFarewell.sayGoodbye(GoodbyeRequest.newBuilder().setName(s).build()).getMessage();
}
public void validateChannel() {
assertThat(channel).isNotNull();
}
}
}