@@ -66,7 +66,13 @@ static void afterClass() {
66
66
void genericPoolShouldWorkWithWrappedConnections () throws Exception {
67
67
68
68
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
69
- .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>());
69
+ .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), connection -> {
70
+ try {
71
+ return "PONG" .equals (connection .sync ().ping ());
72
+ } catch (Exception e ) {
73
+ return false ;
74
+ }
75
+ });
70
76
71
77
borrowAndReturn (pool );
72
78
borrowAndClose (pool );
@@ -91,7 +97,13 @@ void genericPoolShouldCloseConnectionsAboveMaxIdleSize() throws Exception {
91
97
poolConfig .setMaxIdle (2 );
92
98
93
99
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
94
- .createGenericObjectPool (() -> client .connect (), poolConfig );
100
+ .createGenericObjectPool (() -> client .connect (), poolConfig , connection -> {
101
+ try {
102
+ return "PONG" .equals (connection .sync ().ping ());
103
+ } catch (Exception e ) {
104
+ return false ;
105
+ }
106
+ });
95
107
96
108
borrowAndReturn (pool );
97
109
borrowAndClose (pool );
@@ -120,7 +132,13 @@ void genericPoolShouldCloseConnectionsAboveMaxIdleSize() throws Exception {
120
132
void genericPoolShouldWorkWithPlainConnections () throws Exception {
121
133
122
134
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
123
- .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), false );
135
+ .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), false , connection -> {
136
+ try {
137
+ return "PONG" .equals (connection .sync ().ping ());
138
+ } catch (Exception e ) {
139
+ return false ;
140
+ }
141
+ });
124
142
125
143
borrowAndReturn (pool );
126
144
@@ -151,7 +169,13 @@ void softReferencePoolShouldWorkWithPlainConnections() throws Exception {
151
169
void genericPoolUsingWrappingShouldPropagateExceptionsCorrectly () throws Exception {
152
170
153
171
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
154
- .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>());
172
+ .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), connection -> {
173
+ try {
174
+ return "PONG" .equals (connection .sync ().ping ());
175
+ } catch (Exception e ) {
176
+ return false ;
177
+ }
178
+ });
155
179
156
180
StatefulRedisConnection <String , String > connection = pool .borrowObject ();
157
181
RedisCommands <String , String > sync = connection .sync ();
@@ -172,7 +196,13 @@ void genericPoolUsingWrappingShouldPropagateExceptionsCorrectly() throws Excepti
172
196
void wrappedConnectionShouldUseWrappers () throws Exception {
173
197
174
198
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
175
- .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>());
199
+ .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), connection -> {
200
+ try {
201
+ return "PONG" .equals (connection .sync ().ping ());
202
+ } catch (Exception e ) {
203
+ return false ;
204
+ }
205
+ });
176
206
177
207
StatefulRedisConnection <String , String > connection = pool .borrowObject ();
178
208
RedisCommands <String , String > sync = connection .sync ();
@@ -197,7 +227,13 @@ void wrappedMasterSlaveConnectionShouldUseWrappers() throws Exception {
197
227
198
228
GenericObjectPool <StatefulRedisMasterReplicaConnection <String , String >> pool = ConnectionPoolSupport
199
229
.createGenericObjectPool (() -> MasterReplica .connect (client , new StringCodec (), RedisURI .create (host , port )),
200
- new GenericObjectPoolConfig <>());
230
+ new GenericObjectPoolConfig <>(), connection -> {
231
+ try {
232
+ return "PONG" .equals (connection .sync ().ping ());
233
+ } catch (Exception e ) {
234
+ return false ;
235
+ }
236
+ });
201
237
202
238
StatefulRedisMasterReplicaConnection <String , String > connection = pool .borrowObject ();
203
239
RedisCommands <String , String > sync = connection .sync ();
@@ -223,7 +259,13 @@ void wrappedClusterConnectionShouldUseWrappers() throws Exception {
223
259
RedisURI .create (TestSettings .host (), 7379 ));
224
260
225
261
GenericObjectPool <StatefulRedisClusterConnection <String , String >> pool = ConnectionPoolSupport
226
- .createGenericObjectPool (redisClusterClient ::connect , new GenericObjectPoolConfig <>());
262
+ .createGenericObjectPool (redisClusterClient ::connect , new GenericObjectPoolConfig <>(), connection -> {
263
+ try {
264
+ return "PONG" .equals (connection .sync ().ping ());
265
+ } catch (Exception e ) {
266
+ return false ;
267
+ }
268
+ });
227
269
228
270
StatefulRedisClusterConnection <String , String > connection = pool .borrowObject ();
229
271
RedisAdvancedClusterCommands <String , String > sync = connection .sync ();
@@ -250,7 +292,13 @@ void wrappedClusterConnectionShouldUseWrappers() throws Exception {
250
292
void plainConnectionShouldNotUseWrappers () throws Exception {
251
293
252
294
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
253
- .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), false );
295
+ .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), false , connection -> {
296
+ try {
297
+ return "PONG" .equals (connection .sync ().ping ());
298
+ } catch (Exception e ) {
299
+ return false ;
300
+ }
301
+ });
254
302
255
303
StatefulRedisConnection <String , String > connection = pool .borrowObject ();
256
304
RedisCommands <String , String > sync = connection .sync ();
@@ -295,7 +343,13 @@ void softRefPoolShouldWorkWithWrappedConnections() throws Exception {
295
343
void wrappedObjectClosedAfterReturn () throws Exception {
296
344
297
345
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
298
- .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), true );
346
+ .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), true , connection -> {
347
+ try {
348
+ return "PONG" .equals (connection .sync ().ping ());
349
+ } catch (Exception e ) {
350
+ return false ;
351
+ }
352
+ });
299
353
300
354
StatefulRedisConnection <String , String > connection = pool .borrowObject ();
301
355
RedisCommands <String , String > sync = connection .sync ();
@@ -317,7 +371,13 @@ void wrappedObjectClosedAfterReturn() throws Exception {
317
371
void tryWithResourcesReturnsConnectionToPool () throws Exception {
318
372
319
373
GenericObjectPool <StatefulRedisConnection <String , String >> pool = ConnectionPoolSupport
320
- .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>());
374
+ .createGenericObjectPool (() -> client .connect (), new GenericObjectPoolConfig <>(), connection -> {
375
+ try {
376
+ return "PONG" .equals (connection .sync ().ping ());
377
+ } catch (Exception e ) {
378
+ return false ;
379
+ }
380
+ });
321
381
322
382
StatefulRedisConnection <String , String > usedConnection = null ;
323
383
try (StatefulRedisConnection <String , String > connection = pool .borrowObject ()) {
0 commit comments