From c7f5f0735d5980e2d7bf137e419e9f7c6f48933d Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 8 Jan 2018 14:07:38 +0000 Subject: [PATCH] Stop reusing the Cluster when waiting for Cassandra to start See gh-10516 --- ...andraDataAutoConfigurationIntegrationTests.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 fb9a085dd4..afc1c3fc59 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 { } }; } + } }