2222import java .io .IOException ;
2323import java .time .Duration ;
2424import java .util .Arrays ;
25+ import java .util .Collections ;
2526
2627import static org .assertj .core .api .Assertions .assertThat ;
2728import static org .awaitility .Awaitility .await ;
@@ -119,7 +120,7 @@ static void cleanupDatabaseConnectionProvider() {
119120 @ DisplayName ("Should create MultiDbClient with PingStrategy health checks" )
120121 void shouldCreateClientWithPingStrategy () {
121122 // Given: DatabaseConfigs with PingStrategy using proxy URIs
122- HealthCheckStrategySupplier pingSupplier = (uri , options ) -> new PingStrategy (uri , options ,
123+ HealthCheckStrategySupplier pingSupplier = (uri , options ) -> new PingStrategy (options ,
123124 HealthCheckStrategy .Config .builder ().interval (100 ) // Fast interval for testing
124125 .timeout (1000 ).numProbes (1 ).build ());
125126
@@ -152,7 +153,7 @@ void shouldRecoverAfterDisconnect() throws Exception {
152153 RedisURI uri = RedisURI .builder ().withHost (TestSettings .host ()).withPort (9479 ).withTimeout (Duration .ofMillis (1000 ))
153154 .build ();
154155
155- try (PingStrategy strategy = new PingStrategy (uri , rawConnectionFactory ,
156+ try (PingStrategy strategy = new PingStrategy (rawConnectionFactory ,
156157 HealthCheckStrategy .Config .builder ().interval (1000 ).timeout (500 ).numProbes (1 ).build ())) {
157158 // When: Initial health check should work
158159 HealthStatus initialStatus = strategy .doHealthCheck (uri );
@@ -182,7 +183,7 @@ void shouldHandleConnectionTimeout() throws Exception {
182183 RedisURI uri = RedisURI .builder ().withHost (TestSettings .host ()).withPort (9479 ).withTimeout (Duration .ofMillis (100 ))
183184 .build ();
184185
185- try (PingStrategy strategy = new PingStrategy (uri , rawConnectionFactory ,
186+ try (PingStrategy strategy = new PingStrategy (rawConnectionFactory ,
186187 HealthCheckStrategy .Config .builder ().interval (1000 ).timeout (500 ).numProbes (1 ).build ())) {
187188 // When: Initial health check should work
188189 assertThat (strategy .doHealthCheck (uri )).isEqualTo (HealthStatus .HEALTHY );
@@ -211,7 +212,7 @@ void shouldHandleConnectionDrop() throws Exception {
211212 RedisURI uri = RedisURI .builder ().withHost (TestSettings .host ()).withPort (9479 ).withTimeout (Duration .ofMillis (2000 ))
212213 .build ();
213214
214- try (PingStrategy strategy = new PingStrategy (uri , rawConnectionFactory , HealthCheckStrategy .Config .create ())) {
215+ try (PingStrategy strategy = new PingStrategy (rawConnectionFactory , HealthCheckStrategy .Config .create ())) {
215216 // When: Initial health check
216217 assertThat (strategy .doHealthCheck (uri )).isEqualTo (HealthStatus .HEALTHY );
217218
@@ -236,18 +237,17 @@ void shouldHandleConnectionDrop() throws Exception {
236237 @ DisplayName ("Should detect healthy endpoint with PingStrategy" )
237238 void shouldDetectHealthyEndpoint () {
238239 // Given: DatabaseConfig with PingStrategy using proxy URI
239- HealthCheckStrategySupplier pingSupplier = (uri , options ) -> new PingStrategy (uri , options ,
240+ HealthCheckStrategySupplier pingSupplier = (uri , options ) -> new PingStrategy (options ,
240241 HealthCheckStrategy .Config .builder ().interval (50 ) // Very fast for testing
241242 .timeout (1000 ).numProbes (1 ).build ());
242243
243244 DatabaseConfig config = DatabaseConfig .builder (proxyUri1 ).weight (1.0f ).healthCheckStrategySupplier (pingSupplier )
244245 .build ();
245246
246247 // When: Create MultiDbClient and connect
247- MultiDbClient testClient = MultiDbClient .create (Arrays .asList (config ));
248- StatefulRedisMultiDbConnection <String , String > connection = testClient .connect ();
248+ MultiDbClient testClient = MultiDbClient .create (Collections .singletonList (config ));
249249
250- try {
250+ try ( StatefulRedisMultiDbConnection < String , String > connection = testClient . connect ()) {
251251 // Then: Endpoint should be healthy
252252 assertThat (connection .getCurrentEndpoint ()).isEqualTo (proxyUri1 );
253253
@@ -257,7 +257,6 @@ void shouldDetectHealthyEndpoint() {
257257 });
258258
259259 } finally {
260- connection .close ();
261260 testClient .shutdown ();
262261 }
263262 }
@@ -271,9 +270,8 @@ void shouldUseDefaultPingStrategySupplier() {
271270
272271 // When: Create MultiDbClient and connect
273272 MultiDbClient testClient = MultiDbClient .create (Arrays .asList (config1 , config2 ));
274- StatefulRedisMultiDbConnection <String , String > connection = testClient .connect ();
275273
276- try {
274+ try ( StatefulRedisMultiDbConnection < String , String > connection = testClient . connect ()) {
277275 // Then: Connection should work with default PingStrategy
278276 assertThat (connection .sync ().ping ()).isEqualTo ("PONG" );
279277 assertThat (connection .getCurrentEndpoint ()).isNotNull ();
@@ -283,7 +281,6 @@ void shouldUseDefaultPingStrategySupplier() {
283281 assertThat (connection .sync ().get ("default-ping-key" )).isEqualTo ("default-ping-value" );
284282
285283 } finally {
286- connection .close ();
287284 testClient .shutdown ();
288285 }
289286 }
@@ -292,7 +289,7 @@ void shouldUseDefaultPingStrategySupplier() {
292289 @ DisplayName ("Should handle multiple probes with PingStrategy" )
293290 void shouldHandleMultipleProbes () {
294291 // Given: DatabaseConfig with PingStrategy configured for multiple probes using proxy URI
295- HealthCheckStrategySupplier pingSupplier = (uri , options ) -> new PingStrategy (uri , options ,
292+ HealthCheckStrategySupplier pingSupplier = (uri , options ) -> new PingStrategy (options ,
296293 HealthCheckStrategy .Config .builder ().interval (100 ).timeout (1000 ).numProbes (3 ) // Multiple probes
297294 .delayInBetweenProbes (50 ).policy (ProbingPolicy .BuiltIn .MAJORITY_SUCCESS ).build ());
298295
@@ -301,14 +298,12 @@ void shouldHandleMultipleProbes() {
301298
302299 // When: Create MultiDbClient and connect
303300 MultiDbClient testClient = MultiDbClient .create (Arrays .asList (config ));
304- StatefulRedisMultiDbConnection <String , String > connection = testClient .connect ();
305301
306- try {
302+ try ( StatefulRedisMultiDbConnection < String , String > connection = testClient . connect ()) {
307303 // Then: Connection should work with multiple probes
308304 assertThat (connection .sync ().ping ()).isEqualTo ("PONG" );
309305
310306 } finally {
311- connection .close ();
312307 testClient .shutdown ();
313308 }
314309 }
0 commit comments