JAMES-2470 CassandraCluster don't need to await This, is already performed by the Cassandra's testcontainer wait strategy
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3ce75528 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3ce75528 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3ce75528 Branch: refs/heads/master Commit: 3ce755286d1d49912bf06837797b1459796f7a51 Parents: 86debb6 Author: benwa <[email protected]> Authored: Thu Jul 19 15:57:31 2018 +0700 Committer: benwa <[email protected]> Committed: Fri Jul 20 18:17:55 2018 +0700 ---------------------------------------------------------------------- .../backends/cassandra/CassandraCluster.java | 63 +++++--------------- 1 file changed, 14 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/3ce75528/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java ---------------------------------------------------------------------- diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java index 8e9df5b..eec7c80 100644 --- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java +++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java @@ -18,38 +18,27 @@ ****************************************************************/ package org.apache.james.backends.cassandra; -import java.util.Optional; - import javax.inject.Inject; import javax.inject.Named; -import org.apache.commons.text.RandomStringGenerator; import org.apache.james.backends.cassandra.components.CassandraModule; import org.apache.james.backends.cassandra.init.CassandraTypesProvider; import org.apache.james.backends.cassandra.init.ClusterBuilder; import org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory; import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory; import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration; -import org.apache.james.backends.cassandra.utils.FunctionRunnerWithRetry; import org.apache.james.util.Host; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; -import com.datastax.driver.core.exceptions.NoHostAvailableException; public final class CassandraCluster implements AutoCloseable { - - private static final int REPLICATION_FACTOR = 1; - - private static final long SLEEP_BEFORE_RETRY = 20; - private static final int MAX_RETRY = 20000; + public static final String KEYSPACE = "testing"; private final CassandraModule module; private Session session; private CassandraTypesProvider typesProvider; private Cluster cluster; - private String keyspace; - private ClusterConfiguration clusterConfiguration; public static CassandraCluster create(CassandraModule module, String host, int port) { return new CassandraCluster(module, host, port); @@ -67,15 +56,19 @@ public final class CassandraCluster implements AutoCloseable { .host(host) .port(port) .build(); - keyspace = new RandomStringGenerator.Builder().withinRange('a', 'z').build().generate(10); - clusterConfiguration = ClusterConfiguration.builder() - .host(Host.from(host, port)) - .keyspace(keyspace) - .replicationFactor(1) - .maxRetry(10) - .minDelay(5000) - .build(); - session = new FunctionRunnerWithRetry(MAX_RETRY).executeAndRetrieveObject(CassandraCluster.this::tryInitializeSession); + session = new SessionWithInitializedTablesFactory( + ClusterConfiguration.builder() + .host(Host.from(host, port)) + .keyspace(KEYSPACE) + .replicationFactor(1) + .build(), + ClusterWithKeyspaceCreatedFactory + .config(cluster, KEYSPACE) + .replicationFactor(1) + .disableDurableWrites() + .clusterWithInitializedKeyspace(), + module) + .get(); typesProvider = new CassandraTypesProvider(module, session); } catch (Exception exception) { throw new RuntimeException(exception); @@ -85,34 +78,6 @@ public final class CassandraCluster implements AutoCloseable { public Session getConf() { return session; } - - private Optional<Session> tryInitializeSession() { - try { - Cluster clusterWithInitializedKeyspace = ClusterWithKeyspaceCreatedFactory - .config(getCluster(), keyspace) - .replicationFactor(REPLICATION_FACTOR) - .disableDurableWrites() - .clusterWithInitializedKeyspace(); - - return Optional.of(new SessionWithInitializedTablesFactory(clusterConfiguration, clusterWithInitializedKeyspace, module) - .get()); - } catch (NoHostAvailableException exception) { - sleep(SLEEP_BEFORE_RETRY); - return Optional.empty(); - } - } - - public Cluster getCluster() { - return cluster; - } - - private void sleep(long sleepMs) { - try { - Thread.sleep(sleepMs); - } catch (InterruptedException interruptedException) { - throw new RuntimeException(interruptedException); - } - } public CassandraTypesProvider getTypesProvider() { return typesProvider; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
