JAMES-1772 Cassandra durable writes are not needed in tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1590e603 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1590e603 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1590e603 Branch: refs/heads/master Commit: 1590e60343f92663064ee1d79f002cf4a82c5b66 Parents: 606120d Author: Raphael Ouazana <[email protected]> Authored: Tue Jun 21 11:42:40 2016 +0200 Committer: Raphael Ouazana <[email protected]> Committed: Tue Jun 21 11:42:40 2016 +0200 ---------------------------------------------------------------------- .../init/ClusterWithKeyspaceCreatedFactory.java | 16 +++++++++++++--- .../james/backends/cassandra/CassandraCluster.java | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/1590e603/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterWithKeyspaceCreatedFactory.java ---------------------------------------------------------------------- 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 c7d1bc8..f56a3af 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 @@ public class ClusterWithKeyspaceCreatedFactory { 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) + + ";"); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/1590e603/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 d1f1e02..b5bc160 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 final class CassandraCluster { private Optional<Session> 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); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
