forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 3
/
HelloWorldServiceTest.java
51 lines (40 loc) · 1.55 KB
/
HelloWorldServiceTest.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
package io.quarkus.grpc.examples.hello;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import examples.GreeterGrpc;
import examples.HelloReply;
import examples.HelloRequest;
import examples.MutinyGreeterGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.quarkus.test.junit.QuarkusTest;
@QuarkusTest
class HelloWorldServiceTest {
private ManagedChannel channel;
@BeforeEach
void setUp() {
channel = ManagedChannelBuilder.forAddress("localhost", 9001).usePlaintext().build();
}
@AfterEach
public void tearDown() throws InterruptedException {
channel.shutdown();
channel.awaitTermination(10, TimeUnit.SECONDS);
}
@Test
public void testHelloWorldServiceUsingBlockingStub() {
GreeterGrpc.GreeterBlockingStub client = GreeterGrpc.newBlockingStub(channel);
HelloReply reply = client
.sayHello(HelloRequest.newBuilder().setName("neo-blocking").build());
assertThat(reply.getMessage()).isEqualTo("Hello neo-blocking");
}
@Test
public void testHelloWorldServiceUsingMutinyStub() {
HelloReply reply = MutinyGreeterGrpc.newMutinyStub(channel)
.sayHello(HelloRequest.newBuilder().setName("neo-blocking").build()).await().atMost(Duration.ofSeconds(5));
assertThat(reply.getMessage()).isEqualTo("Hello neo-blocking");
}
}