@@ -118,88 +118,77 @@ void requestQueueSize() {
118
118
119
119
@ Test
120
120
void requestQueueSizeAppliedForReconnect () {
121
-
122
121
client .setOptions (ClientOptions .builder ().requestQueueSize (10 )
123
122
.timeoutOptions (TimeoutOptions .builder ().timeoutCommands (false ).build ()).build ());
124
-
125
- RedisAsyncCommands <String , String > connection = client . connect () .async ();
126
- testHitRequestQueueLimit (connection );
123
+ final StatefulRedisConnection < String , String > connection = client . connect ();
124
+ final RedisAsyncCommands <String , String > commands = connection .async ();
125
+ testHitRequestQueueLimit (commands , connection );
127
126
}
128
127
129
128
@ Test
130
129
void testHitRequestQueueLimitReconnectWithAuthCommand () {
131
-
132
130
WithPassword .run (client , () -> {
133
-
134
131
client .setOptions (ClientOptions .builder ().protocolVersion (ProtocolVersion .RESP2 ).pingBeforeActivateConnection (false )
135
132
.requestQueueSize (10 ).timeoutOptions (TimeoutOptions .builder ().timeoutCommands (false ).build ()).build ());
136
-
137
- RedisAsyncCommands <String , String > connection = client . connect () .async ();
138
- connection .auth (passwd );
139
- testHitRequestQueueLimit (connection );
133
+ final StatefulRedisConnection < String , String > connection = client . connect ();
134
+ final RedisAsyncCommands <String , String > commands = connection .async ();
135
+ commands .auth (passwd );
136
+ testHitRequestQueueLimit (commands , connection );
140
137
});
141
138
}
142
139
143
140
@ Test
144
141
@ EnabledOnCommand ("ACL" )
145
142
void testHitRequestQueueLimitReconnectWithAuthUsernamePasswordCommand () {
146
-
147
143
WithPassword .run (client , () -> {
148
-
149
144
client .setOptions (ClientOptions .builder ().protocolVersion (ProtocolVersion .RESP2 ).pingBeforeActivateConnection (false )
150
145
.requestQueueSize (10 ).timeoutOptions (TimeoutOptions .builder ().timeoutCommands (false ).build ()).build ());
151
-
152
- RedisAsyncCommands <String , String > connection = client . connect () .async ();
153
- connection .auth (username , passwd );
154
- testHitRequestQueueLimit (connection );
146
+ final StatefulRedisConnection < String , String > connection = client . connect ();
147
+ final RedisAsyncCommands <String , String > commands = connection .async ();
148
+ commands .auth (username , passwd );
149
+ testHitRequestQueueLimit (commands , connection );
155
150
});
156
151
}
157
152
158
153
@ Test
159
154
void testHitRequestQueueLimitReconnectWithUriAuth () {
160
-
161
155
WithPassword .run (client , () -> {
162
156
client .setOptions (ClientOptions .builder ().requestQueueSize (10 )
163
157
.timeoutOptions (TimeoutOptions .builder ().timeoutCommands (false ).build ()).build ());
164
- ;
165
-
166
- RedisURI redisURI = RedisURI .create (host , port );
158
+ final RedisURI redisURI = RedisURI .create (host , port );
167
159
redisURI .setPassword (passwd );
168
-
169
- RedisAsyncCommands <String , String > connection = client . connect ( redisURI ) .async ();
170
- testHitRequestQueueLimit (connection );
160
+ final StatefulRedisConnection < String , String > connection = client . connect ( redisURI );
161
+ final RedisAsyncCommands <String , String > commands = connection .async ();
162
+ testHitRequestQueueLimit (commands , connection );
171
163
});
172
164
}
173
165
174
166
@ Test
175
167
void testHitRequestQueueLimitReconnectWithUriAuthPingCommand () {
176
-
177
168
WithPassword .run (client , () -> {
178
-
179
169
client .setOptions (ClientOptions .builder ().requestQueueSize (10 )
180
170
.timeoutOptions (TimeoutOptions .builder ().timeoutCommands (false ).build ()).build ());
181
-
182
- RedisURI redisURI = RedisURI .create (host , port );
171
+ final RedisURI redisURI = RedisURI .create (host , port );
183
172
redisURI .setPassword (passwd );
184
-
185
- RedisAsyncCommands <String , String > connection = client . connect ( redisURI ) .async ();
186
- testHitRequestQueueLimit (connection );
173
+ final StatefulRedisConnection < String , String > connection = client . connect ( redisURI );
174
+ RedisAsyncCommands <String , String > commands = connection .async ();
175
+ testHitRequestQueueLimit (commands , connection );
187
176
});
188
177
}
189
178
190
- private void testHitRequestQueueLimit (RedisAsyncCommands <String , String > connection ) {
191
-
192
- ConnectionWatchdog watchdog = getConnectionWatchdog (connection . getStatefulConnection () );
179
+ private void testHitRequestQueueLimit (final RedisAsyncCommands <String , String > commands ,
180
+ final StatefulRedisConnection < String , String > connection ) {
181
+ ConnectionWatchdog watchdog = getConnectionWatchdog (connection );
193
182
194
183
watchdog .setListenOnChannelInactive (false );
195
184
196
- connection .quit ();
185
+ commands .quit ();
197
186
198
- Wait .untilTrue (() -> !connection .getStatefulConnection (). isOpen ()).waitOrTimeout ();
187
+ Wait .untilTrue (() -> !connection .isOpen ()).waitOrTimeout ();
199
188
200
189
List <RedisFuture <String >> pings = new ArrayList <>();
201
190
for (int i = 0 ; i < 10 ; i ++) {
202
- pings .add (connection .ping ());
191
+ pings .add (commands .ping ());
203
192
}
204
193
205
194
watchdog .setListenOnChannelInactive (true );
@@ -208,8 +197,7 @@ private void testHitRequestQueueLimit(RedisAsyncCommands<String, String> connect
208
197
for (RedisFuture <String > ping : pings ) {
209
198
assertThat (TestFutures .getOrTimeout (ping )).isEqualTo ("PONG" );
210
199
}
211
-
212
- connection .getStatefulConnection ().close ();
200
+ connection .close ();
213
201
}
214
202
215
203
@ Test
@@ -252,68 +240,52 @@ void requestQueueSizeOvercommittedReconnect() {
252
240
253
241
@ Test
254
242
void disconnectedWithoutReconnect () {
255
-
256
243
client .setOptions (ClientOptions .builder ().autoReconnect (false ).build ());
257
-
258
- RedisAsyncCommands <String , String > connection = client .connect ().async ();
259
-
260
- connection .quit ();
261
- Wait .untilTrue (() -> !connection .getStatefulConnection ().isOpen ()).waitOrTimeout ();
262
- try {
263
- connection .get (key );
244
+ try (final StatefulRedisConnection <String , String > connection = client .connect ()) {
245
+ RedisAsyncCommands <String , String > commands = connection .async ();
246
+ commands .quit ();
247
+ Wait .untilTrue (() -> !connection .isOpen ()).waitOrTimeout ();
248
+ commands .get (key );
264
249
} catch (Exception e ) {
265
250
assertThat (e ).isInstanceOf (RedisException .class ).hasMessageContaining ("not connected" );
266
- } finally {
267
- connection .getStatefulConnection ().close ();
268
251
}
269
252
}
270
253
271
254
@ Test
272
255
void disconnectedRejectCommands () {
273
-
274
256
client .setOptions (ClientOptions .builder ().disconnectedBehavior (ClientOptions .DisconnectedBehavior .REJECT_COMMANDS )
275
257
.timeoutOptions (TimeoutOptions .builder ().timeoutCommands (false ).build ()).build ());
276
-
277
- RedisAsyncCommands <String , String > connection = client .connect ().async ();
278
-
279
- getConnectionWatchdog (connection .getStatefulConnection ()).setListenOnChannelInactive (false );
280
- connection .quit ();
281
- Wait .untilTrue (() -> !connection .getStatefulConnection ().isOpen ()).waitOrTimeout ();
282
- try {
283
- connection .get (key );
258
+ try (final StatefulRedisConnection <String , String > connection = client .connect ()) {
259
+ RedisAsyncCommands <String , String > commands = connection .async ();
260
+ getConnectionWatchdog (connection ).setListenOnChannelInactive (false );
261
+ commands .quit ();
262
+ Wait .untilTrue (() -> !connection .isOpen ()).waitOrTimeout ();
263
+ commands .get (key );
284
264
} catch (Exception e ) {
285
265
assertThat (e ).isInstanceOf (RedisException .class ).hasMessageContaining ("not connected" );
286
- } finally {
287
- connection .getStatefulConnection ().close ();
288
266
}
289
267
}
290
268
291
269
@ Test
292
270
void disconnectedAcceptCommands () {
293
-
294
271
client .setOptions (ClientOptions .builder ().autoReconnect (false )
295
272
.disconnectedBehavior (ClientOptions .DisconnectedBehavior .ACCEPT_COMMANDS ).build ());
296
-
297
- RedisAsyncCommands <String , String > connection = client .connect ().async ();
298
-
299
- connection .quit ();
300
- Wait .untilTrue (() -> !connection .getStatefulConnection ().isOpen ()).waitOrTimeout ();
301
- connection .get (key );
302
- connection .getStatefulConnection ().close ();
273
+ try (final StatefulRedisConnection <String , String > connection = client .connect ()) {
274
+ RedisAsyncCommands <String , String > commands = connection .async ();
275
+ commands .quit ();
276
+ Wait .untilTrue (() -> !connection .isOpen ()).waitOrTimeout ();
277
+ commands .get (key );
278
+ }
303
279
}
304
280
305
281
@ Test
306
282
@ Inject
307
283
void pingBeforeConnect (StatefulRedisConnection <String , String > sharedConnection ) {
308
-
309
284
sharedConnection .sync ().set (key , value );
310
- RedisCommands <String , String > connection = client .connect ().sync ();
311
-
312
- try {
313
- String result = connection .get (key );
285
+ try (final StatefulRedisConnection <String , String > connection = client .connect ()) {
286
+ RedisCommands <String , String > commands = connection .sync ();
287
+ String result = commands .get (key );
314
288
assertThat (result ).isEqualTo (value );
315
- } finally {
316
- connection .getStatefulConnection ().close ();
317
289
}
318
290
}
319
291
@@ -337,17 +309,12 @@ void connectTimeout() throws Exception {
337
309
338
310
@ Test
339
311
void connectWithAuthentication () {
340
-
341
312
WithPassword .run (client , () -> {
342
313
RedisURI redisURI = RedisURI .Builder .redis (host , port ).withPassword (passwd ).build ();
343
-
344
- RedisCommands <String , String > connection = client .connect (redisURI ).sync ();
345
-
346
- try {
347
- String result = connection .info ();
314
+ try (final StatefulRedisConnection <String , String > connection = client .connect (redisURI )) {
315
+ final RedisCommands <String , String > commands = connection .sync ();
316
+ String result = commands .info ();
348
317
assertThat (result ).contains ("memory" );
349
- } finally {
350
- connection .getStatefulConnection ().close ();
351
318
}
352
319
});
353
320
}
@@ -375,21 +342,14 @@ void authenticationTimeout() {
375
342
376
343
@ Test
377
344
void sslAndAuthentication () {
378
-
379
345
WithPassword .run (client , () -> {
380
-
381
346
RedisURI redisURI = RedisURI .Builder .redis (host , 6443 ).withPassword (passwd ).withVerifyPeer (false ).withSsl (true )
382
347
.build ();
383
-
384
- RedisCommands <String , String > connection = client .connect (redisURI ).sync ();
385
-
386
- try {
387
- String result = connection .info ();
348
+ try (final StatefulRedisConnection <String , String > connection = client .connect (redisURI )) {
349
+ final RedisCommands <String , String > commands = connection .sync ();
350
+ String result = commands .info ();
388
351
assertThat (result ).contains ("memory" );
389
- } finally {
390
- connection .getStatefulConnection ().close ();
391
352
}
392
-
393
353
});
394
354
}
395
355
0 commit comments