33
33
import reactor .netty .BaseHttpTest ;
34
34
import reactor .netty .NettyPipeline ;
35
35
import reactor .netty .resources .ConnectionProvider ;
36
+ import reactor .util .Logger ;
37
+ import reactor .util .Loggers ;
36
38
37
39
import javax .net .ssl .SSLException ;
38
40
import java .security .cert .CertificateException ;
55
57
*/
56
58
class Http2ConnectionLivenessHandlerTest extends BaseHttpTest {
57
59
60
+ private static final Logger log = Loggers .getLogger (Http2ConnectionLivenessHandlerTest .class );
61
+
58
62
static SslContext sslServer ;
59
63
static SslContext sslClient ;
60
64
@@ -199,6 +203,7 @@ void closeConnectionInPoolIfPingFrameDelayed() {
199
203
.bindNow ();
200
204
201
205
ConnectionProvider pool = ConnectionProvider .create ("closeConnectionInPoolIfPingFrameDelayed" , 1 );
206
+
202
207
Channel channel = createClient (pool , disposableServer ::address )
203
208
.protocol (H2 )
204
209
.keepAlive (true )
@@ -217,6 +222,8 @@ void closeConnectionInPoolIfPingFrameDelayed() {
217
222
218
223
assertThat (handler .getReceivedPingTimes ()).hasSize (1 );
219
224
assertThat (channel .parent ().isOpen ()).isFalse ();
225
+
226
+ pool .dispose ();
220
227
}
221
228
222
229
@ Test
@@ -255,8 +262,8 @@ void ackPingFrameWithinInterval() {
255
262
Mono .delay (Duration .ofSeconds (10 ))
256
263
.block ();
257
264
258
- assertThat (handler .getReceivedPingTimes ()).hasSizeGreaterThanOrEqualTo (2 );
259
265
assertThat (channel .parent ().isOpen ()).isTrue ();
266
+ assertThat (handler .getReceivedPingTimes ()).hasSizeGreaterThanOrEqualTo (2 );
260
267
}
261
268
262
269
@ Test
@@ -279,7 +286,11 @@ void connectionRetentionInPoolOnPingFrameAck() {
279
286
.handle ((req , resp ) -> resp .sendString (Mono .just ("Test" )))
280
287
.bindNow ();
281
288
282
- ConnectionProvider pool = ConnectionProvider .create ("connectionRetentionInPoolOnPingFrameAck" , 1 );
289
+ ConnectionProvider pool = ConnectionProvider .builder ("connectionRetentionInPoolOnPingFrameAck" )
290
+ .maxConnections (10 )
291
+ .maxIdleTime (Duration .ofSeconds (10 ))
292
+ .maxLifeTime (Duration .ofSeconds (10 ))
293
+ .build ();
283
294
Channel channel = createClient (pool , disposableServer ::address )
284
295
.protocol (H2 )
285
296
.keepAlive (true )
@@ -296,8 +307,10 @@ void connectionRetentionInPoolOnPingFrameAck() {
296
307
Mono .delay (Duration .ofSeconds (10 ))
297
308
.block ();
298
309
299
- assertThat (handler .getReceivedPingTimes ()).hasSizeGreaterThanOrEqualTo (2 );
300
310
assertThat (channel .parent ().isOpen ()).isTrue ();
311
+ assertThat (handler .getReceivedPingTimes ()).hasSizeGreaterThanOrEqualTo (2 );
312
+
313
+ pool .dispose ();
301
314
}
302
315
303
316
private static final class Http2PingFrameHandler extends SimpleChannelInboundHandler <Http2PingFrame > {
@@ -309,7 +322,9 @@ private static final class Http2PingFrameHandler extends SimpleChannelInboundHan
309
322
private Http2PingFrameHandler () {
310
323
this .consumer = (ctx , frame ) ->
311
324
ctx .writeAndFlush (new DefaultHttp2PingFrame (frame .content (), true ))
312
- .addListener (ChannelFutureListener .CLOSE_ON_FAILURE );
325
+ .addListener ((listener ) -> {
326
+ log .info ("Wrote ping ack. data: {}, result: {}" , frame .content (), listener .isSuccess ());
327
+ });
313
328
}
314
329
315
330
private Http2PingFrameHandler (BiConsumer <ChannelHandlerContext , Http2PingFrame > consumer ) {
0 commit comments