From fbd803f32ad1f201233ffb196c3373102da274c7 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 21 Jan 2015 15:24:13 +0100 Subject: [PATCH] DATAREST-414 - Added retry logic to connect to embedded Cassandra. The Cassandra tests sometimes cannot to the embedded instance on the CI server. Added a triple retry with a delay of 200ms to work around a potentially slow Cassandra bootstrap. --- .../AbstractCassandraIntegrationTest.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java index de9b4fdc5..e39aa0bc7 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java @@ -25,6 +25,7 @@ import org.springframework.data.rest.webmvc.CommonWebTests; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; +import com.datastax.driver.core.exceptions.NoHostAvailableException; /** * Base class for testing with an embedded cassandra database @@ -67,7 +68,27 @@ public abstract class AbstractCassandraIntegrationTest extends CommonWebTests { // check system session connected if (systemSession == null) { - systemSession = cluster.connect(); + systemSession = tryToConnect(cluster, 3); + } + } + + private static Session tryToConnect(Cluster cluster, int attempts) { + + try { + return cluster.connect(); + } catch (NoHostAvailableException o_O) { + + if (attempts == 0) { + throw o_O; + } + + try { + Thread.sleep(200); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + return tryToConnect(cluster, --attempts); } } }