Skip to content

Commit

Permalink
JAMES-1772 Cassandra durable writes are not needed in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Ouazana committed Jun 21, 2016
1 parent 606120d commit 1590e60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -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;
}
Expand All @@ -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)
+ ";");
}
}

Expand Down
Expand Up @@ -80,7 +80,7 @@ public void clearAllTables() {
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);
Expand Down

0 comments on commit 1590e60

Please sign in to comment.