23
23
import org .junit .jupiter .api .Test ;
24
24
import org .junit .jupiter .api .condition .EnabledOnOs ;
25
25
import org .junit .jupiter .api .condition .OS ;
26
+
26
27
import org .springframework .beans .factory .annotation .Autowired ;
27
28
import org .springframework .boot .test .context .SpringBootTest ;
28
29
import org .springframework .grpc .autoconfigure .server .GrpcServerProperties ;
30
+ import org .springframework .grpc .client .ChannelBuilderOptions ;
29
31
import org .springframework .grpc .client .GrpcChannelFactory ;
30
32
import org .springframework .grpc .sample .proto .HelloReply ;
31
33
import org .springframework .grpc .sample .proto .HelloRequest ;
36
38
import org .springframework .test .context .ActiveProfiles ;
37
39
38
40
import io .grpc .ManagedChannel ;
39
- import io .grpc .StatusRuntimeException ;
40
41
import io .grpc .Status .Code ;
42
+ import io .grpc .StatusRuntimeException ;
43
+ import io .grpc .netty .NettyChannelBuilder ;
41
44
42
45
/**
43
46
* More detailed integration tests for {@link GrpcServerFactory gRPC server factories} and
@@ -51,7 +54,7 @@ class ServerWithInProcessChannel {
51
54
52
55
@ Test
53
56
void servesResponseToClient (@ Autowired GrpcChannelFactory channels ) {
54
- assertThatResponseIsServedToChannel (channels .createChannel ("0.0.0.0:0" ). build ( ));
57
+ assertThatResponseIsServedToChannel (channels .createChannel ("0.0.0.0:0" , ChannelBuilderOptions . defaults () ));
55
58
}
56
59
57
60
}
@@ -63,7 +66,7 @@ class ServerWithException {
63
66
@ Test
64
67
void specificErrorResponse (@ Autowired GrpcChannelFactory channels ) {
65
68
SimpleGrpc .SimpleBlockingStub client = SimpleGrpc
66
- .newBlockingStub (channels .createChannel ("0.0.0.0:0" ). build ( ));
69
+ .newBlockingStub (channels .createChannel ("0.0.0.0:0" , ChannelBuilderOptions . defaults () ));
67
70
assertThat (assertThrows (StatusRuntimeException .class ,
68
71
() -> client .sayHello (HelloRequest .newBuilder ().setName ("error" ).build ()))
69
72
.getStatus ()
@@ -73,7 +76,7 @@ void specificErrorResponse(@Autowired GrpcChannelFactory channels) {
73
76
@ Test
74
77
void defaultErrorResponseIsUnknown (@ Autowired GrpcChannelFactory channels ) {
75
78
SimpleGrpc .SimpleBlockingStub client = SimpleGrpc
76
- .newBlockingStub (channels .createChannel ("0.0.0.0:0" ). build ( ));
79
+ .newBlockingStub (channels .createChannel ("0.0.0.0:0" , ChannelBuilderOptions . defaults () ));
77
80
assertThat (assertThrows (StatusRuntimeException .class ,
78
81
() -> client .sayHello (HelloRequest .newBuilder ().setName ("internal" ).build ()))
79
82
.getStatus ()
@@ -89,7 +92,7 @@ class ServerWithUnhandledException {
89
92
@ Test
90
93
void specificErrorResponse (@ Autowired GrpcChannelFactory channels ) {
91
94
SimpleGrpc .SimpleBlockingStub client = SimpleGrpc
92
- .newBlockingStub (channels .createChannel ("0.0.0.0:0" ). build ( ));
95
+ .newBlockingStub (channels .createChannel ("0.0.0.0:0" , ChannelBuilderOptions . defaults () ));
93
96
assertThat (assertThrows (StatusRuntimeException .class ,
94
97
() -> client .sayHello (HelloRequest .newBuilder ().setName ("error" ).build ()))
95
98
.getStatus ()
@@ -99,7 +102,7 @@ void specificErrorResponse(@Autowired GrpcChannelFactory channels) {
99
102
@ Test
100
103
void defaultErrorResponseIsUnknown (@ Autowired GrpcChannelFactory channels ) {
101
104
SimpleGrpc .SimpleBlockingStub client = SimpleGrpc
102
- .newBlockingStub (channels .createChannel ("0.0.0.0:0" ). build ( ));
105
+ .newBlockingStub (channels .createChannel ("0.0.0.0:0" , ChannelBuilderOptions . defaults () ));
103
106
assertThat (assertThrows (StatusRuntimeException .class ,
104
107
() -> client .sayHello (HelloRequest .newBuilder ().setName ("internal" ).build ()))
105
108
.getStatus ()
@@ -116,7 +119,8 @@ class ServerWithAnyIPv4AddressAndRandomPort {
116
119
@ Test
117
120
void servesResponseToClientWithAnyIPv4AddressAndRandomPort (@ Autowired GrpcChannelFactory channels ,
118
121
@ LocalGrpcPort int port ) {
119
- assertThatResponseIsServedToChannel (channels .createChannel ("0.0.0.0:" + port ).build ());
122
+ assertThatResponseIsServedToChannel (
123
+ channels .createChannel ("0.0.0.0:" + port , ChannelBuilderOptions .defaults ()));
120
124
}
121
125
122
126
}
@@ -129,7 +133,8 @@ class ServerWithAnyIPv6AddressAndRandomPort {
129
133
@ Test
130
134
void servesResponseToClientWithAnyIPv4AddressAndRandomPort (@ Autowired GrpcChannelFactory channels ,
131
135
@ LocalGrpcPort int port ) {
132
- assertThatResponseIsServedToChannel (channels .createChannel ("0.0.0.0:" + port ).build ());
136
+ assertThatResponseIsServedToChannel (
137
+ channels .createChannel ("0.0.0.0:" + port , ChannelBuilderOptions .defaults ()));
133
138
}
134
139
135
140
}
@@ -142,7 +147,8 @@ class ServerWithLocalhostAndRandomPort {
142
147
@ Test
143
148
void servesResponseToClientWithLocalhostAndRandomPort (@ Autowired GrpcChannelFactory channels ,
144
149
@ LocalGrpcPort int port ) {
145
- assertThatResponseIsServedToChannel (channels .createChannel ("127.0.0.1:" + port ).build ());
150
+ assertThatResponseIsServedToChannel (
151
+ channels .createChannel ("127.0.0.1:" + port , ChannelBuilderOptions .defaults ()));
146
152
}
147
153
148
154
}
@@ -156,7 +162,8 @@ class ServerConfiguredWithStaticClientChannel {
156
162
157
163
@ Test
158
164
void servesResponseToClientWithConfiguredChannel (@ Autowired GrpcChannelFactory channels ) {
159
- assertThatResponseIsServedToChannel (channels .createChannel ("test-channel" ).build ());
165
+ assertThatResponseIsServedToChannel (
166
+ channels .createChannel ("test-channel" , ChannelBuilderOptions .defaults ()));
160
167
}
161
168
162
169
}
@@ -169,7 +176,8 @@ class ServerWithUnixDomain {
169
176
170
177
@ Test
171
178
void clientChannelWithUnixDomain (@ Autowired GrpcChannelFactory channels ) {
172
- assertThatResponseIsServedToChannel (channels .createChannel ("unix:unix-test-channel" ).build ());
179
+ assertThatResponseIsServedToChannel (channels .createChannel ("unix:unix-test-channel" ,
180
+ ChannelBuilderOptions .defaults ().<NettyChannelBuilder >withCustomizer ((__ , b ) -> b .usePlaintext ())));
173
181
}
174
182
175
183
}
@@ -185,7 +193,8 @@ class ServerWithSsl {
185
193
186
194
@ Test
187
195
void clientChannelWithSsl (@ Autowired GrpcChannelFactory channels ) {
188
- assertThatResponseIsServedToChannel (channels .createChannel ("test-channel" ).build ());
196
+ assertThatResponseIsServedToChannel (
197
+ channels .createChannel ("test-channel" , ChannelBuilderOptions .defaults ()));
189
198
}
190
199
191
200
}
@@ -203,7 +212,8 @@ class ServerWithClientAuth {
203
212
204
213
@ Test
205
214
void clientChannelWithSsl (@ Autowired GrpcChannelFactory channels ) {
206
- assertThatResponseIsServedToChannel (channels .createChannel ("test-channel" ).build ());
215
+ assertThatResponseIsServedToChannel (
216
+ channels .createChannel ("test-channel" , ChannelBuilderOptions .defaults ()));
207
217
}
208
218
209
219
}
0 commit comments