JAMES-2544 Propose an extension for Cassandra cluster
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7023a291 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7023a291 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7023a291 Branch: refs/heads/master Commit: 7023a2919f8ab287e09bc701d8d5e539d6d68ecb Parents: d031739 Author: Benoit Tellier <[email protected]> Authored: Thu Sep 13 15:14:25 2018 +0700 Committer: Benoit Tellier <[email protected]> Committed: Fri Sep 14 10:18:33 2018 +0700 ---------------------------------------------------------------------- .../cassandra/CassandraClusterExtension.java | 71 ++++++++++++++++++++ .../cassandra/CassandraActiveScriptDAOTest.java | 55 +++++---------- 2 files changed, 88 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/7023a291/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraClusterExtension.java ---------------------------------------------------------------------- diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraClusterExtension.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraClusterExtension.java new file mode 100644 index 0000000..c5b144f --- /dev/null +++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraClusterExtension.java @@ -0,0 +1,71 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.backends.cassandra; + +import org.apache.james.backends.cassandra.components.CassandraModule; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ParameterContext; +import org.junit.jupiter.api.extension.ParameterResolutionException; +import org.junit.jupiter.api.extension.ParameterResolver; + +public class CassandraClusterExtension implements BeforeAllCallback, AfterAllCallback, AfterEachCallback, ParameterResolver { + private final DockerCassandraExtension cassandraExtension; + private final CassandraModule cassandraModule; + private CassandraCluster cassandraCluster; + + public CassandraClusterExtension(CassandraModule cassandraModule) { + this.cassandraModule = cassandraModule; + this.cassandraExtension = new DockerCassandraExtension(); + } + + @Override + public void beforeAll(ExtensionContext extensionContext) { + cassandraExtension.beforeAll(extensionContext); + cassandraCluster = CassandraCluster.create(cassandraModule, cassandraExtension.getDockerCassandra().getHost()); + } + + @Override + public void afterEach(ExtensionContext extensionContext) { + cassandraCluster.clearTables(); + } + + @Override + public void afterAll(ExtensionContext extensionContext) { + cassandraCluster.close(); + cassandraExtension.afterAll(extensionContext); + } + + @Override + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + return (parameterContext.getParameter().getType() == CassandraCluster.class); + } + + @Override + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + return cassandraCluster; + } + + public CassandraCluster getCassandraCluster() { + return cassandraCluster; + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/7023a291/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraActiveScriptDAOTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraActiveScriptDAOTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraActiveScriptDAOTest.java index 4b973b9..2fd0426 100644 --- a/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraActiveScriptDAOTest.java +++ b/server/data/data-cassandra/src/test/java/org/apache/james/sieve/cassandra/CassandraActiveScriptDAOTest.java @@ -24,56 +24,37 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; import org.apache.james.backends.cassandra.CassandraCluster; -import org.apache.james.backends.cassandra.DockerCassandraRule; +import org.apache.james.backends.cassandra.CassandraClusterExtension; import org.apache.james.core.User; import org.apache.james.sieve.cassandra.model.ActiveScriptInfo; import org.apache.james.sieverepository.api.ScriptName; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -public class CassandraActiveScriptDAOTest { +class CassandraActiveScriptDAOTest { + private static final User USER = User.fromUsername("user"); + private static final ScriptName SCRIPT_NAME = new ScriptName("sciptName"); + private static final ScriptName NEW_SCRIPT_NAME = new ScriptName("newScriptName"); - public static final User USER = User.fromUsername("user"); - public static final ScriptName SCRIPT_NAME = new ScriptName("sciptName"); - public static final ScriptName NEW_SCRIPT_NAME = new ScriptName("newScriptName"); - - @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule(); - private static CassandraCluster cassandra; + @RegisterExtension + static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraSieveRepositoryModule.MODULE); private CassandraActiveScriptDAO activeScriptDAO; - @BeforeClass - public static void setUpClass() { - cassandra = CassandraCluster.create(CassandraSieveRepositoryModule.MODULE, cassandraServer.getHost()); - } - - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp(CassandraCluster cassandra) { activeScriptDAO = new CassandraActiveScriptDAO(cassandra.getConf()); } - @After - public void tearDown() { - cassandra.clearTables(); - } - - @AfterClass - public static void tearDownClass() { - cassandra.closeCluster(); - } - @Test - public void getActiveSctiptInfoShouldReturnEmptyByDefault() { + void getActiveSctiptInfoShouldReturnEmptyByDefault() { assertThat(activeScriptDAO.getActiveSctiptInfo(USER).join().isPresent()) .isFalse(); } @Test - public void getActiveSctiptInfoShouldReturnStoredName() { + void getActiveSctiptInfoShouldReturnStoredName() { activeScriptDAO.activate(USER, SCRIPT_NAME).join(); Optional<ActiveScriptInfo> actual = activeScriptDAO.getActiveSctiptInfo(USER).join(); @@ -83,7 +64,7 @@ public class CassandraActiveScriptDAOTest { } @Test - public void activateShouldAllowRename() { + void activateShouldAllowRename() { activeScriptDAO.activate(USER, SCRIPT_NAME).join(); activeScriptDAO.activate(USER, NEW_SCRIPT_NAME).join(); @@ -94,7 +75,7 @@ public class CassandraActiveScriptDAOTest { } @Test - public void unactivateShouldAllowRemovingActiveScript() { + void unactivateShouldAllowRemovingActiveScript() { activeScriptDAO.activate(USER, SCRIPT_NAME).join(); activeScriptDAO.unactivate(USER).join(); @@ -103,13 +84,11 @@ public class CassandraActiveScriptDAOTest { assertThat(actual.isPresent()).isFalse(); } - @Test - public void unactivateShouldWorkWhenNoneStore() { + void unactivateShouldWorkWhenNoneStore() { activeScriptDAO.unactivate(USER).join(); Optional<ActiveScriptInfo> actual = activeScriptDAO.getActiveSctiptInfo(USER).join(); assertThat(actual.isPresent()).isFalse(); } - } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
