From 1590e60343f92663064ee1d79f002cf4a82c5b66 Mon Sep 17 00:00:00 2001 From: Raphael Ouazana Date: Tue, 21 Jun 2016 11:42:40 +0200 Subject: [PATCH] JAMES-1772 Cassandra durable writes are not needed in tests --- .../init/ClusterWithKeyspaceCreatedFactory.java | 16 +++++++++++++--- .../backends/cassandra/CassandraCluster.java | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterWithKeyspaceCreatedFactory.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterWithKeyspaceCreatedFactory.java index c7d1bc8accf..f56a3af72b4 100644 --- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterWithKeyspaceCreatedFactory.java +++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterWithKeyspaceCreatedFactory.java @@ -26,9 +26,17 @@ public class ClusterWithKeyspaceCreatedFactory { private final static int DEFAULT_REPLICATION_FACTOR = 1; + public static Cluster clusterWithInitializedKeyspaceWithoutDurableWrites(Cluster cluster, String keyspace, int replicationFactor) { + return clusterWithInitializedKeyspace(cluster, keyspace, replicationFactor, false); + } + public static Cluster clusterWithInitializedKeyspace(Cluster cluster, String keyspace, int replicationFactor) { + return clusterWithInitializedKeyspace(cluster, keyspace, replicationFactor, true); + } + + private static Cluster clusterWithInitializedKeyspace(Cluster cluster, String keyspace, int replicationFactor, boolean durableWrites) { if (isKeyspacePresent(cluster, keyspace)) { - createKeyspace(cluster, keyspace, replicationFactor); + createKeyspace(cluster, keyspace, replicationFactor, durableWrites); } return cluster; } @@ -41,10 +49,12 @@ private static boolean isKeyspacePresent(Cluster cluster, String keyspace) { return cluster.getMetadata().getKeyspace(keyspace) == null; } - private static void createKeyspace(Cluster cluster, String keyspace, int replicationFactor) { + private static void createKeyspace(Cluster cluster, String keyspace, int replicationFactor, boolean durableWrites) { try (Session session = cluster.connect()) { session.execute("CREATE KEYSPACE IF NOT EXISTS " + keyspace - + " WITH replication = {'class':'SimpleStrategy', 'replication_factor':" + replicationFactor + "};"); + + " WITH replication = {'class':'SimpleStrategy', 'replication_factor':" + replicationFactor + "}" + + " AND durable_writes = " + String.valueOf(durableWrites) + + ";"); } } 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 d1f1e0221b9..b5bc16080ba 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 @@ -80,7 +80,7 @@ public void clearAllTables() { private Optional tryInitializeSession() { try { Cluster clusterWithInitializedKeyspace = ClusterWithKeyspaceCreatedFactory - .clusterWithInitializedKeyspace(getCluster(), KEYSPACE_NAME, REPLICATION_FACTOR); + .clusterWithInitializedKeyspaceWithoutDurableWrites(getCluster(), KEYSPACE_NAME, REPLICATION_FACTOR); return Optional.of(new SessionWithInitializedTablesFactory(module).createSession(clusterWithInitializedKeyspace, KEYSPACE_NAME)); } catch (NoHostAvailableException exception) { sleep(SLEEP_BEFORE_RETRY);