|
16 | 16 |
|
17 | 17 | package net.devh.boot.grpc.test.setup;
|
18 | 18 |
|
19 |
| -import static io.grpc.Status.DEADLINE_EXCEEDED; |
20 |
| -import static net.devh.boot.grpc.test.util.GrpcAssertions.assertStatus; |
21 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | 19 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
23 | 20 | import static org.junit.jupiter.api.Assertions.assertNull;
|
24 | 21 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
30 | 27 | import org.springframework.test.annotation.DirtiesContext;
|
31 | 28 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
32 | 29 |
|
33 |
| -import io.grpc.StatusRuntimeException; |
34 | 30 | import io.grpc.internal.testing.StreamRecorder;
|
35 | 31 | import io.grpc.stub.StreamObserver;
|
36 | 32 | import lombok.SneakyThrows;
|
|
43 | 39 | /**
|
44 | 40 | * These tests check the property {@link GrpcChannelProperties#getDeadline()}.
|
45 | 41 | */
|
46 |
| -@Slf4j |
47 |
| -@SpringBootTest(properties = { |
48 |
| - "grpc.client.GLOBAL.address=localhost:9090", |
49 |
| - "grpc.client.GLOBAL.deadline=1s", |
50 |
| - "grpc.client.GLOBAL.negotiationType=PLAINTEXT", |
51 |
| -}) |
52 |
| -@SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class}) |
53 |
| -public class DeadlineTests extends AbstractSimpleServerClientTest { |
| 42 | +public class DeadlineTests { |
54 | 43 |
|
55 |
| - @Test |
56 |
| - @SneakyThrows |
57 |
| - @DirtiesContext |
58 |
| - void testServiceStubDeadlineEnabledAndSuccessful() { |
59 |
| - log.info("--- Starting test with unsuccessful and than successful call ---"); |
60 |
| - final StreamRecorder<SomeType> streamRecorder1 = StreamRecorder.create(); |
61 |
| - StreamObserver<SomeType> echo1 = this.testServiceStub.echo(streamRecorder1); |
62 |
| - assertThrows(ExecutionException.class, () -> streamRecorder1.firstValue().get()); |
| 44 | + @Slf4j |
| 45 | + @SpringBootTest(properties = { |
| 46 | + "grpc.client.GLOBAL.address=localhost:9090", |
| 47 | + "grpc.client.GLOBAL.deadline=1s", |
| 48 | + "grpc.client.GLOBAL.negotiationType=PLAINTEXT", |
| 49 | + }) |
| 50 | + @SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class}) |
| 51 | + static class DeadlineSetupTest extends AbstractSimpleServerClientTest { |
| 52 | + @Test |
| 53 | + @SneakyThrows |
| 54 | + @DirtiesContext |
| 55 | + void testServiceStubDeadlineEnabledAndSuccessful() { |
| 56 | + log.info("--- Starting test with unsuccessful and than successful call ---"); |
| 57 | + final StreamRecorder<SomeType> streamRecorder1 = StreamRecorder.create(); |
| 58 | + StreamObserver<SomeType> echo1 = this.testServiceStub.echo(streamRecorder1); |
| 59 | + assertThrows(ExecutionException.class, () -> streamRecorder1.firstValue().get()); |
63 | 60 |
|
64 |
| - final StreamRecorder<SomeType> streamRecorder2 = StreamRecorder.create(); |
65 |
| - StreamObserver<SomeType> echo2 = testServiceStub.echo(streamRecorder2); |
66 |
| - echo2.onNext(SomeType.getDefaultInstance()); |
67 |
| - assertNull(streamRecorder2.getError()); |
68 |
| - assertNotNull(streamRecorder2.firstValue().get().getVersion()); |
69 |
| - log.info("--- Test completed --- "); |
| 61 | + final StreamRecorder<SomeType> streamRecorder2 = StreamRecorder.create(); |
| 62 | + StreamObserver<SomeType> echo2 = testServiceStub.echo(streamRecorder2); |
| 63 | + echo2.onNext(SomeType.getDefaultInstance()); |
| 64 | + assertNull(streamRecorder2.getError()); |
| 65 | + assertNotNull(streamRecorder2.firstValue().get().getVersion()); |
| 66 | + log.info("--- Test completed --- "); |
| 67 | + } |
70 | 68 | }
|
71 | 69 |
|
72 |
| - @Test |
73 |
| - @SneakyThrows |
74 |
| - @DirtiesContext |
75 |
| - void testServiceStubDeadlineEnabledAndUnsuccessful() { |
76 |
| - log.info("--- Starting test with unsuccessful call ---"); |
77 |
| - final StreamRecorder<SomeType> streamRecorder = StreamRecorder.create(); |
78 |
| - this.testServiceStub.echo(streamRecorder); |
79 |
| - assertThrows(ExecutionException.class, () -> streamRecorder.firstValue().get()); |
80 |
| - assertNotNull(streamRecorder.getError()); |
81 |
| - assertEquals(StatusRuntimeException.class, streamRecorder.getError().getClass()); |
82 |
| - assertStatus(DEADLINE_EXCEEDED.getCode(), (StatusRuntimeException) streamRecorder.getError()); |
83 |
| - log.info("--- Test completed --- "); |
| 70 | + @Slf4j |
| 71 | + @SpringBootTest(properties = { |
| 72 | + "grpc.client.GLOBAL.address=localhost:9090", |
| 73 | + "grpc.client.GLOBAL.deadline=0s", |
| 74 | + "grpc.client.GLOBAL.negotiationType=PLAINTEXT", |
| 75 | + }) |
| 76 | + @SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class}) |
| 77 | + static class ZeroDeadlineSetupTest extends AbstractSimpleServerClientTest { |
84 | 78 | }
|
85 | 79 |
|
86 | 80 | }
|
0 commit comments