diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java index fb9a085dd4b..afc1c3fc596 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java @@ -109,19 +109,20 @@ public class CassandraDataAutoConfigurationIntegrationTests { @Override protected void waitUntilReady() { super.waitUntilReady(); - Cluster cluster = Cluster.builder().addContactPoint("localhost").build(); + try { Unreliables.retryUntilTrue((int) this.startupTimeout.getSeconds(), - TimeUnit.SECONDS, checkConnection(cluster)); + TimeUnit.SECONDS, checkConnection()); } - catch (TimeoutException e) { - throw new IllegalStateException(); + catch (TimeoutException ex) { + throw new IllegalStateException(ex); } } - private Callable checkConnection(Cluster cluster) { + private Callable checkConnection() { return () -> { - try { + try (Cluster cluster = Cluster.builder().addContactPoint("localhost") + .build()) { cluster.connect(); return true; } @@ -130,6 +131,7 @@ public class CassandraDataAutoConfigurationIntegrationTests { } }; } + } }