31
31
import org .junit .jupiter .api .Test ;
32
32
import reactor .core .publisher .Mono ;
33
33
import reactor .netty .BaseHttpTest ;
34
- import reactor .netty .DisposableServer ;
35
34
import reactor .netty .NettyPipeline ;
36
35
import reactor .netty .resources .ConnectionProvider ;
37
36
56
55
*/
57
56
class Http2ConnectionLivenessHandlerTest extends BaseHttpTest {
58
57
59
- static SelfSignedCertificate ssc ;
60
58
static SslContext sslServer ;
61
59
static SslContext sslClient ;
62
60
63
61
@ BeforeAll
64
62
static void createSelfSignedCertificate () throws CertificateException , SSLException {
65
- ssc = new SelfSignedCertificate ();
63
+ SelfSignedCertificate ssc = new SelfSignedCertificate ();
66
64
sslServer = SslContextBuilder .forServer (ssc .certificate (), ssc .privateKey ())
67
65
.build ();
68
66
sslClient = SslContextBuilder .forClient ()
@@ -72,7 +70,7 @@ static void createSelfSignedCertificate() throws CertificateException, SSLExcept
72
70
73
71
@ Test
74
72
void successReceiveResponse () {
75
- DisposableServer disposableServer = createServer ()
73
+ disposableServer = createServer ()
76
74
.protocol (H2 )
77
75
.secure (spec -> spec .sslContext (sslServer ))
78
76
.handle ((req , resp ) -> resp .sendString (Mono .just ("Test" )))
@@ -93,7 +91,7 @@ void successReceiveResponse() {
93
91
void noPingCheckWhenNotConfigured () {
94
92
Http2PingFrameHandler handler = new Http2PingFrameHandler ();
95
93
96
- DisposableServer disposableServer = createServer ()
94
+ disposableServer = createServer ()
97
95
.protocol (H2 )
98
96
.maxKeepAliveRequests (1 )
99
97
.secure (spec -> spec .sslContext (sslServer ))
@@ -119,7 +117,7 @@ void noPingCheckWhenNotConfigured() {
119
117
.single ()
120
118
.block ();
121
119
122
- Mono .delay (Duration .ofMillis ( 100 ))
120
+ Mono .delay (Duration .ofSeconds ( 1 ))
123
121
.block ();
124
122
125
123
assertThat (handler .getReceivedPingTimes ()).isEmpty ();
@@ -137,7 +135,7 @@ void closeConnectionIfPingFrameDelayed() {
137
135
.subscribe ()
138
136
);
139
137
140
- DisposableServer disposableServer = createServer ()
138
+ disposableServer = createServer ()
141
139
.protocol (H2 )
142
140
.maxKeepAliveRequests (1 )
143
141
.secure (spec -> spec .sslContext (sslServer ))
@@ -166,7 +164,7 @@ void closeConnectionIfPingFrameDelayed() {
166
164
.single ()
167
165
.block ();
168
166
169
- Mono .delay (Duration .ofMillis ( 600 ))
167
+ Mono .delay (Duration .ofSeconds ( 2 ))
170
168
.block ();
171
169
172
170
assertThat (handler .getReceivedPingTimes ()).hasSize (1 );
@@ -184,7 +182,7 @@ void closeConnectionInPoolIfPingFrameDelayed() {
184
182
.subscribe ()
185
183
);
186
184
187
- DisposableServer disposableServer = createServer ()
185
+ disposableServer = createServer ()
188
186
.protocol (H2 )
189
187
.maxKeepAliveRequests (1 )
190
188
.secure (spec -> spec .sslContext (sslServer ))
@@ -214,7 +212,7 @@ void closeConnectionInPoolIfPingFrameDelayed() {
214
212
.single ()
215
213
.block ();
216
214
217
- Mono .delay (Duration .ofMillis ( 600 ))
215
+ Mono .delay (Duration .ofSeconds ( 2 ))
218
216
.block ();
219
217
220
218
assertThat (handler .getReceivedPingTimes ()).hasSize (1 );
@@ -225,7 +223,7 @@ void closeConnectionInPoolIfPingFrameDelayed() {
225
223
void ackPingFrameWithinInterval () {
226
224
Http2PingFrameHandler handler = new Http2PingFrameHandler ();
227
225
228
- DisposableServer disposableServer = createServer ()
226
+ disposableServer = createServer ()
229
227
.protocol (H2 )
230
228
.maxKeepAliveRequests (1 )
231
229
.secure (spec -> spec .sslContext (sslServer ))
@@ -246,15 +244,15 @@ void ackPingFrameWithinInterval() {
246
244
.keepAlive (true )
247
245
.secure (spec -> spec .sslContext (sslClient ))
248
246
.http2Settings (builder -> {
249
- builder .pingInterval (Duration .ofMillis ( 100 ));
247
+ builder .pingInterval (Duration .ofSeconds ( 1 ));
250
248
})
251
249
.get ()
252
250
.uri ("/" )
253
251
.responseConnection ((conn , receiver ) -> Mono .just (receiver .channel ()))
254
252
.single ()
255
253
.block ();
256
254
257
- Mono .delay (Duration .ofSeconds (1 ))
255
+ Mono .delay (Duration .ofSeconds (10 ))
258
256
.block ();
259
257
260
258
assertThat (handler .getReceivedPingTimes ()).hasSizeGreaterThanOrEqualTo (2 );
@@ -265,7 +263,7 @@ void ackPingFrameWithinInterval() {
265
263
void connectionRetentionInPoolOnPingFrameAck () {
266
264
Http2PingFrameHandler handler = new Http2PingFrameHandler ();
267
265
268
- DisposableServer disposableServer = createServer ()
266
+ disposableServer = createServer ()
269
267
.protocol (H2 )
270
268
.maxKeepAliveRequests (1 )
271
269
.secure (spec -> spec .sslContext (sslServer ))
@@ -287,15 +285,15 @@ void connectionRetentionInPoolOnPingFrameAck() {
287
285
.keepAlive (true )
288
286
.secure (spec -> spec .sslContext (sslClient ))
289
287
.http2Settings (builder -> {
290
- builder .pingInterval (Duration .ofMillis ( 100 ));
288
+ builder .pingInterval (Duration .ofSeconds ( 1 ));
291
289
})
292
290
.get ()
293
291
.uri ("/" )
294
292
.responseConnection ((conn , receiver ) -> Mono .just (receiver .channel ()))
295
293
.single ()
296
294
.block ();
297
295
298
- Mono .delay (Duration .ofSeconds (1 ))
296
+ Mono .delay (Duration .ofSeconds (10 ))
299
297
.block ();
300
298
301
299
assertThat (handler .getReceivedPingTimes ()).hasSizeGreaterThanOrEqualTo (2 );
@@ -322,6 +320,7 @@ private Http2PingFrameHandler(BiConsumer<ChannelHandlerContext, Http2PingFrame>
322
320
protected void channelRead0 (ChannelHandlerContext ctx , Http2PingFrame frame ) throws InterruptedException {
323
321
receivedPingTimes .add (LocalDateTime .now (ZoneId .systemDefault ()));
324
322
consumer .accept (ctx , frame );
323
+ ctx .fireChannelRead (frame );
325
324
}
326
325
327
326
public List <LocalDateTime > getReceivedPingTimes () {
0 commit comments