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 bt...@apache.org on 2020/03/02 03:16:03 UTC

[james-project] 06/29: JAMES-3061 Moving the `key space creations` duty to the DockerCassandra

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 079bd0282aad8dc02c6462cac26ba482aa034505
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Mon Feb 24 18:13:07 2020 +0700

    JAMES-3061 Moving the `key space creations` duty to the DockerCassandra
    
    It's now only providing non privileged resources
---
 .../james/backends/cassandra/CassandraCluster.java | 51 +++++++++-------------
 1 file changed, 21 insertions(+), 30 deletions(-)

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 8df9d59..91c61ad 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
@@ -26,7 +26,6 @@ import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.init.CassandraTableManager;
 import org.apache.james.backends.cassandra.init.CassandraTypesProvider;
 import org.apache.james.backends.cassandra.init.ClusterFactory;
-import org.apache.james.backends.cassandra.init.KeyspaceFactory;
 import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
 import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
 import org.apache.james.util.Host;
@@ -34,13 +33,6 @@ import org.apache.james.util.Host;
 import com.datastax.driver.core.Cluster;
 
 public final class CassandraCluster implements AutoCloseable {
-    public static final String KEYSPACE = "testing";
-
-    private static Optional<Exception> startStackTrace = Optional.empty();
-    private final CassandraModule module;
-    private TestingSession session;
-    private CassandraTypesProvider typesProvider;
-    private Cluster cluster;
 
     public static CassandraCluster create(CassandraModule module, Host host) {
         assertClusterNotRunning();
@@ -55,27 +47,26 @@ public final class CassandraCluster implements AutoCloseable {
       });
     }
 
+    private static Optional<Exception> startStackTrace = Optional.empty();
+
+    private final CassandraModule module;
+    private final Cluster nonPrivilegedCluster;
+    private final TestingSession nonPrivilegedSession;
+    private final CassandraTypesProvider typesProvider;
+
     private CassandraCluster(CassandraModule module, Host host) throws RuntimeException {
         this.module = module;
-        try {
-            ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder()
-                .host(host)
-                .keyspace(KEYSPACE)
-                .createKeyspace()
-                .disableDurableWrites()
-                .build();
-            cluster = ClusterFactory.create(clusterConfiguration);
-            KeyspaceFactory.createKeyspace(clusterConfiguration, cluster);
-            session = new TestingSession(
-                new SessionWithInitializedTablesFactory(clusterConfiguration, cluster, module).get());
-            typesProvider = new CassandraTypesProvider(module, session);
-        } catch (Exception exception) {
-            throw new RuntimeException(exception);
-        }
+
+        ClusterConfiguration configuration = DockerCassandra.configurationBuilder(host)
+            .build();
+        this.nonPrivilegedCluster = ClusterFactory.create(configuration);
+        this.nonPrivilegedSession = new TestingSession(new SessionWithInitializedTablesFactory(configuration,
+            nonPrivilegedCluster, module).get());
+        this.typesProvider = new CassandraTypesProvider(module, nonPrivilegedSession);
     }
 
     public TestingSession getConf() {
-        return session;
+        return nonPrivilegedSession;
     }
 
     public CassandraTypesProvider getTypesProvider() {
@@ -84,19 +75,19 @@ public final class CassandraCluster implements AutoCloseable {
 
     @Override
     public void close() {
-        session.registerScenario(NOTHING);
-        if (!cluster.isClosed()) {
+        nonPrivilegedSession.registerScenario(NOTHING);
+        if (!nonPrivilegedCluster.isClosed()) {
             clearTables();
             closeCluster();
         }
     }
 
-    public void closeCluster() {
-        cluster.closeAsync().force();
+    void closeCluster() {
+        nonPrivilegedCluster.closeAsync().force();
         startStackTrace = Optional.empty();
     }
 
-    public void clearTables() {
-        new CassandraTableManager(module, session).clearAllTables();
+    void clearTables() {
+        new CassandraTableManager(module, nonPrivilegedSession).clearAllTables();
     }
 }


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