james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/5] james-project git commit: JAMES-1944 add integration test about querryLogger config
Date Thu, 02 Mar 2017 11:21:04 GMT
JAMES-1944 add integration test about querryLogger config


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d71dfc4f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d71dfc4f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d71dfc4f

Branch: refs/heads/master
Commit: d71dfc4fc4458ffed7fbce91f8e0d197d45ce8aa
Parents: 4d02ac5
Author: Luc DUZAN <lduzan@linagora.com>
Authored: Tue Feb 21 17:57:30 2017 +0100
Committer: benwa <btellier@linagora.com>
Committed: Thu Mar 2 18:20:35 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/CassandraConfTest.java     | 119 -----------------
 .../james/CassandraLogConfigurationTest.java    | 130 +++++++++++++++++++
 .../org/apache/james/CassandraNodeConfTest.java | 119 +++++++++++++++++
 .../org/apache/james/DockerCassandraRule.java   |   2 +-
 4 files changed, 250 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java
deleted file mode 100644
index 6d1f0a2..0000000
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************
- * 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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.modules.mailbox.CassandraSessionConfiguration;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.testcontainers.DockerClientFactory;
-
-public class CassandraConfTest {
-
-    private static final int IMAP_PORT = 1143;
-
-    private static String getDockerHostIp() {
-        return DockerClientFactory.instance().dockerHostIpAddress();
-    }
-
-    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
-
-    @Rule
-    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
-            new EmbeddedElasticSearchRule());
-
-    private GuiceJamesServerImpl jamesServer;
-    private SocketChannel socketChannel;
-
-    @Before
-    public void setUp() throws IOException {
-        socketChannel = SocketChannel.open();
-    }
-
-    @After
-    public void after() throws IOException {
-        socketChannel.close();
-        if (jamesServer != null) {
-            jamesServer.stop();
-        }
-    }
-
-    @Test
-    public void serverShouldStartServiceWhenNodeIsReachable() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer();
-
-        assertThatServerStartCorrectly();
-    }
-
-    @Test
-    public void serverShouldStartWhenOneCassandraNodeIsUnreachable() throws Exception {
-        String unreachableNode = "10.2.3.42";
-        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(unreachableNode
+ "," + dockerCassandraRule.getIp());
-
-        jamesServer = cassandraJmapTestRule.jmapServer(
-                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(()
-> configuration));
-
-        assertThatServerStartCorrectly();
-    }
-
-    @Test
-    public void configShouldWorkWithNonDefaultPort() throws Exception {
-        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(getDockerHostIp()
+ ":" + dockerCassandraRule.getBindingPort());
-        jamesServer = cassandraJmapTestRule.jmapServer(
-                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(()
-> configuration));
-
-        assertThatServerStartCorrectly();
-    }
-
-    private void assertThatServerStartCorrectly() throws Exception, IOException {
-        jamesServer.start();
-        socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT));
-        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1
Server");
-    }
-
-    private PropertiesConfiguration getCassandraConfigurationForDocker(String confIps) {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-
-        configuration.addProperty("cassandra.nodes", confIps);
-        configuration.addProperty("cassandra.keyspace", "apache_james");
-        configuration.addProperty("cassandra.replication.factor", 1);
-        configuration.addProperty("cassandra.retryConnection.maxRetries", 10);
-        configuration.addProperty("cassandra.retryConnection", 5000);
-
-        return configuration;
-    }
-
-    private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException
{
-        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
-        socketChannel.read(byteBuffer);
-        byte[] bytes = byteBuffer.array();
-        return new String(bytes, Charset.forName("UTF-8"));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java
new file mode 100644
index 0000000..5d7f156
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java
@@ -0,0 +1,130 @@
+/****************************************************************
+ * 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;
+
+import com.google.inject.ProvisionException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.modules.mailbox.CassandraSessionConfiguration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+import java.nio.charset.Charset;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CassandraLogConfigurationTest {
+
+    private static final int IMAP_PORT = 1143;
+
+    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
+
+    @Rule
+    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
+            new EmbeddedElasticSearchRule());
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    private GuiceJamesServerImpl jamesServer;
+    private SocketChannel socketChannel;
+
+    @Before
+    public void setUp() throws IOException {
+        socketChannel = SocketChannel.open();
+    }
+
+    @After
+    public void after() throws IOException {
+        socketChannel.close();
+        if (jamesServer != null) {
+            jamesServer.stop();
+        }
+    }
+
+    @Test
+    public void serverShouldStartWithMinimalConfigAboutAConstantThresholdSlowQueryLogger()
throws Exception {
+        jamesServer = cassandraJmapTestRule.jmapServer(
+            (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(()
-> {
+                PropertiesConfiguration configuration = dockerCassandraRule.getCassandraConfigurationForDocker();
+
+                configuration.addProperty("cassandra.query.logger.constant.threshold", 100);
+
+                return configuration;
+            }));
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void serverShouldStartWithPersonalizedConfigAboutPercentileSlowQuerryLogger()
throws Exception {
+        jamesServer = cassandraJmapTestRule.jmapServer(
+            (binder) ->
+                binder.bind(CassandraSessionConfiguration.class).toInstance(() -> {
+                    PropertiesConfiguration configuration = dockerCassandraRule.getCassandraConfigurationForDocker();
+
+                    configuration.addProperty("cassandra.query.slow.query.latency.threshold.percentile",
90);
+                    configuration.addProperty("cassandra.query.logger.max.logged.parameters",
9);
+                    configuration.addProperty("cassandra.query.logger.max.query.string.length",
9000);
+                    configuration.addProperty("cassandra.query.logger.max.parameter.value.length",
90);
+
+                    return configuration;
+                }));
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void serverStartShouldFailIfConfigAboutLoggerIsInvalid() throws Exception {
+        thrown.expect(ProvisionException.class);
+
+        jamesServer = cassandraJmapTestRule.jmapServer(
+            (binder) ->
+                binder.bind(CassandraSessionConfiguration.class).toInstance(() -> {
+                    PropertiesConfiguration configuration = dockerCassandraRule.getCassandraConfigurationForDocker();
+
+                    configuration.addProperty("cassandra.query.slow.query.latency.threshold.percentile",
90);
+                    configuration.addProperty("cassandra.query.logger.constant.threshold",
100);
+
+                    return configuration;
+                }));
+
+        assertThatServerStartCorrectly();
+    }
+
+    private void assertThatServerStartCorrectly() throws Exception {
+        jamesServer.start();
+        socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT));
+        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1
Server");
+    }
+
+    private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException
{
+        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
+        socketChannel.read(byteBuffer);
+        byte[] bytes = byteBuffer.array();
+        return new String(bytes, Charset.forName("UTF-8"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
new file mode 100644
index 0000000..180aea6
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
@@ -0,0 +1,119 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+import java.nio.charset.Charset;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.modules.mailbox.CassandraSessionConfiguration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.testcontainers.DockerClientFactory;
+
+public class CassandraNodeConfTest {
+
+    private static final int IMAP_PORT = 1143;
+
+    private static String getDockerHostIp() {
+        return DockerClientFactory.instance().dockerHostIpAddress();
+    }
+
+    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
+
+    @Rule
+    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
+            new EmbeddedElasticSearchRule());
+
+    private GuiceJamesServerImpl jamesServer;
+    private SocketChannel socketChannel;
+
+    @Before
+    public void setUp() throws IOException {
+        socketChannel = SocketChannel.open();
+    }
+
+    @After
+    public void after() throws IOException {
+        socketChannel.close();
+        if (jamesServer != null) {
+            jamesServer.stop();
+        }
+    }
+
+    @Test
+    public void serverShouldStartServiceWhenNodeIsReachable() throws Exception {
+        jamesServer = cassandraJmapTestRule.jmapServer();
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void serverShouldStartWhenOneCassandraNodeIsUnreachable() throws Exception {
+        String unreachableNode = "10.2.3.42";
+        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(unreachableNode
+ "," + dockerCassandraRule.getIp());
+
+        jamesServer = cassandraJmapTestRule.jmapServer(
+                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(()
-> configuration));
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void configShouldWorkWithNonDefaultPort() throws Exception {
+        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(getDockerHostIp()
+ ":" + dockerCassandraRule.getBindingPort());
+        jamesServer = cassandraJmapTestRule.jmapServer(
+                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(()
-> configuration));
+
+        assertThatServerStartCorrectly();
+    }
+
+    private void assertThatServerStartCorrectly() throws Exception {
+        jamesServer.start();
+        socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT));
+        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1
Server");
+    }
+
+    private PropertiesConfiguration getCassandraConfigurationForDocker(String confIps) {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+
+        configuration.addProperty("cassandra.nodes", confIps);
+        configuration.addProperty("cassandra.keyspace", "apache_james");
+        configuration.addProperty("cassandra.replication.factor", 1);
+        configuration.addProperty("cassandra.retryConnection.maxRetries", 10);
+        configuration.addProperty("cassandra.retryConnection", 5000);
+
+        return configuration;
+    }
+
+    private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException
{
+        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
+        socketChannel.read(byteBuffer);
+        byte[] bytes = byteBuffer.array();
+        return new String(bytes, Charset.forName("UTF-8"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
index e482214..4980f38 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
@@ -41,7 +41,7 @@ public class DockerCassandraRule implements GuiceModuleTestRule {
         return bindingIp == null || bindingIp.equals("0.0.0.0");
     }
 
-    private PropertiesConfiguration getCassandraConfigurationForDocker() {
+    public PropertiesConfiguration getCassandraConfigurationForDocker() {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
 
         configuration.addProperty("cassandra.nodes", getIp() + ":" + CASSANDRA_PORT);


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


Mime
View raw message