You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2015/11/04 09:30:22 UTC

svn commit: r1712501 - in /james/project/trunk/backends-common/cassandra/src: main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java test/java/org/apache/james/backends/cassandra/CassandraCluster.java

Author: aduprat
Date: Wed Nov  4 08:30:22 2015
New Revision: 1712501

URL: http://svn.apache.org/viewvc?rev=1712501&view=rev
Log:
JAMES-1634 Faster Cassandra tests. Contributed by Duprat <an...@gmail.com>

Modified:
    james/project/trunk/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java
    james/project/trunk/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java

Modified: james/project/trunk/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java
URL: http://svn.apache.org/viewvc/james/project/trunk/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java?rev=1712501&r1=1712500&r2=1712501&view=diff
==============================================================================
--- james/project/trunk/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java (original)
+++ james/project/trunk/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java Wed Nov  4 08:30:22 2015
@@ -20,8 +20,10 @@
 package org.apache.james.backends.cassandra.init;
 
 import java.util.List;
+import java.util.Optional;
 
 import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.QueryOptions;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 
@@ -40,7 +42,9 @@ public class ClusterFactory {
     private final static String DEFAULT_CLUSTER_IP = "localhost";
     private final static int DEFAULT_CLUSTER_PORT = 9042;
 
-    public static Cluster createClusterForClusterWithPassWord(List<CassandraServer> servers, String userName, String password) {
+    public static Cluster createClusterForClusterWithPassWord(List<CassandraServer> servers, String userName, String password, 
+            Optional<Integer> refreshSchemaIntervalMillis) {
+
         Cluster.Builder clusterBuilder = Cluster.builder();
         servers.forEach(
             (server) -> clusterBuilder.addContactPoint(server.ip).withPort(server.port)
@@ -48,22 +52,29 @@ public class ClusterFactory {
         if(!Strings.isNullOrEmpty(userName) && !Strings.isNullOrEmpty(password)) {
             clusterBuilder.withCredentials(userName, password);
         }
+        if (refreshSchemaIntervalMillis.isPresent()) {
+            clusterBuilder.withQueryOptions(new QueryOptions().setRefreshSchemaIntervalMillis(refreshSchemaIntervalMillis.get()));
+        }
         return clusterBuilder.build();
     }
 
     public static Cluster createClusterForClusterWithoutPassWord(List<CassandraServer> servers) {
-        return createClusterForClusterWithPassWord(servers, null, null);
+        return createClusterForClusterWithPassWord(servers, null, null, Optional.empty());
     }
 
     public static Cluster createClusterForSingleServerWithPassWord(String ip, int port, String userName, String password) {
-        return createClusterForClusterWithPassWord(ImmutableList.of(new CassandraServer(ip, port)), userName, password);
+        return createClusterForClusterWithPassWord(ImmutableList.of(new CassandraServer(ip, port)), userName, password, Optional.empty());
     }
 
     public static Cluster createClusterForSingleServerWithoutPassWord(String ip, int port) {
-        return createClusterForClusterWithPassWord(ImmutableList.of(new CassandraServer(ip, port)), null, null);
+        return createClusterForClusterWithPassWord(ImmutableList.of(new CassandraServer(ip, port)), null, null, Optional.empty());
+    }
+
+    public static Cluster createTestingCluster(String ip, int port) {
+        return createClusterForClusterWithPassWord(ImmutableList.of(new CassandraServer(ip, port)), null, null, Optional.of(0));
     }
 
-     public static Cluster createDefaultSession() {
+    public static Cluster createDefaultSession() {
         return createClusterForSingleServerWithoutPassWord(DEFAULT_CLUSTER_IP, DEFAULT_CLUSTER_PORT);
     }
 }

Modified: james/project/trunk/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
URL: http://svn.apache.org/viewvc/james/project/trunk/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java?rev=1712501&r1=1712500&r2=1712501&view=diff
==============================================================================
--- james/project/trunk/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java (original)
+++ james/project/trunk/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java Wed Nov  4 08:30:22 2015
@@ -55,6 +55,7 @@ public final class CassandraCluster {
         this.module = module;
         try {
             EmbeddedCassandraServerHelper.startEmbeddedCassandra();
+
             session = new FunctionRunnerWithRetry(MAX_RETRY)
                 .executeAndRetrieveObject(CassandraCluster.this::tryInitializeSession);
             typesProvider = new CassandraTypesProvider(module, session);



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org