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 ro...@apache.org on 2016/11/30 14:01:20 UTC
[01/16] james-project git commit: JAMES-1868 Add a Metric
implementation with DropWizard-metrics
Repository: james-project
Updated Branches:
refs/heads/master 9ce8f34ef -> 7bcc6201b
JAMES-1868 Add a Metric implementation with DropWizard-metrics
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0254c439
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0254c439
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0254c439
Branch: refs/heads/master
Commit: 0254c439cc28a9e29aa4b798de988d2995237897
Parents: 4374778
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Nov 24 11:54:20 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:21:43 2016 +0700
----------------------------------------------------------------------
.../metrics/metrics-dropwizard/pom.xml | 58 ++++++++++++++++++++
.../metrics/dropwizard/DropWizardMetric.java | 43 +++++++++++++++
.../dropwizard/DropWizardMetricFactory.java | 43 +++++++++++++++
3 files changed, 144 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/0254c439/server/container/metrics/metrics-dropwizard/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/pom.xml b/server/container/metrics/metrics-dropwizard/pom.xml
new file mode 100644
index 0000000..083224e
--- /dev/null
+++ b/server/container/metrics/metrics-dropwizard/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>james-server</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.0.0-beta6-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>james-server-metrics-dropwizard</artifactId>
+
+ <name>Apache James :: Server :: Metrics :: Dropwizard</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-filesystem-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/0254c439/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetric.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetric.java b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetric.java
new file mode 100644
index 0000000..1e55395
--- /dev/null
+++ b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetric.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.metrics.dropwizard;
+
+import org.apache.james.metrics.api.Metric;
+
+import com.codahale.metrics.Counter;
+
+public class DropWizardMetric implements Metric {
+
+ private final Counter counter;
+
+ public DropWizardMetric(Counter counter) {
+ this.counter = counter;
+ }
+
+ @Override
+ public void increment() {
+ counter.inc();
+ }
+
+ @Override
+ public void decrement() {
+ counter.dec();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/0254c439/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
new file mode 100644
index 0000000..2e89060
--- /dev/null
+++ b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.metrics.dropwizard;
+
+import javax.inject.Inject;
+
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+
+import com.codahale.metrics.MetricRegistry;
+
+public class DropWizardMetricFactory implements MetricFactory {
+
+ private final MetricRegistry metricRegistry;
+
+ @Inject
+ public DropWizardMetricFactory() {
+ this.metricRegistry = new MetricRegistry();
+ }
+
+ @Override
+ public Metric generate(String name) {
+ return new DropWizardMetric(metricRegistry.counter(name));
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[06/16] james-project git commit: JAMES-1868 Add Spring support for
DropWizard
Posted by ro...@apache.org.
JAMES-1868 Add Spring support for DropWizard
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/61a319f8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/61a319f8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/61a319f8
Branch: refs/heads/master
Commit: 61a319f8c16edfc308b04e06b50fc4827740498b
Parents: 69769e0
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Nov 24 11:58:27 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:31:07 2016 +0700
----------------------------------------------------------------------
.../resources/META-INF/spring/spring-mailbox.xml | 2 +-
.../META-INF/org/apache/james/spring-server.xml | 8 ++++++++
.../META-INF/spring/activemq-queue-context.xml | 19 ++++++++++---------
3 files changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/61a319f8/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
index 153e1a2..f681a0d 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
@@ -65,6 +65,6 @@
<beans profile="cassandra">
<import resource="classpath:META-INF/spring/mailbox-cassandra.xml"/>
<import resource="classpath:META-INF/spring/mailbox-elasticsearch.xml"/>
- <import resource="classpath:META-INF/spring/kafka.xml"/>
+ <!-- <import resource="classpath:META-INF/spring/kafka.xml"/> -->
</beans>
</beans>
http://git-wip-us.apache.org/repos/asf/james-project/blob/61a319f8/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index 2175f47..658f1e9 100644
--- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -285,6 +285,14 @@
<import resource="classpath:jetm-monitoring.conf" />
-->
+ <!--
+ ======================================================================
+ Metrics
+ ======================================================================
+ -->
+
+ <bean id="metricFactory" class="org.apache.james.metrics.dropwizard.DropWizardMetricFactory"/>
+
<beans profile="cassandra">
<import resource="classpath:META-INF/cassandra-session.xml"/>
http://git-wip-us.apache.org/repos/asf/james-project/blob/61a319f8/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml b/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
index 1545212..5c1b52c 100644
--- a/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
+++ b/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
@@ -18,21 +18,22 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
- xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- James Mail Queue Factory -->
- <bean id="mailqueuefactory" class="org.apache.james.queue.activemq.ActiveMQMailQueueFactory" depends-on="broker">
- <constructor-arg index="0" ref="jmsConnectionFactory"/>
- <constructor-arg index="1">
- <util:constant static-field="org.apache.james.queue.api.MailQueueItemDecoratorFactory.RAW_FACTORY"/>
- </constructor-arg>
- </bean>
+ <bean id="mailqueuefactory" class="org.apache.james.queue.activemq.ActiveMQMailQueueFactory" depends-on="broker">
+ <constructor-arg index="0" ref="jmsConnectionFactory"/>
+ <constructor-arg index="1">
+ <util:constant static-field="org.apache.james.queue.api.MailQueueItemDecoratorFactory.RAW_FACTORY"/>
+ </constructor-arg>
+ <constructor-arg index="2" ref="metricFactory"/>
+ </bean>
<!--
ActiveMQ Broker, Connections, Blob
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[15/16] james-project git commit: JAMES-1868 Adding app dependency
Posted by ro...@apache.org.
JAMES-1868 Adding app dependency
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6c9c5e62
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6c9c5e62
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6c9c5e62
Branch: refs/heads/master
Commit: 6c9c5e62d79728d0cf5b8e389f523f2491dbd449
Parents: b373bcd
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Nov 30 09:40:01 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 17:36:41 2016 +0700
----------------------------------------------------------------------
server/app/pom.xml | 8 ++++++++
1 file changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c9c5e62/server/app/pom.xml
----------------------------------------------------------------------
diff --git a/server/app/pom.xml b/server/app/pom.xml
index bf29ea1..4be0e15 100644
--- a/server/app/pom.xml
+++ b/server/app/pom.xml
@@ -253,6 +253,14 @@
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-dropwizard</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
<artifactId>james-server-protocols-library</artifactId>
<scope>runtime</scope>
</dependency>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[10/16] james-project git commit: JAMES-1868 Add documentation for
the metric feature
Posted by ro...@apache.org.
JAMES-1868 Add documentation for the metric feature
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/994c8d32
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/994c8d32
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/994c8d32
Branch: refs/heads/master
Commit: 994c8d32b248e2d8d1dd4f6bbf8035bd4f62f8be
Parents: 78f7dbb
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Nov 28 09:48:28 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:32:21 2016 +0700
----------------------------------------------------------------------
server/src/site/site.xml | 1 +
server/src/site/xdoc/metrics.xml | 70 +++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/994c8d32/server/src/site/site.xml
----------------------------------------------------------------------
diff --git a/server/src/site/site.xml b/server/src/site/site.xml
index a328ad4..3d136f8 100644
--- a/server/src/site/site.xml
+++ b/server/src/site/site.xml
@@ -79,6 +79,7 @@ Removed from trunk for now.
<item name="Domains" href="/manage-domains.html" />
<item name="Users" href="/manage-users.html" />
<item name="Recipient Rewrite" href="/manage-recipientrewrite.html" />
+ <item name="Metrics" href="/metrics.html" />
</item>
<item name="5. Monitor" href="/monitor.html" collapse="true" >
<item name="Logging" href="/monitor-logging.html" />
http://git-wip-us.apache.org/repos/asf/james-project/blob/994c8d32/server/src/site/xdoc/metrics.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/metrics.xml b/server/src/site/xdoc/metrics.xml
new file mode 100644
index 0000000..c0a32ab
--- /dev/null
+++ b/server/src/site/xdoc/metrics.xml
@@ -0,0 +1,70 @@
+<?xml version="1.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.
+-->
+<document>
+
+ <properties>
+ <title>Apache James Server 3 - Metrics</title>
+ </properties>
+
+ <body>
+
+ <section name="Presentation">
+
+ <p>James relies on the <a href="http://metrics.dropwizard.io/3.1.0/manual/core/">Dropwizard metric library</a>
+ for keeping track of some core metrics of James.</p>
+
+ <p>Such metrics are made available via JMX. You can connect for instance using VisualVM and the associated
+ mbean plugins.</p>
+
+ </section>
+
+ <section name="Available metrics">
+
+ <p>
+ Here are the available metrics :
+ <ul>
+ <li>Number of active SMTP connections</li>
+ <li>Number of SMTP commands received</li>
+ <li>Number of active IMAP connections</li>
+ <li>Number of IMAP commands received</li>
+ <li>Number of active LMTP connections</li>
+ <li>Number of LMTP commands received</li>
+ <li>Number of per queue number of enqueued mails</li>
+ <li>Number of sent emails</li>
+ <li>Number of delivered emails</li>
+ </ul>
+ </p>
+
+ <p>
+ In addition to these metrics, you can define your own metrics using the <b>Metrics</b> mailet. By adding
+ it in your mailet container, you can count emails that pass via any points. You can also, using matchers,
+ count emails that matches the conditions you defined.
+ </p>
+ </section>
+
+ <section name="Limitations">
+
+ <p>Those metrics are only available with Guice.</p>
+
+ </section>
+
+ </body>
+
+</document>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[03/16] james-project git commit: JAMES-1868 Add support for IMAP
related metrics
Posted by ro...@apache.org.
JAMES-1868 Add support for IMAP related metrics
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8e52e76a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8e52e76a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8e52e76a
Branch: refs/heads/master
Commit: 8e52e76a37c913b7c17ff25c740429193bcc7760
Parents: 0254c43
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Nov 24 11:55:20 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:29:32 2016 +0700
----------------------------------------------------------------------
server/protocols/protocols-imap4/pom.xml | 5 ++-
.../james/imapserver/netty/IMAPServer.java | 26 ++++--------
.../imapserver/netty/IMAPServerFactory.java | 36 ++++++----------
.../netty/ImapChannelUpstreamHandler.java | 20 +++++++--
.../james/imapserver/netty/ImapMetrics.java | 44 ++++++++++++++++++++
.../james/imapserver/netty/OioIMAPServer.java | 8 ++++
.../imapserver/netty/OioIMAPServerFactory.java | 15 ++++++-
.../META-INF/spring/imapserver-context.xml | 9 ++--
8 files changed, 112 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/pom.xml b/server/protocols/protocols-imap4/pom.xml
index d6d11c0..92f2cb6 100644
--- a/server/protocols/protocols-imap4/pom.xml
+++ b/server/protocols/protocols-imap4/pom.xml
@@ -41,7 +41,10 @@
<groupId>org.apache.james</groupId>
<artifactId>james-server-filesystem-api</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-imap</artifactId>
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
index da4d907..0d592c4 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
@@ -22,7 +22,6 @@ import static org.jboss.netty.channel.Channels.pipeline;
import java.util.concurrent.TimeUnit;
-import javax.inject.Inject;
import javax.net.ssl.SSLEngine;
import org.apache.commons.configuration.ConfigurationException;
@@ -55,9 +54,10 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
private static final String softwaretype = "JAMES " + VERSION + " Server ";
- private ImapProcessor processor;
- private ImapEncoder encoder;
- private ImapDecoder decoder;
+ private final ImapProcessor processor;
+ private final ImapEncoder encoder;
+ private final ImapDecoder decoder;
+ private final ImapMetrics imapMetrics;
private String hello;
private boolean compress;
@@ -72,19 +72,11 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
public final static int DEFAULT_TIMEOUT = 30 * 60; // default timeout is 30 seconds
public final static int DEFAULT_LITERAL_SIZE_LIMIT = 0;
- @Inject
- public void setImapProcessor(ImapProcessor processor) {
+ public IMAPServer(ImapDecoder decoder, ImapEncoder encoder, ImapProcessor processor, ImapMetrics imapMetrics) {
this.processor = processor;
- }
-
- @Inject
- public void setImapDecoder(ImapDecoder decoder) {
- this.decoder = decoder;
- }
-
- @Inject
- public void setImapEncoder(ImapEncoder encoder) {
this.encoder = encoder;
+ this.decoder = decoder;
+ this.imapMetrics = imapMetrics;
}
@Override
@@ -186,9 +178,9 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
ImapChannelUpstreamHandler coreHandler;
Encryption secure = getEncryption();
if (secure!= null && secure.isStartTLS()) {
- coreHandler = new ImapChannelUpstreamHandler(hello, processor, encoder, getLogger(), compress, plainAuthDisallowed, secure.getContext(), getEnabledCipherSuites());
+ coreHandler = new ImapChannelUpstreamHandler(hello, processor, encoder, getLogger(), compress, plainAuthDisallowed, secure.getContext(), getEnabledCipherSuites(), imapMetrics);
} else {
- coreHandler = new ImapChannelUpstreamHandler(hello, processor, encoder, getLogger(), compress, plainAuthDisallowed);
+ coreHandler = new ImapChannelUpstreamHandler(hello, processor, encoder, getLogger(), compress, plainAuthDisallowed, imapMetrics);
}
return coreHandler;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
index d29a8e1..cb92875 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
@@ -28,44 +28,35 @@ import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.decode.ImapDecoder;
import org.apache.james.imap.encode.ImapEncoder;
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
import org.apache.james.protocols.lib.netty.AbstractServerFactory;
import org.slf4j.Logger;
public class IMAPServerFactory extends AbstractServerFactory {
- private FileSystem fileSystem;
- private ImapDecoder decoder;
- private ImapEncoder encoder;
- private ImapProcessor processor;
-
- @Inject
- public final void setFileSystem(FileSystem filesystem) {
- this.fileSystem = filesystem;
- }
+ protected final FileSystem fileSystem;
+ protected final ImapDecoder decoder;
+ protected final ImapEncoder encoder;
+ protected final ImapProcessor processor;
+ protected final ImapMetrics imapMetrics;
@Inject
- public void setImapProcessor(ImapProcessor processor) {
- this.processor = processor;
- }
-
- @Inject
- public void setImapDecoder(ImapDecoder decoder) {
+ public IMAPServerFactory(FileSystem fileSystem, ImapDecoder decoder, ImapEncoder encoder, ImapProcessor processor, MetricFactory metricFactory) {
+ this.fileSystem = fileSystem;
this.decoder = decoder;
- }
-
- @Inject
- public void setImapEncoder(ImapEncoder encoder) {
this.encoder = encoder;
+ this.processor = processor;
+ this.imapMetrics = new ImapMetrics(metricFactory);
}
protected IMAPServer createServer() {
- return new IMAPServer();
+ return new IMAPServer(decoder, encoder, processor, imapMetrics);
}
@Override
protected List<AbstractConfigurableAsyncServer> createServers(Logger log, HierarchicalConfiguration config) throws Exception {
-
List<AbstractConfigurableAsyncServer> servers = new ArrayList<AbstractConfigurableAsyncServer>();
List<HierarchicalConfiguration> configs = config.configurationsAt("imapserver");
@@ -73,9 +64,6 @@ public class IMAPServerFactory extends AbstractServerFactory {
IMAPServer server = createServer();
server.setLog(log);
server.setFileSystem(fileSystem);
- server.setImapDecoder(decoder);
- server.setImapEncoder(encoder);
- server.setImapProcessor(processor);
server.configure(serverConfig);
servers.add(server);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
index cc24c20..50114ec 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
@@ -32,6 +32,7 @@ import org.apache.james.imap.encode.ImapEncoder;
import org.apache.james.imap.encode.ImapResponseComposer;
import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
import org.apache.james.imap.main.ResponseEncoder;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.protocols.api.logger.ProtocolLoggerAdapter;
import org.apache.james.protocols.api.logger.ProtocolSessionLogger;
import org.apache.james.protocols.lib.Slf4jLoggerAdapter;
@@ -70,12 +71,18 @@ public class ImapChannelUpstreamHandler extends SimpleChannelUpstreamHandler imp
private final ImapHeartbeatHandler heartbeatHandler = new ImapHeartbeatHandler();
private final boolean plainAuthDisallowed;
+
+ private final Metric imapConnectionsMetric;
+ private final Metric imapCommandsMetric;
- public ImapChannelUpstreamHandler(String hello, ImapProcessor processor, ImapEncoder encoder, Logger logger, boolean compress, boolean plainAuthDisallowed) {
- this(hello, processor, encoder, logger, compress, plainAuthDisallowed, null, null);
+ public ImapChannelUpstreamHandler(String hello, ImapProcessor processor, ImapEncoder encoder, Logger logger, boolean compress,
+ boolean plainAuthDisallowed, ImapMetrics imapMetrics) {
+ this(hello, processor, encoder, logger, compress, plainAuthDisallowed, null, null, imapMetrics);
}
- public ImapChannelUpstreamHandler(String hello, ImapProcessor processor, ImapEncoder encoder, Logger logger, boolean compress, boolean plainAuthDisallowed, SSLContext context, String[] enabledCipherSuites) {
+ public ImapChannelUpstreamHandler(String hello, ImapProcessor processor, ImapEncoder encoder, Logger logger, boolean compress,
+ boolean plainAuthDisallowed, SSLContext context, String[] enabledCipherSuites,
+ ImapMetrics imapMetrics) {
this.logger = logger;
this.hello = hello;
this.processor = processor;
@@ -84,6 +91,8 @@ public class ImapChannelUpstreamHandler extends SimpleChannelUpstreamHandler imp
this.enabledCipherSuites = enabledCipherSuites;
this.compress = compress;
this.plainAuthDisallowed = plainAuthDisallowed;
+ this.imapConnectionsMetric = imapMetrics.getConnectionsMetric();
+ this.imapCommandsMetric = imapMetrics.getCommandsMetric();
}
private Logger getLogger(Channel channel) {
@@ -108,6 +117,7 @@ public class ImapChannelUpstreamHandler extends SimpleChannelUpstreamHandler imp
ImapSession imapSession = (ImapSession) attributes.remove(ctx.getChannel());
if (imapSession != null)
imapSession.logout();
+ imapConnectionsMetric.decrement();
super.channelClosed(ctx, e);
}
@@ -117,6 +127,7 @@ public class ImapChannelUpstreamHandler extends SimpleChannelUpstreamHandler imp
InetSocketAddress address = (InetSocketAddress) ctx.getChannel().getRemoteAddress();
getLogger(ctx.getChannel()).info("Connection established from " + address.getAddress().getHostAddress());
+ imapConnectionsMetric.increment();
ImapResponseComposer response = new ImapResponseComposerImpl(new ChannelImapResponseWriter(ctx.getChannel()));
ctx.setAttachment(response);
@@ -171,7 +182,8 @@ public class ImapChannelUpstreamHandler extends SimpleChannelUpstreamHandler imp
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
-
+
+ imapCommandsMetric.increment();
ImapSession session = (ImapSession) attributes.get(ctx.getChannel());
ImapResponseComposer response = (ImapResponseComposer) ctx.getAttachment();
ImapMessage message = (ImapMessage) e.getMessage();
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapMetrics.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapMetrics.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapMetrics.java
new file mode 100644
index 0000000..f199816
--- /dev/null
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapMetrics.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.imapserver.netty;
+
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+
+public class ImapMetrics {
+ private static final String IMAP_COMMANDS = "imapCommands";
+ private static final String IMAP_CONNECTIONS = "imapConnections";
+
+ private final Metric commandsMetric;
+ private final Metric connectionsMetric;
+
+ public ImapMetrics(MetricFactory metricFactory) {
+ commandsMetric = metricFactory.generate(IMAP_COMMANDS);
+ connectionsMetric = metricFactory.generate(IMAP_CONNECTIONS);
+ }
+
+ public Metric getCommandsMetric() {
+ return commandsMetric;
+ }
+
+ public Metric getConnectionsMetric() {
+ return connectionsMetric;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
index 2e5368a..c3ce882 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
@@ -18,6 +18,10 @@
****************************************************************/
package org.apache.james.imapserver.netty;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.decode.ImapDecoder;
+import org.apache.james.imap.encode.ImapEncoder;
+import org.apache.james.metrics.api.Metric;
import org.jboss.netty.channel.socket.ServerSocketChannelFactory;
import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory;
import org.jboss.netty.handler.execution.ExecutionHandler;
@@ -28,6 +32,10 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
*/
public class OioIMAPServer extends IMAPServer {
+ public OioIMAPServer(ImapDecoder decoder, ImapEncoder encoder, ImapProcessor processor, ImapMetrics imapMetrics) {
+ super(decoder, encoder, processor, imapMetrics);
+ }
+
@Override
protected ServerSocketChannelFactory createSocketChannelFactory() {
return new OioServerSocketChannelFactory(createBossExecutor(), createWorkerExecutor());
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
index 5743f2a..5b6a12a 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
@@ -18,11 +18,24 @@
****************************************************************/
package org.apache.james.imapserver.netty;
+import javax.inject.Inject;
+
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.decode.ImapDecoder;
+import org.apache.james.imap.encode.ImapEncoder;
+import org.apache.james.metrics.api.MetricFactory;
+
public class OioIMAPServerFactory extends IMAPServerFactory {
+ @Inject
+ public OioIMAPServerFactory(FileSystem fileSystem, ImapDecoder decoder, ImapEncoder encoder, ImapProcessor processor, MetricFactory metricFactory) {
+ super(fileSystem, decoder, encoder, processor, metricFactory);
+ }
+
@Override
protected IMAPServer createServer() {
- return new OioIMAPServer();
+ return new OioIMAPServer(decoder, encoder, processor, imapMetrics);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8e52e76a/server/protocols/protocols-imap4/src/main/resources/META-INF/spring/imapserver-context.xml
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/resources/META-INF/spring/imapserver-context.xml b/server/protocols/protocols-imap4/src/main/resources/META-INF/spring/imapserver-context.xml
index 7ae7156..b48e89e 100644
--- a/server/protocols/protocols-imap4/src/main/resources/META-INF/spring/imapserver-context.xml
+++ b/server/protocols/protocols-imap4/src/main/resources/META-INF/spring/imapserver-context.xml
@@ -20,10 +20,11 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="imapserver" class="org.apache.james.imapserver.netty.IMAPServerFactory">
- <property name="imapProcessor" ref="imapProcessor"/>
- <property name="imapEncoder" ref="imapEncoder"/>
- <property name="imapDecoder" ref="imapDecoder"/>
- <property name="fileSystem" ref="filesystem"/>
+ <constructor-arg index="0" ref="filesystem" />
+ <constructor-arg index="1" ref="imapDecoder" />
+ <constructor-arg index="2" ref="imapEncoder" />
+ <constructor-arg index="3" ref="imapProcessor" />
+ <constructor-arg index="4" ref="metricFactory" />
</bean>
<!-- The imapProcessor configuration will be reviewed when IMAP will be integrated into Protocols project -->
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[14/16] james-project git commit: JAMES-1868 Remove Spring support
for Cassandra and ElasticSearch
Posted by ro...@apache.org.
JAMES-1868 Remove Spring support for Cassandra and ElasticSearch
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b373bcd6
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b373bcd6
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b373bcd6
Branch: refs/heads/master
Commit: b373bcd6ecb5d6fca4be364fa4533dcaf655bcc9
Parents: 994c8d3
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Nov 30 09:32:22 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 17:36:37 2016 +0700
----------------------------------------------------------------------
.../META-INF/spring/mailbox-cassandra.xml | 94 --------------------
.../META-INF/spring/mailbox-elasticsearch.xml | 72 ---------------
.../main/resources/META-INF/spring/kafka.xml | 42 ---------
.../META-INF/spring/spring-mailbox.xml | 7 --
.../resources/cassandra-template.properties | 28 ------
.../resources/elasticsearch-template.properties | 24 -----
.../app/src/main/resources/indexer-template.xml | 2 +-
.../META-INF/org/apache/james/spring-server.xml | 5 --
8 files changed, 1 insertion(+), 273 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/mailbox/cassandra/src/main/resources/META-INF/spring/mailbox-cassandra.xml
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/resources/META-INF/spring/mailbox-cassandra.xml b/mailbox/cassandra/src/main/resources/META-INF/spring/mailbox-cassandra.xml
deleted file mode 100644
index 5078a18..0000000
--- a/mailbox/cassandra/src/main/resources/META-INF/spring/mailbox-cassandra.xml
+++ /dev/null
@@ -1,94 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
-
- <bean id="cassandra-mailboxIdFactory" class="org.apache.james.mailbox.cassandra.CassandraId.Factory" />
- <!--
- Mailbox Cassandra
- -->
- <bean id="cassandra-mailboxmanager"
- class="org.apache.james.mailbox.cassandra.CassandraMailboxManager"
- init-method="init"
- lazy-init="true">
- <constructor-arg index="0" ref="cassandra-sessionMapperFactory"/>
- <constructor-arg index="1" ref="authenticator"/>
- <constructor-arg index="2" ref="cassandra-locker"/>
- <constructor-arg index="3" ref="messageIdFactory" />
- <property name="messageSearchIndex" ref="elasticsearch-listener"/>
- <property name="quotaManager" ref="quotaManager"/>
- <property name="quotaRootResolver" ref="quotaRootResolver"/>
- <property name="quotaUpdater" ref="quotaUpdater"/>
- <property name="delegatingMailboxListener" ref="delegating-listener"/>
- </bean>
-
- <bean id ="cassandra-subscriptionManager"
- class="org.apache.james.mailbox.cassandra.CassandraSubscriptionManager"
- lazy-init="true">
- <constructor-arg index="0" ref="cassandra-sessionMapperFactory"/>
- </bean>
-
- <bean id="cassandra-sessionMapperFactory"
- class="org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory"
- lazy-init="true">
- <constructor-arg index="0" ref="cassandra-uidProvider"/>
- <constructor-arg index="1" ref="cassandra-modSeqProvider"/>
- <constructor-arg index="2" ref="cassandra-session"/>
- <constructor-arg index="3" ref="cassandra-type-provider"/>
- </bean>
-
- <bean id="cassandra-uidProvider"
- class="org.apache.james.mailbox.cassandra.mail.CassandraUidProvider"
- lazy-init="true">
- <constructor-arg index="0" ref="cassandra-session"/>
- </bean>
-
- <bean id="cassandra-modSeqProvider"
- class="org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider"
- lazy-init="true">
- <constructor-arg index="0" ref="cassandra-session"/>
- </bean>
-
- <alias name="no-locker" alias="cassandra-locker"/>
-
- <bean name="cassandraMaxQuotaManager"
- class="org.apache.james.mailbox.cassandra.quota.CassandraPerUserMaxQuotaManager"
- lazy-init="true">
- <constructor-arg index="0" ref="cassandra-session"/>
- </bean>
-
- <bean name="cassandraCurrentQuotaManager"
- class="org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManager"
- lazy-init="true">
- <constructor-arg index="0" ref="cassandra-session"/>
- </bean>
-
- <bean id="cassandra-mailbox-id-deserializer" class="org.apache.james.mailbox.cassandra.CassandraMailboxIdDeserializer"/>
-
- <bean id="cassandra-mailbox-path-register-mapper" class="org.apache.james.mailbox.cassandra.event.distributed.CassandraMailboxPathRegisterMapper" lazy-init="true">
- <constructor-arg index="0" ref="cassandra-session"/>
- <constructor-arg index="1" ref="cassandra-type-provider"/>
- <constructor-arg index="2" ref="${cassandra.mailbox.path.register.mapper.ttl}"/>
- </bean>
-
-</beans>
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/mailbox/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml b/mailbox/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml
deleted file mode 100644
index a2e9cb3..0000000
--- a/mailbox/elasticsearch/src/main/resources/META-INF/spring/mailbox-elasticsearch.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
-
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="ignoreUnresolvablePlaceholders" value="true"/>
- <property name ="location" value="classpath:elasticsearch.properties"/>
- </bean>
-
- <bean id="elasticsearch-listener" class="org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex">
- <constructor-arg index="0" ref="messageMapperFactory"/>
- <constructor-arg index="1" ref="elasticsearch-indexer"/>
- <constructor-arg index="2" ref="elasticsearch-searcher"/>
- <constructor-arg index="3" ref="elasticsearch-json"/>
- </bean>
-
- <bean id="elasticsearch-indexer" class="org.apache.james.mailbox.elasticsearch.ElasticSearchIndexer">
- <constructor-arg index="0" ref="elasticsearch-clientprovider-2"/>
- </bean>
-
- <bean id="elasticsearch-json" class="org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson">
- <constructor-arg index="0" ref="text-extractor"/>
- </bean>
-
- <bean id="elasticsearch-searcher" class="org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher">
- <constructor-arg index="0" ref="elasticsearch-clientprovider-2"/>
- <constructor-arg index="1" ref="query-converter"/>
- </bean>
-
- <bean id="elasticsearch-clientprovider-0" class="org.apache.james.mailbox.elasticsearch.ClientProviderImpl">
- <constructor-arg index="0" value="${elasticsearch.masterHost}"/>
- <constructor-arg index="1" value="${elasticsearch.port}"/>
- </bean>
-
- <bean id="elasticsearch-clientprovider-2" class="org.apache.james.mailbox.elasticsearch.NodeMappingFactory" factory-method="applyMapping">
- <constructor-arg index="0" ref="elasticsearch-clientprovider-1"/>
- </bean>
-
- <bean id="elasticsearch-clientprovider-1" class="org.apache.james.mailbox.elasticsearch.IndexCreationFactory" factory-method="createIndex">
- <constructor-arg index="0" ref="elasticsearch-clientprovider-0"/>
- </bean>
-
- <bean id="query-converter" class="org.apache.james.mailbox.elasticsearch.query.QueryConverter">
- <constructor-arg index="0" ref="criterion-converter"/>
- </bean>
-
- <bean id="criterion-converter" class="org.apache.james.mailbox.elasticsearch.query.CriterionConverter"/>
-
- <bean id="text-extractor" class="org.apache.james.mailbox.tika.extractor.TikaTextExtractor"/>
-
-</beans>
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/mailbox/kafka/src/main/resources/META-INF/spring/kafka.xml
----------------------------------------------------------------------
diff --git a/mailbox/kafka/src/main/resources/META-INF/spring/kafka.xml b/mailbox/kafka/src/main/resources/META-INF/spring/kafka.xml
deleted file mode 100644
index 870cebf..0000000
--- a/mailbox/kafka/src/main/resources/META-INF/spring/kafka.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
-
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="ignoreUnresolvablePlaceholders" value="true"/>
- <property name ="location" value="classpath:events.properties"/>
- </bean>
-
- <bean id="kafka-publisher" class="org.apache.james.mailbox.kafka.KafkaPublisher" lazy-init="true">
- <constructor-arg index="0" ref="${kafka.ip}"/>
- <constructor-arg index="1" ref="${kafka.port}"/>
- </bean>
-
- <bean id="kafka-consumer" class="org.apache.james.mailbox.kafka.KafkaMessageConsumer" lazy-init="true">
- <constructor-arg index="0" ref="${zookeeper.connection.string}"/>
- <constructor-arg index="1" ref="${group.id}"/>
- <constructor-arg index="2" ref="${event.thread.count}"/>
- </bean>
-
-</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
index f681a0d..db43d6a 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
@@ -60,11 +60,4 @@
-->
<bean id="messageParser" class="org.apache.james.mailbox.store.mail.model.impl.MessageParser"/>
-
-
- <beans profile="cassandra">
- <import resource="classpath:META-INF/spring/mailbox-cassandra.xml"/>
- <import resource="classpath:META-INF/spring/mailbox-elasticsearch.xml"/>
- <!-- <import resource="classpath:META-INF/spring/kafka.xml"/> -->
- </beans>
</beans>
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/server/app/src/main/resources/cassandra-template.properties
----------------------------------------------------------------------
diff --git a/server/app/src/main/resources/cassandra-template.properties b/server/app/src/main/resources/cassandra-template.properties
deleted file mode 100644
index 0dd2c2a..0000000
--- a/server/app/src/main/resources/cassandra-template.properties
+++ /dev/null
@@ -1,28 +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.
-
-# This template file can be used as example for James Server configuration
-# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
-
-# Configuration file for cassandra mailbox
-
-cassandra.ip=127.0.0.1
-cassandra.port=9042
-cassandra.keyspace=apache_james
-cassandra.replication.factor=1
-
-cassandra.mailbox.path.register.mapper.ttl=1800
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/server/app/src/main/resources/elasticsearch-template.properties
----------------------------------------------------------------------
diff --git a/server/app/src/main/resources/elasticsearch-template.properties b/server/app/src/main/resources/elasticsearch-template.properties
deleted file mode 100644
index cec4be8..0000000
--- a/server/app/src/main/resources/elasticsearch-template.properties
+++ /dev/null
@@ -1,24 +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.
-
-# This template file can be used as example for James Server configuration
-# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
-
-# Configuration file for ElasticSearch
-
-elasticsearch.clusterName=elasticsearch
-elasticsearch.masterHost=127.0.0.1
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/server/app/src/main/resources/indexer-template.xml
----------------------------------------------------------------------
diff --git a/server/app/src/main/resources/indexer-template.xml b/server/app/src/main/resources/indexer-template.xml
index 8fd7248..24c52e7 100644
--- a/server/app/src/main/resources/indexer-template.xml
+++ b/server/app/src/main/resources/indexer-template.xml
@@ -27,7 +27,7 @@
<indexer>
<!-- supported providers are: -->
- <!-- lazyIndex, luceneIndex, elasticsearch -->
+ <!-- lazyIndex, luceneIndex -->
<!-- -->
<provider>luceneIndex</provider>
</indexer>
http://git-wip-us.apache.org/repos/asf/james-project/blob/b373bcd6/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index 658f1e9..4a05a83 100644
--- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -293,9 +293,4 @@
<bean id="metricFactory" class="org.apache.james.metrics.dropwizard.DropWizardMetricFactory"/>
-
- <beans profile="cassandra">
- <import resource="classpath:META-INF/cassandra-session.xml"/>
- </beans>
-
</beans>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[12/16] james-project git commit: MAILET-115 Introduce builder for
FakeMailetConfig
Posted by ro...@apache.org.
MAILET-115 Introduce builder for FakeMailetConfig
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7a9c4382
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7a9c4382
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7a9c4382
Branch: refs/heads/master
Commit: 7a9c43820efdf11c3c319cc1b77a971c97d71992
Parents: 67bbb4b
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Nov 30 16:28:30 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:32:21 2016 +0700
----------------------------------------------------------------------
.../org/apache/mailet/base/MailetUtilTest.java | 21 +++---
.../mailet/base/test/FakeMailetConfig.java | 74 +++++++++++--------
.../james/transport/mailets/AddFooterTest.java | 60 ++++++++++------
.../transport/mailets/AddSubjectPrefixTest.java | 28 +++++---
.../james/transport/mailets/LogMessageTest.java | 60 +++++++++++++---
.../MailAttributesToMimeHeadersTest.java | 34 +++++----
.../james/transport/mailets/OnlyTextTest.java | 9 ++-
.../mailets/RemoveAllMailAttributesTest.java | 5 +-
.../mailets/RemoveMailAttributeTest.java | 26 +++++--
.../transport/mailets/RemoveMimeHeaderTest.java | 38 ++++++----
.../transport/mailets/ReplaceContentTest.java | 67 +++++++++++------
.../transport/mailets/SetMailAttributeTest.java | 33 ++++-----
.../transport/mailets/SetMimeHeaderTest.java | 60 ++++++++++------
.../transport/mailets/StripAttachmentTest.java | 75 +++++++++++---------
.../transport/mailets/ToProcessorTest.java | 42 ++++++++---
.../james/jmap/MailetPreconditionTest.java | 14 ++--
.../james/transport/mailets/BounceTest.java | 5 +-
.../mailets/RecipientRewriteTableTest.java | 7 +-
.../transport/mailets/ToRepositoryTest.java | 24 +++++--
.../mailets/delivery/LocalDeliveryTest.java | 5 +-
.../mailets/delivery/ToRecipientFolderTest.java | 46 ++++++++----
.../managesieve/ManageSieveMailetTestCase.java | 7 +-
.../james/jmap/mailet/VacationMailetTest.java | 5 +-
23 files changed, 485 insertions(+), 260 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java b/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
index 9a6700f..db1f131 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
@@ -22,20 +22,12 @@ package org.apache.mailet.base;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.mailet.base.test.FakeMailetConfig;
-import org.junit.Before;
import org.junit.Test;
public class MailetUtilTest {
private static final String A_PARAMETER = "aParameter";
- FakeMailetConfig config;
-
- @Before
- public void setUp() throws Exception {
- config = new FakeMailetConfig();
- }
-
@Test
public void getInitParameterShouldReturnTrueWhenIsValueTrueLowerCase() {
assertThat(getParameterValued("true", false)).isTrue();
@@ -86,13 +78,16 @@ public class MailetUtilTest {
@Test
public void getInitParameterShouldReturnDefaultValueWhenNull() {
- assertThat(MailetUtil.getInitParameter(config, A_PARAMETER, false)).isFalse();
- assertThat(MailetUtil.getInitParameter(config, A_PARAMETER, true)).isTrue();
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .build();
+ assertThat(MailetUtil.getInitParameter(mailetConfig, A_PARAMETER, false)).isFalse();
+ assertThat(MailetUtil.getInitParameter(mailetConfig, A_PARAMETER, true)).isTrue();
}
private boolean getParameterValued(String value, boolean defaultValue) {
- config.clear();
- config.setProperty(A_PARAMETER, value);
- return MailetUtil.getInitParameter(config, A_PARAMETER, defaultValue);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .setProperty(A_PARAMETER, value)
+ .build();
+ return MailetUtil.getInitParameter(mailetConfig, A_PARAMETER, defaultValue);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java
index 83533c1..23dff08 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java
@@ -25,28 +25,59 @@ import java.util.Properties;
import org.apache.mailet.MailetConfig;
import org.apache.mailet.MailetContext;
+import com.google.common.base.Optional;
+
/**
* MailetConfig over Properties
*/
public class FakeMailetConfig implements MailetConfig {
- public String mailetName;
- public MailetContext mc;
-
- private final Properties properties;
-
- public FakeMailetConfig() {
- this("A Mailet", FakeMailContext.defaultContext());
+ public static Builder builder() {
+ return new Builder();
}
-
- public FakeMailetConfig(String mailetName, MailetContext mc) {
- this(mailetName, mc, new Properties());
+
+ public static class Builder {
+
+ private Optional<String> mailetName;
+ private Optional<MailetContext> mailetContext;
+ private Properties properties;
+
+ private Builder() {
+ mailetName = Optional.absent();
+ mailetContext = Optional.absent();
+ properties = new Properties();
+ }
+
+ public Builder mailetName(String mailetName) {
+ this.mailetName = Optional.fromNullable(mailetName);
+ return this;
+ }
+
+ public Builder mailetContext(MailetContext mailetContext) {
+ this.mailetContext = Optional.fromNullable(mailetContext);
+ return this;
+ }
+
+ public Builder setProperty(String key, String value) {
+ this.properties.setProperty(key, value);
+ return this;
+ }
+
+ public FakeMailetConfig build() {
+ return new FakeMailetConfig(mailetName.or("A Mailet"),
+ mailetContext.or(FakeMailContext.defaultContext()),
+ properties);
+ }
}
- public FakeMailetConfig(String mailetName, MailetContext mc, Properties arg0) {
+ private final String mailetName;
+ private final MailetContext mailetContext;
+ private final Properties properties;
+
+ private FakeMailetConfig(String mailetName, MailetContext mailetContext, Properties properties) {
this.mailetName = mailetName;
- this.mc = mc;
- this.properties = arg0;
+ this.mailetContext = mailetContext;
+ this.properties = properties;
}
public String getInitParameter(String name) {
@@ -58,25 +89,10 @@ public class FakeMailetConfig implements MailetConfig {
}
public MailetContext getMailetContext() {
- return mc;
+ return mailetContext;
}
public String getMailetName() {
return mailetName;
}
-
- // Override setProperty to work like it should in this MockMailetConfig
- public Object setProperty(String key, String value) {
- String oldValue = properties.getProperty(key);
- String newValue = value;
-
- if (oldValue != null) {
- newValue = oldValue + "," + value;
- }
- return properties.setProperty(key, newValue);
- }
-
- public void clear() {
- properties.clear();
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
index 9b8d8cf..cfdb7bc 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
@@ -33,7 +33,6 @@ import javax.mail.MessagingException;
import org.apache.mailet.Mail;
import org.apache.mailet.Mailet;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -57,7 +56,6 @@ public class AddFooterTest {
private final String javaCharset;
private final String javaMailCharset;
private Mailet mailet;
- private FakeMailetConfig mailetConfig;
@Parameters
public static Collection<String[]> data() {
@@ -90,14 +88,14 @@ public class AddFooterTest {
@Before
public void setup() {
mailet = new AddFooter();
- mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
-
}
@Test
public void shouldAddFooterWhenQuotedPrintableTextPlainMessage() throws MessagingException, IOException {
-
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String quotedPrintableTextPlainMessage = Joiner.on("\r\n").join(
@@ -120,8 +118,10 @@ public class AddFooterTest {
@Test
public void shouldEnsureCarriageReturnWhenAddFooterWithTextPlainMessage() throws MessagingException, IOException {
-
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String quotedPrintableTextPlainMessage = Joiner.on("\r\n").join(
@@ -151,7 +151,10 @@ public class AddFooterTest {
@Test
public void shouldNotAddFooterWhenUnsupportedEncoding() throws MessagingException, IOException {
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String quotedPrintableTextPlainMessage = Joiner.on("\r\n").join(
@@ -171,7 +174,10 @@ public class AddFooterTest {
@Test
public void shouldNotAddFooterWhenUnsupportedTextContentType() throws MessagingException, IOException {
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String quotedPrintableTextPlainMessage = Joiner.on("\r\n").join(
@@ -195,7 +201,10 @@ public class AddFooterTest {
*/
@Test
public void shouldNotAddFooterWhenNestedUnsupportedMultipart() throws MessagingException, IOException {
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String quotedPrintableMultipartMixedMessage = Joiner.on("\r\n").join(
@@ -228,8 +237,10 @@ public class AddFooterTest {
*/
@Test
public void shouldAddFooterWhenMultipartRelatedHtmlMessage() throws MessagingException, IOException {
-
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String htmlMultipartRelatedMessagePart1 = Joiner.on("\r\n").join(
@@ -279,8 +290,10 @@ public class AddFooterTest {
@Test
public void shouldAddFooterWhenMultipartAlternivateMessage() throws MessagingException,
IOException {
-
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String multipartAlternativeMessage = Joiner.on("\r\n").join(
@@ -337,8 +350,10 @@ public class AddFooterTest {
@Test
public void shouldAddFooterWhenHtmlMessageWithMixedCaseBodyTag() throws MessagingException,
IOException {
-
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String htmlMessage = Joiner.on("\r\n").join(
@@ -372,8 +387,10 @@ public class AddFooterTest {
@Test
public void shouldAddFooterWhenHtmlMessageWithNoBodyTag() throws MessagingException,
IOException {
-
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
String htmlMessage = Joiner.on("\r\n").join(
@@ -407,7 +424,10 @@ public class AddFooterTest {
@SuppressWarnings("unchecked")
@Test
public void shouldThrowMessagingExceptionWhenIOExceptionReadingMessage() throws MessagingException {
- mailetConfig.setProperty("text", "------ my footer \u00E0/\u20AC ------");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("text", "------ my footer \u00E0/\u20AC ------")
+ .build();
mailet.init(mailetConfig);
Mail mail = mock(Mail.class);
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
index 9715900..26c5bb4 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
@@ -27,7 +27,6 @@ import javax.mail.internet.MimeMessage;
import org.apache.mailet.Mailet;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -40,17 +39,18 @@ public class AddSubjectPrefixTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
private Mailet mailet;
- private FakeMailetConfig mailetConfig;
@Before
public void setup() {
mailet = new AddSubjectPrefix();
- mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
}
@Test
public void shouldAddPrefixToSubject() throws MessagingException {
- mailetConfig.setProperty("subjectPrefix", "JUNIT");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPrefix", "JUNIT")
+ .build();
mailet.init(mailetConfig);
MimeMessage mockedMimeMessage = MailUtil.createMimeMessageWithSubject("test");
@@ -64,7 +64,10 @@ public class AddSubjectPrefixTest {
@Test
public void shouldAddPrefixToEncodedSubject() throws MessagingException {
- mailetConfig.setProperty("subjectPrefix", "\u0420\u0443\u0441\u0441\u043a\u0438\u0439");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPrefix", "\u0420\u0443\u0441\u0441\u043a\u0438\u0439")
+ .build();
mailet.init(mailetConfig);
String subject =
@@ -80,7 +83,10 @@ public class AddSubjectPrefixTest {
@Test
public void shouldDefinePrefixAsSubjectWhenNoSubject() throws MessagingException {
- mailetConfig.setProperty("subjectPrefix", "JUNIT");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPrefix", "JUNIT")
+ .build();
mailet.init(mailetConfig);
String noSubject = null;
@@ -94,7 +100,10 @@ public class AddSubjectPrefixTest {
@Test
public void shouldDefinePrefixAsSubjectWhenEmptySubject() throws MessagingException {
- mailetConfig.setProperty("subjectPrefix", "JUNIT");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPrefix", "JUNIT")
+ .build();
mailet.init(mailetConfig);
MimeMessage mockedMimeMessage = MailUtil.createMimeMessageWithSubject("");
@@ -107,7 +116,10 @@ public class AddSubjectPrefixTest {
@Test
public void shouldThrowWhenEmptyPrefix() throws MessagingException {
- mailetConfig.setProperty("subjectPrefix", "");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPrefix", "")
+ .build();
expectedException.expect(MessagingException.class);
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java
index c61e093..b037d33 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java
@@ -52,16 +52,16 @@ public class LogMessageTest {
public ExpectedException expectedException = ExpectedException.none();
private LogMessage mailet;
- private FakeMailetConfig mailetConfig;
+ private FakeMailContext mailContext;
private Logger logger;
+
@Before
public void setup() {
logger = mock(Logger.class);
- FakeMailContext mailContext = FakeMailContext.builder()
+ mailContext = FakeMailContext.builder()
.logger(logger)
.build();
- mailetConfig = new FakeMailetConfig("LogContext", mailContext);
mailet = new LogMessage();
}
@@ -72,12 +72,20 @@ public class LogMessageTest {
@Test
public void initShouldIgnoreExceptions() throws Exception {
- mailetConfig.setProperty("maxBody", "comment");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .setProperty("maxBody", "comment")
+ .build();
mailet.init(mailetConfig);
}
@Test
public void serviceShouldFailWhenMailHasNoStream() throws Exception {
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -97,6 +105,10 @@ public class LogMessageTest {
@Test
public void serviceShouldLog() throws Exception {
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .build();
mailet.init(mailetConfig);
mailet.service(createMail());
@@ -111,6 +123,10 @@ public class LogMessageTest {
@Test
public void serviceShouldLogWhenExceptionOccured() throws Exception {
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .build();
mailet.init(mailetConfig);
Mail mail = mock(Mail.class);
@@ -130,7 +146,11 @@ public class LogMessageTest {
@Test
public void serviceShouldSetTheMailStateWhenPassThroughIsFalse() throws Exception {
- mailetConfig.setProperty("passThrough", "false");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .setProperty("passThrough", "false")
+ .build();
mailet.init(mailetConfig);
FakeMail mail = createMail();
@@ -141,7 +161,11 @@ public class LogMessageTest {
@Test
public void serviceShouldNotChangeTheMailStateWhenPassThroughIsTrue() throws Exception {
- mailetConfig.setProperty("passThrough", "true");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .setProperty("passThrough", "true")
+ .build();
mailet.init(mailetConfig);
FakeMail mail = createMail();
@@ -153,7 +177,11 @@ public class LogMessageTest {
@Test
public void serviceShouldNotLogHeadersWhenFalse() throws Exception {
- mailetConfig.setProperty("headers", "false");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .setProperty("headers", "false")
+ .build();
mailet.init(mailetConfig);
mailet.service(createMail());
@@ -165,7 +193,11 @@ public class LogMessageTest {
@Test
public void serviceShouldNotLogBodyWhenFalse() throws Exception {
- mailetConfig.setProperty("body", "false");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .setProperty("body", "false")
+ .build();
mailet.init(mailetConfig);
mailet.service(createMail());
@@ -179,7 +211,11 @@ public class LogMessageTest {
@Test
public void serviceShouldNotLogFullBodyWhenBodyMaxIsSet() throws Exception {
- mailetConfig.setProperty("maxBody", "2");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .setProperty("maxBody", "2")
+ .build();
mailet.init(mailetConfig);
mailet.service(createMail());
@@ -194,7 +230,11 @@ public class LogMessageTest {
@Test
public void serviceShouldLogAdditionalCommentWhenCommentIsSet() throws Exception {
- mailetConfig.setProperty("comment", "comment");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("LogContext")
+ .mailetContext(mailContext)
+ .setProperty("comment", "comment")
+ .build();
mailet.init(mailetConfig);
mailet.service(createMail());
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
index 5147d71..8a5ac95 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
@@ -28,7 +28,6 @@ import javax.mail.internet.MimeMessage;
import org.apache.mailet.Mailet;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -58,10 +57,13 @@ public class MailAttributesToMimeHeadersTest {
@Test
public void shouldPutAttributesIntoHeadersWhenMappingDefined() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("simplemapping", MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1);
- mailetConfig.setProperty("simplemapping", MAIL_ATTRIBUTE_NAME2 + "; " + HEADER_NAME2);
- mailetConfig.setProperty("simplemapping", "another.attribute" + "; " + "Another-Header");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("simplemapping",
+ MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1 +
+ "," + MAIL_ATTRIBUTE_NAME2 + "; " + HEADER_NAME2 +
+ "," + "another.attribute" + "; " + "Another-Header")
+ .build();
mailet.init(mailetConfig);
FakeMail mockedMail = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
@@ -77,8 +79,10 @@ public class MailAttributesToMimeHeadersTest {
@Test
public void shouldAddAttributeIntoHeadersWhenHeaderAlreadyPresent() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("simplemapping", MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("simplemapping", MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1)
+ .build();
mailet.init(mailetConfig);
MimeMessage mimeMessage = MailUtil.createMimeMessage();
@@ -94,23 +98,29 @@ public class MailAttributesToMimeHeadersTest {
@Test
public void shouldThrowAtInitWhenNoSemicolumnInConfigurationEntry() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("simplemapping", "invalidConfigEntry");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("simplemapping", "invalidConfigEntry")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
@Test
public void shouldThrowAtInitWhenTwoSemicolumnsInConfigurationEntry() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("simplemapping", "first;second;third");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("simplemapping", "first;second;third")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
@Test
public void shouldThrowAtInitWhenNoConfigurationEntry() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/OnlyTextTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/OnlyTextTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/OnlyTextTest.java
index 1e3688c..56572cf 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/OnlyTextTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/OnlyTextTest.java
@@ -31,7 +31,6 @@ import javax.mail.internet.MimeMultipart;
import org.apache.mailet.Mail;
import org.apache.mailet.Mailet;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import junit.framework.TestCase;
@@ -53,7 +52,9 @@ public class OnlyTextTest extends TestCase {
Mail mail;
mailet = new OnlyText();
- mci = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+ mci = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
mailet.init(mci);
// ----------------
@@ -178,7 +179,9 @@ public class OnlyTextTest extends TestCase {
public void testHtml2Text() throws MessagingException {
OnlyText mailet = new OnlyText();
- mailet.init(new FakeMailetConfig("Test", FakeMailContext.defaultContext()));
+ mailet.init(FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build());
String html;
html = "<b>Prova di html</b><br /><p>Un paragrafo</p><LI>e ci mettiamo anche una lista</LI><br>";
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
index c6e7ab8..7f2c0e3 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
@@ -26,7 +26,6 @@ import javax.mail.MessagingException;
import org.apache.mailet.Mail;
import org.apache.mailet.Mailet;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -39,7 +38,9 @@ public class RemoveAllMailAttributesTest {
@Before
public void setUp() throws Exception {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
mailet = new RemoveAllMailAttributes();
mailet.init(mailetConfig);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMailAttributeTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMailAttributeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMailAttributeTest.java
index 292440d..fd9bb39 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMailAttributeTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMailAttributeTest.java
@@ -27,7 +27,6 @@ import org.apache.mailet.Mail;
import org.apache.mailet.Mailet;
import org.apache.mailet.MailetException;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.junit.Before;
import org.junit.Test;
@@ -42,12 +41,10 @@ public class RemoveMailAttributeTest {
private static final String VALUE_3 = "value3";
private static final String ATTRIBUTE1_ATTRIBUTE2 = "attribute1, attribute2";
private Mailet removeMailet;
- private FakeMailetConfig mailetConfig;
@Before
public void setup() throws Exception {
removeMailet = new RemoveMailAttribute();
- mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
}
@Test
@@ -57,6 +54,9 @@ public class RemoveMailAttributeTest {
@Test(expected = MailetException.class)
public void initShouldThrowExceptionIfMailetConfigDoesNotContainAttribute() throws MessagingException {
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
removeMailet.init(mailetConfig);
}
@@ -67,7 +67,10 @@ public class RemoveMailAttributeTest {
@Test
public void serviceShouldDoNothingWhenMailHasEmptyAttribute() throws MessagingException {
- mailetConfig.setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE1_ATTRIBUTE2);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE1_ATTRIBUTE2)
+ .build();
removeMailet.init(mailetConfig);
Mail mail = FakeMail.builder().build();
@@ -78,7 +81,10 @@ public class RemoveMailAttributeTest {
@Test
public void serviceShouldDoNothingWhenMailDoNotMatchAttribute() throws MessagingException {
- mailetConfig.setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE1_ATTRIBUTE2);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE1_ATTRIBUTE2)
+ .build();
removeMailet.init(mailetConfig);
Mail mail = FakeMail.builder()
@@ -91,7 +97,10 @@ public class RemoveMailAttributeTest {
@Test
public void serviceShouldRemoveSpecifiedAttribute() throws MessagingException {
- mailetConfig.setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE_1);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE_1)
+ .build();
removeMailet.init(mailetConfig);
Mail mail = FakeMail.builder()
@@ -106,7 +115,10 @@ public class RemoveMailAttributeTest {
@Test
public void serviceShouldRemoveSpecifiedAttributes() throws MessagingException {
- mailetConfig.setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE1_ATTRIBUTE2);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty(RemoveMailAttribute.MAILET_NAME_PARAMETER, ATTRIBUTE1_ATTRIBUTE2)
+ .build();
removeMailet.init(mailetConfig);
Mail mail = FakeMail.builder()
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
index 8bc5c5a..4477d0f 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
@@ -30,7 +30,6 @@ import javax.mail.internet.MimeMessage;
import org.apache.mailet.Mail;
import org.apache.mailet.base.GenericMailet;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -60,8 +59,10 @@ public class RemoveMimeHeaderTest {
@Test
public void serviceShouldRemoveHeaderWhenOneMatching() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", HEADER1);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", HEADER1)
+ .build();
mailet.init(mailetConfig);
MimeMessage mimeMessage = MailUtil.createMimeMessage();
@@ -78,9 +79,10 @@ public class RemoveMimeHeaderTest {
@Test
public void serviceShouldRemoveHeadersWhenTwoMatching() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", HEADER1);
- mailetConfig.setProperty("name", HEADER2);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", HEADER1 + "," + HEADER2)
+ .build();
mailet.init(mailetConfig);
MimeMessage mimeMessage = MailUtil.createMimeMessage();
@@ -97,9 +99,11 @@ public class RemoveMimeHeaderTest {
@Test
public void serviceShouldNotRemoveHeaderWhenNoneMatching() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "other1");
- mailetConfig.setProperty("name", "other2");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "other1")
+ .setProperty("name", "other2")
+ .build();
mailet.init(mailetConfig);
MimeMessage mimeMessage = MailUtil.createMimeMessage();
@@ -116,8 +120,10 @@ public class RemoveMimeHeaderTest {
@Test
public void serviceShouldNotRemoveHeaderWhenEmptyConfig() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "")
+ .build();
mailet.init(mailetConfig);
MimeMessage mimeMessage = MailUtil.createMimeMessage();
@@ -135,15 +141,19 @@ public class RemoveMimeHeaderTest {
@Test
public void initShouldThrowWhenInvalidConfig() throws MessagingException {
expectedException.expect(MessagingException.class);
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
mailet.init(mailetConfig);
}
@SuppressWarnings("unchecked")
@Test
public void serviceShouldNotThrowWhenExceptionOccured() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "")
+ .build();
mailet.init(mailetConfig);
Mail mail = mock(Mail.class);
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/ReplaceContentTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ReplaceContentTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ReplaceContentTest.java
index c13ec0a..42d7cce 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ReplaceContentTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ReplaceContentTest.java
@@ -29,7 +29,6 @@ import javax.mail.internet.MimeMessage;
import org.apache.mailet.Mail;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.junit.Before;
import org.junit.Rule;
@@ -44,12 +43,10 @@ public class ReplaceContentTest {
public ExpectedException expectedException = ExpectedException.none();
private ReplaceContent mailet;
- private FakeMailetConfig mailetConfig;
@Before
public void setup() {
mailet = new ReplaceContent();
- mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
}
@Test
@@ -59,7 +56,10 @@ public class ReplaceContentTest {
@Test
public void serviceShouldReplaceSubjectWhenMatching() throws Exception {
- mailetConfig.setProperty("subjectPattern", "/test/TEST/i/,/o/a//,/s/s/i/");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPattern", "/test/TEST/i/,/o/a//,/s/s/i/")
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -75,13 +75,16 @@ public class ReplaceContentTest {
@Test
public void serviceShouldReplaceBodyWhenMatching() throws Exception {
- mailetConfig.setProperty("bodyPattern",
- "/test/TEST/i/," +
- "/o/a/r/," +
- "/S/s/r/,/\\u00E8/e'//," +
- "/test([^\\/]*?)bla/X$1Y/im/," +
- "/X(.\\n)Y/P$1Q//," +
- "/\\/\\/,//");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("bodyPattern",
+ "/test/TEST/i/," +
+ "/o/a/r/," +
+ "/S/s/r/,/\\u00E8/e'//," +
+ "/test([^\\/]*?)bla/X$1Y/im/," +
+ "/X(.\\n)Y/P$1Q//," +
+ "/\\/\\/,//")
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -99,7 +102,10 @@ public class ReplaceContentTest {
@Test
public void serviceShouldNotLoopWhenCaseInsensitiveAndRepeat() throws Exception {
- mailetConfig.setProperty("bodyPattern", "/a/a/ir/");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("bodyPattern", "/a/a/ir/")
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -115,7 +121,10 @@ public class ReplaceContentTest {
@Test
public void serviceShouldReplaceSubjectWhenConfigurationFromFile() throws Exception {
- mailetConfig.setProperty("subjectPatternFile", "#/org/apache/james/mailet/standard/mailets/replaceSubject.patterns");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPatternFile", "#/org/apache/james/mailet/standard/mailets/replaceSubject.patterns")
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -131,9 +140,12 @@ public class ReplaceContentTest {
@Test
public void serviceShouldRemoveOrAddTextInBody() throws Exception {
- mailetConfig.setProperty("bodyPattern", "/--original message--/<quote>/i/,"
- + "/<quote>(.*)(\\r\\n)([^>]+)/<quote>$1$2>$3/imrs/,"
- + "/<quote>\\r\\n//im/");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("bodyPattern", "/--original message--/<quote>/i/,"
+ + "/<quote>(.*)(\\r\\n)([^>]+)/<quote>$1$2>$3/imrs/,"
+ + "/<quote>\\r\\n//im/")
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -154,7 +166,10 @@ public class ReplaceContentTest {
@Test
public void serviceShouldReplaceBodyWhenMatchingASCIICharacter() throws Exception {
- mailetConfig.setProperty("bodyPattern", "/\\u2026/.../r/");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("bodyPattern", "/\\u2026/.../r/")
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -176,10 +191,13 @@ public class ReplaceContentTest {
+ "\r\n"
+ "=93test=94 with th=92 apex";
- mailetConfig.setProperty("bodyPattern", "/[\\u2018\\u2019\\u201A]/'//,"
- + "/[\\u201C\\u201D\\u201E]/\"//," + "/[\\x91\\x92\\x82]/'//,"
- + "/[\\x93\\x94\\x84]/\"/r/," + "/\\x85/...//," + "/\\x8B/<//,"
- + "/\\x9B/>//," + "/\\x96/-//," + "/\\x97/--//,");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("bodyPattern", "/[\\u2018\\u2019\\u201A]/'//,"
+ + "/[\\u201C\\u201D\\u201E]/\"//," + "/[\\x91\\x92\\x82]/'//,"
+ + "/[\\x93\\x94\\x84]/\"/r/," + "/\\x85/...//," + "/\\x8B/<//,"
+ + "/\\x9B/>//," + "/\\x96/-//," + "/\\x97/--//,")
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()),
@@ -195,8 +213,11 @@ public class ReplaceContentTest {
@Test
public void serviceShouldSetContenTypeWhenInitialized() throws Exception {
- mailetConfig.setProperty("subjectPattern", "/test/TEST/i/,/o/a//,/s/s/i/");
- mailetConfig.setProperty("charset", Charsets.UTF_8.name());
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("subjectPattern", "/test/TEST/i/,/o/a//,/s/s/i/")
+ .setProperty("charset", Charsets.UTF_8.name())
+ .build();
mailet.init(mailetConfig);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java
index 83804fa..f7423da 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java
@@ -30,7 +30,6 @@ import javax.mail.internet.MimeMessage;
import org.apache.mailet.Mail;
import org.apache.mailet.Mailet;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -51,9 +50,11 @@ public class SetMailAttributeTest {
@Test
public void shouldAddConfiguredAttributes() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("org.apache.james.junit1", "true");
- mailetConfig.setProperty("org.apache.james.junit2", "happy");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("org.apache.james.junit1", "true")
+ .setProperty("org.apache.james.junit2", "happy")
+ .build();
mailet.init(mailetConfig);
@@ -67,7 +68,9 @@ public class SetMailAttributeTest {
@Test
public void shouldAddNothingWhenNoConfiguredAttribute() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
mailet.init(mailetConfig);
@@ -80,8 +83,10 @@ public class SetMailAttributeTest {
@Test
public void shouldOverwriteAttributeWhenAttributeAlreadyPresent() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("org.apache.james.junit1", "bar");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("org.apache.james.junit1", "bar")
+ .build();
mailet.init(mailetConfig);
@@ -92,18 +97,4 @@ public class SetMailAttributeTest {
assertThat(mail.getAttribute("org.apache.james.junit1")).isEqualTo("bar");
}
-
- @Test
- public void shouldThrowWhenNullProperty() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- expectedException.expect(NullPointerException.class);
- mailetConfig.setProperty(null, "bar");
- }
-
- @Test
- public void shouldThrowWhenNullValue() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- expectedException.expect(NullPointerException.class);
- mailetConfig.setProperty("org.apache.james.junit1", null);
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
index ba32971..a08ee21 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
@@ -20,17 +20,15 @@
package org.apache.james.transport.mailets;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.assertj.core.api.Assertions.assertThat;
-
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.apache.mailet.Mail;
import org.apache.mailet.Mailet;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -51,9 +49,11 @@ public class SetMimeHeaderTest {
@Test
public void shouldAddHeaderToMime() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "header-name");
- mailetConfig.setProperty("value", "test-value");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "header-name")
+ .setProperty("value", "test-value")
+ .build();
mailet.init(mailetConfig);
MimeMessage mimeMessage = MailUtil.createMimeMessage();
@@ -66,9 +66,11 @@ public class SetMimeHeaderTest {
@Test
public void shouldAddHeaderWhenAlreadyPresent() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "header-name");
- mailetConfig.setProperty("value", "test-value");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "header-name")
+ .setProperty("value", "test-value")
+ .build();
mailet.init(mailetConfig);
MimeMessage mimeMessage = MailUtil.createMimeMessage();
@@ -82,9 +84,11 @@ public class SetMimeHeaderTest {
@Test
public void shouldNotThrowOnMessagingException() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "header-name");
- mailetConfig.setProperty("value", "test-value");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "header-name")
+ .setProperty("value", "test-value")
+ .build();
mailet.init(mailetConfig);
Mail mail = mock(Mail.class);
@@ -94,41 +98,51 @@ public class SetMimeHeaderTest {
@Test
public void shouldThrowWhenNoConfiguration() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
@Test
public void shouldThrowWhenNoValue() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "correct");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "correct")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
@Test
public void shouldThrowWhenNoHeader() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("value", "correct");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("value", "correct")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
@Test
public void shouldThrowWhenEmptyValue() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("value", "");
- mailetConfig.setProperty("name", "correct");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("value", "")
+ .setProperty("name", "correct")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
@Test
public void shouldThrowWhenEmptyHeader() throws MessagingException {
- FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
- mailetConfig.setProperty("name", "");
- mailetConfig.setProperty("value", "correct");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("name", "")
+ .setProperty("value", "correct")
+ .build();
expectedException.expect(MessagingException.class);
mailet.init(mailetConfig);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
index f103e41..a9bd6e8 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
@@ -38,7 +38,6 @@ import org.apache.commons.io.FileUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.Mailet;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.junit.Assert;
import org.junit.Test;
@@ -119,11 +118,12 @@ public class StripAttachmentTest {
public void testSimpleAttachment2() throws MessagingException, IOException {
Mailet mailet = new StripAttachment();
- FakeMailetConfig mci = new FakeMailetConfig("Test",
- FakeMailContext.defaultContext());
- mci.setProperty("directory", "./");
- mci.setProperty("remove", "all");
- mci.setProperty("notpattern", "^(winmail\\.dat$)");
+ FakeMailetConfig mci = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("directory", "./")
+ .setProperty("remove", "all")
+ .setProperty("notpattern", "^(winmail\\.dat$)")
+ .build();
mailet.init(mci);
MimeMessage message = new MimeMessage(Session
@@ -252,21 +252,25 @@ public class StripAttachmentTest {
public void testToAndFromAttributes() throws MessagingException,
IOException {
Mailet strip = new StripAttachment();
- FakeMailetConfig mci = new FakeMailetConfig("Test",
- FakeMailContext.defaultContext());
- mci.setProperty("attribute", "my.attribute");
- mci.setProperty("remove", "all");
- mci.setProperty("notpattern", ".*\\.tmp.*");
+ FakeMailetConfig mci = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("attribute", "my.attribute")
+ .setProperty("remove", "all")
+ .setProperty("notpattern", ".*\\.tmp.*")
+ .build();
strip.init(mci);
Mailet recover = new RecoverAttachment();
- FakeMailetConfig mci2 = new FakeMailetConfig("Test",
- FakeMailContext.defaultContext());
- mci2.setProperty("attribute", "my.attribute");
+ FakeMailetConfig mci2 = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("attribute", "my.attribute")
+ .build();
recover.init(mci2);
Mailet onlyText = new OnlyText();
- onlyText.init(new FakeMailetConfig("Test", FakeMailContext.defaultContext()));
+ onlyText.init(FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build());
MimeMessage message = new MimeMessage(Session
.getDefaultInstance(new Properties()));
@@ -343,26 +347,27 @@ public class StripAttachmentTest {
private Mailet initMailet() throws MessagingException {
Mailet mailet = new StripAttachment();
- FakeMailetConfig mci = new FakeMailetConfig("Test",
- FakeMailContext.defaultContext());
- mci.setProperty("directory", "./");
- mci.setProperty("remove", "all");
- mci.setProperty("pattern", ".*\\.tmp");
- mci.setProperty("decodeFilename", "true");
- mci.setProperty("replaceFilenamePattern",
- "/[\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5]/A//,"
- + "/[\u00C6]/AE//,"
- + "/[\u00C8\u00C9\u00CA\u00CB]/E//,"
- + "/[\u00CC\u00CD\u00CE\u00CF]/I//,"
- + "/[\u00D2\u00D3\u00D4\u00D5\u00D6]/O//,"
- + "/[\u00D7]/x//," + "/[\u00D9\u00DA\u00DB\u00DC]/U//,"
- + "/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]/a//,"
- + "/[\u00E6]/ae//,"
- + "/[\u00E8\u00E9\u00EA\u00EB]/e/r/,"
- + "/[\u00EC\u00ED\u00EE\u00EF]/i//,"
- + "/[\u00F2\u00F3\u00F4\u00F5\u00F6]/o//,"
- + "/[\u00F9\u00FA\u00FB\u00FC]/u//,"
- + "/[^A-Za-z0-9._-]+/_/r/");
+ FakeMailetConfig mci = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("directory", "./")
+ .setProperty("remove", "all")
+ .setProperty("pattern", ".*\\.tmp")
+ .setProperty("decodeFilename", "true")
+ .setProperty("replaceFilenamePattern",
+ "/[\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5]/A//,"
+ + "/[\u00C6]/AE//,"
+ + "/[\u00C8\u00C9\u00CA\u00CB]/E//,"
+ + "/[\u00CC\u00CD\u00CE\u00CF]/I//,"
+ + "/[\u00D2\u00D3\u00D4\u00D5\u00D6]/O//,"
+ + "/[\u00D7]/x//," + "/[\u00D9\u00DA\u00DB\u00DC]/U//,"
+ + "/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]/a//,"
+ + "/[\u00E6]/ae//,"
+ + "/[\u00E8\u00E9\u00EA\u00EB]/e/r/,"
+ + "/[\u00EC\u00ED\u00EE\u00EF]/i//,"
+ + "/[\u00F2\u00F3\u00F4\u00F5\u00F6]/o//,"
+ + "/[\u00F9\u00FA\u00FB\u00FC]/u//,"
+ + "/[^A-Za-z0-9._-]+/_/r/")
+ .build();
mailet.init(mci);
return mailet;
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java
index e380c13..3db12fd 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java
@@ -45,14 +45,14 @@ public class ToProcessorTest {
public ExpectedException expectedException = ExpectedException.none();
private Mailet mailet;
- private FakeMailetConfig mailetConfig;
private Logger logger;
+ private FakeMailContext mailContext;
@Before
public void setup() {
mailet = new ToProcessor();
logger = mock(Logger.class);
- mailetConfig = new FakeMailetConfig("Test", FakeMailContext.builder().logger(logger).build());
+ mailContext = FakeMailContext.builder().logger(logger).build();
}
@Test
@@ -62,7 +62,11 @@ public class ToProcessorTest {
@Test
public void initShouldThrowWhenProcessorIsNotGiven() throws MessagingException {
- mailetConfig.setProperty("notice", "error in message");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .mailetContext(mailContext)
+ .setProperty("notice", "error in message")
+ .build();
expectedException.expect(MailetException.class);
mailet.init(mailetConfig);
@@ -71,7 +75,11 @@ public class ToProcessorTest {
@Test
public void serviceShouldSetTheStateOfTheMail() throws MessagingException {
String processor = "error";
- mailetConfig.setProperty("processor", processor);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .mailetContext(mailContext)
+ .setProperty("processor", processor)
+ .build();
mailet.init(mailetConfig);
Mail mail = FakeMail.builder()
@@ -85,9 +93,13 @@ public class ToProcessorTest {
@Test
public void serviceShouldSetTheErrorMessageOfTheMailWhenNotAlreadySet() throws MessagingException {
String processor = "error";
- mailetConfig.setProperty("processor", processor);
String notice = "error in message";
- mailetConfig.setProperty("notice", notice);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .mailetContext(mailContext)
+ .setProperty("processor", processor)
+ .setProperty("notice", notice)
+ .build();
mailet.init(mailetConfig);
Mail mail = FakeMail.builder()
@@ -101,9 +113,13 @@ public class ToProcessorTest {
@Test
public void serviceShouldAppendTheErrorMessageOfTheMailWhenSomeErrorMessageOnMail() throws MessagingException {
String processor = "error";
- mailetConfig.setProperty("processor", processor);
String notice = "error in message";
- mailetConfig.setProperty("notice", notice);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .mailetContext(mailContext)
+ .setProperty("processor", processor)
+ .setProperty("notice", notice)
+ .build();
mailet.init(mailetConfig);
Mail mail = FakeMail.builder()
@@ -118,9 +134,13 @@ public class ToProcessorTest {
@Test
public void serviceShouldLogWhenDebug() throws MessagingException {
- mailetConfig.setProperty("processor", "error");
- mailetConfig.setProperty("notice", "error in message");
- mailetConfig.setProperty("debug", "true");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .mailetContext(mailContext)
+ .setProperty("processor", "error")
+ .setProperty("notice", "error in message")
+ .setProperty("debug", "true")
+ .build();
mailet.init(mailetConfig);
Mail mail = FakeMail.builder()
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
index efcfd5c..0e1af99 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
@@ -97,7 +97,11 @@ public class MailetPreconditionTest {
Properties properties = new Properties();
properties.setProperty("name", WRONG_NAME);
RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader();
- removeMimeHeader.init(new FakeMailetConfig(WRONG_NAME, MAILET_CONTEXT, properties));
+ removeMimeHeader.init(FakeMailetConfig.builder()
+ .mailetName(WRONG_NAME)
+ .mailetContext(MAILET_CONTEXT)
+ .setProperty("name", WRONG_NAME)
+ .build());
List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), removeMimeHeader));
new JMAPModule.VacationMailetCheck().check(pairs);
@@ -105,10 +109,12 @@ public class MailetPreconditionTest {
@Test(expected = ConfigurationException.class)
public void bccMailetCheckShouldNotThrowOnValidPair() throws Exception {
- Properties properties = new Properties();
- properties.setProperty("name", BCC);
RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader();
- removeMimeHeader.init(new FakeMailetConfig(BCC, MAILET_CONTEXT, properties));
+ removeMimeHeader.init(FakeMailetConfig.builder()
+ .mailetName(BCC)
+ .mailetContext(MAILET_CONTEXT)
+ .setProperty("name", BCC)
+ .build());
List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), removeMimeHeader));
new JMAPModule.VacationMailetCheck().check(pairs);
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
index 8484a89..c07d976 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
@@ -54,7 +54,10 @@ public class BounceTest {
fakeMailContext = FakeMailContext.defaultContext();
when(dnsService.getLocalHost()).thenThrow(new UnknownHostException());
- bounce.init(new FakeMailetConfig(MAILET_NAME, fakeMailContext));
+ bounce.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .mailetContext(fakeMailContext)
+ .build());
senderMailAddress = new MailAddress("sender@domain.com");
recipientMailAddress = new MailAddress("recipient@domain.com");
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
index 375964b..b1782f8 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
@@ -57,7 +57,12 @@ public class RecipientRewriteTableTest {
message = new MimeMessage(Session.getDefaultInstance(new Properties()));
mailetContext = FakeMailContext.defaultContext();
- mailetConfig = new FakeMailetConfig("Test", mailetContext);
+
+ mailetConfig = FakeMailetConfig.builder()
+ .mailetName("vut")
+ .mailetContext(mailetContext)
+ .build();
+
mail = FakeMail.builder().build();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
index 32f1c67..cd14097 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
@@ -31,7 +31,6 @@ import org.apache.james.mailrepository.api.MailRepositoryStore;
import org.apache.mailet.Mail;
import org.apache.mailet.MailetConfig;
import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
@@ -43,7 +42,6 @@ public class ToRepositoryTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
private ToRepository mailet;
- private FakeMailetConfig mailetConfig;
private MailRepositoryStore mailRepositoryStore;
private FakeMail message;
@@ -53,7 +51,6 @@ public class ToRepositoryTest {
mailRepositoryStore = mock(MailRepositoryStore.class);
mailet = new ToRepository();
mailet.setStore(mailRepositoryStore);
- mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
message = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
}
@@ -79,6 +76,9 @@ public class ToRepositoryTest {
when(mailRepositoryStore.select(any(String.class))).thenThrow(new RuntimeException());
expectedException.expect(MessagingException.class);
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
mailet.init(mailetConfig);
}
@@ -86,6 +86,10 @@ public class ToRepositoryTest {
public void serviceShouldStoreMailIntoRepository() throws Exception {
MailRepository mailRepository = mock(MailRepository.class);
when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
+
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
mailet.init(mailetConfig);
mailet.service(message);
@@ -97,6 +101,10 @@ public class ToRepositoryTest {
public void serviceShouldGhostMailIfPassThroughNotSet() throws Exception {
MailRepository mailRepository = mock(MailRepository.class);
when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
+
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .build();
mailet.init(mailetConfig);
mailet.service(message);
@@ -106,7 +114,10 @@ public class ToRepositoryTest {
@Test
public void serviceShouldGhostMailIfPassThroughSetToFalse() throws Exception {
- mailetConfig.setProperty("passThrough", "false");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("passThrough", "false")
+ .build();
MailRepository mailRepository = mock(MailRepository.class);
when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
mailet.init(mailetConfig);
@@ -118,7 +129,10 @@ public class ToRepositoryTest {
@Test
public void serviceShouldNotGhostMailIfPassThroughSetToTrue() throws Exception {
- mailetConfig.setProperty("passThrough", "true");
+ FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .setProperty("passThrough", "true")
+ .build();
MailRepository mailRepository = mock(MailRepository.class);
when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
mailet.init(mailetConfig);
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
index 05e9653..61d842b 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
@@ -89,7 +89,10 @@ public class LocalDeliveryTest {
}
when(session.getUser()).thenReturn(user);
- config = new FakeMailetConfig("Local delivery", FakeMailContext.builder().logger(mock(Logger.class)).build());
+ config = FakeMailetConfig.builder()
+ .mailetName("Local delivery")
+ .mailetContext(FakeMailContext.builder().logger(mock(Logger.class)).build())
+ .build();
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
index cf299d8..6ae5aa2 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
@@ -67,19 +67,18 @@ public class ToRecipientFolderTest {
public static final MailboxPath INBOX = new MailboxPath("#private", USER, "INBOX");
public static final MailboxPath JUNK = new MailboxPath("#private", USER_LOCAL_PART, "Junk");
public static final MailboxPath JUNK_VIRTUAL_HOSTING = new MailboxPath("#private", USER, "Junk");
+ public static final String MAILET_NAME = "RecipientFolderTest";
private MessageManager messageManager;
private UsersRepository usersRepository;
private MailboxManager mailboxManager;
private ToRecipientFolder testee;
private MailboxSession.User user;
-
-
- private FakeMailetConfig mailetConfig;
+ private FakeMailContext mailetContext;
@Before
public void setUp() throws Exception {
- mailetConfig = new FakeMailetConfig("RecipientFolderTest", FakeMailContext.builder().logger(mock(Logger.class)).build());
+ mailetContext = FakeMailContext.builder().logger(mock(Logger.class)).build();
messageManager = mock(MessageManager.class);
usersRepository = mock(UsersRepository.class);
mailboxManager = mock(MailboxManager.class);
@@ -100,16 +99,22 @@ public class ToRecipientFolderTest {
@Test
public void initParameterTesting() throws Exception {
- mailetConfig.setProperty(ToRecipientFolder.FOLDER_PARAMETER, "Junk");
- testee.init(mailetConfig);
+ testee.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .mailetContext(mailetContext)
+ .setProperty(ToRecipientFolder.FOLDER_PARAMETER, "Junk")
+ .build());
Assert.assertEquals("Junk", testee.getInitParameter(ToRecipientFolder.FOLDER_PARAMETER));
}
@Test
public void consumeOptionShouldGhostTheMail() throws Exception {
- mailetConfig.setProperty(ToRecipientFolder.CONSUME_PARAMETER, "true");
- testee.init(mailetConfig);
+ testee.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .mailetContext(mailetContext)
+ .setProperty(ToRecipientFolder.CONSUME_PARAMETER, "true")
+ .build());
Mail mail = createMail();
testee.service(mail);
@@ -119,7 +124,10 @@ public class ToRecipientFolderTest {
@Test
public void consumeOptionShouldNotGhostTheMailByDefault() throws Exception {
- testee.init(mailetConfig);
+ testee.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .mailetContext(mailetContext)
+ .build());
Mail mail = createMail();
testee.service(mail);
@@ -134,8 +142,11 @@ public class ToRecipientFolderTest {
when(mailboxManager.getMailbox(eq(JUNK_VIRTUAL_HOSTING), any(MailboxSession.class))).thenReturn(messageManager);
when(user.getUserName()).thenReturn(USER);
- mailetConfig.setProperty(ToRecipientFolder.FOLDER_PARAMETER, "Junk");
- testee.init(mailetConfig);
+ testee.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .mailetContext(mailetContext)
+ .setProperty(ToRecipientFolder.FOLDER_PARAMETER, "Junk")
+ .build());
testee.service(createMail());
verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
@@ -148,7 +159,10 @@ public class ToRecipientFolderTest {
when(mailboxManager.getMailbox(eq(INBOX), any(MailboxSession.class))).thenReturn(messageManager);
when(user.getUserName()).thenReturn(USER);
- testee.init(mailetConfig);
+ testee.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .mailetContext(mailetContext)
+ .build());
testee.service(createMail());
verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
@@ -162,8 +176,12 @@ public class ToRecipientFolderTest {
when(mailboxManager.getMailbox(eq(JUNK), any(MailboxSession.class))).thenReturn(messageManager);
when(user.getUserName()).thenReturn(USER_LOCAL_PART);
- mailetConfig.setProperty(ToRecipientFolder.FOLDER_PARAMETER, "Junk");
- testee.init(mailetConfig);
+ testee.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .mailetContext(mailetContext)
+ .setProperty(ToRecipientFolder.FOLDER_PARAMETER, "Junk")
+ .setProperty(ToRecipientFolder.CONSUME_PARAMETER, "true")
+ .build());
testee.service(createMail());
verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailetTestCase.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailetTestCase.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailetTestCase.java
index bd05700..bdf6dd5 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailetTestCase.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailetTestCase.java
@@ -467,8 +467,11 @@ public class ManageSieveMailetTestCase {
mailet.setSieveRepository(sieveRepository);
mailet.setUsersRepository(usersRepository);
fakeMailContext = FakeMailContext.defaultContext();
- FakeMailetConfig config = new FakeMailetConfig("ManageSieve mailet", fakeMailContext);
- config.setProperty("helpURL", "file:./src/test/resources/help.txt");
+ FakeMailetConfig config = FakeMailetConfig.builder()
+ .mailetName("ManageSieve mailet")
+ .mailetContext(fakeMailContext)
+ .setProperty("helpURL", "file:./src/test/resources/help.txt")
+ .build();
mailet.init(config);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a9c4382/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java
index 1ba6995..1568dd0 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java
@@ -94,7 +94,10 @@ public class VacationMailetTest {
notificationRegistry = mock(NotificationRegistry.class);
testee = new VacationMailet(vacationRepository, zonedDateTimeProvider, automaticallySentMailDetector, notificationRegistry, mimeMessageBodyGenerator);
mailetContext = mock(MailetContext.class);
- testee.init(new FakeMailetConfig("vacation", mailetContext));
+ testee.init(FakeMailetConfig.builder()
+ .mailetName("vacation")
+ .mailetContext(mailetContext)
+ .build());
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[07/16] james-project git commit: JAMES-1868 Enable JMX monitoring
for metrics via Guice
Posted by ro...@apache.org.
JAMES-1868 Enable JMX monitoring for metrics via Guice
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ff1f8e99
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ff1f8e99
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ff1f8e99
Branch: refs/heads/master
Commit: ff1f8e9969d9323dc07b52bdb9cf483af2bf7605
Parents: 61a319f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Nov 24 15:51:48 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:32:17 2016 +0700
----------------------------------------------------------------------
.../modules/server/DropWizardMetricsModule.java | 39 ++++++++++++++++++++
.../metrics/metrics-dropwizard/pom.xml | 4 ++
.../dropwizard/DropWizardMetricFactory.java | 22 +++++++++--
3 files changed, 62 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ff1f8e99/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
index 31f66fa..8e77370 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
@@ -19,11 +19,22 @@
package org.apache.james.modules.server;
+import java.util.List;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.metrics.dropwizard.DropWizardMetricFactory;
+import org.apache.james.utils.ConfigurationPerformer;
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
import com.google.inject.Scopes;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
public class DropWizardMetricsModule extends AbstractModule {
@@ -31,6 +42,34 @@ public class DropWizardMetricsModule extends AbstractModule {
protected void configure() {
bind(DropWizardMetricFactory.class).in(Scopes.SINGLETON);
bind(MetricFactory.class).to(DropWizardMetricFactory.class);
+
+ Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(DropWizardConfigurationPerformer.class);
+ }
+
+ @Singleton
+ public static class DropWizardConfigurationPerformer implements ConfigurationPerformer {
+ public static final HierarchicalConfiguration NO_CONFIGURATION = null;
+
+ private final DropWizardMetricFactory metricFactory;
+
+ @Inject
+ public DropWizardConfigurationPerformer(DropWizardMetricFactory metricFactory) {
+ this.metricFactory = metricFactory;
+ }
+
+ @Override
+ public void initModule() {
+ try {
+ metricFactory.configure(NO_CONFIGURATION);
+ } catch (ConfigurationException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ public List<Class<? extends Configurable>> forClasses() {
+ return ImmutableList.of(DropWizardMetricFactory.class);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ff1f8e99/server/container/metrics/metrics-dropwizard/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/pom.xml b/server/container/metrics/metrics-dropwizard/pom.xml
index 083224e..3d40daf 100644
--- a/server/container/metrics/metrics-dropwizard/pom.xml
+++ b/server/container/metrics/metrics-dropwizard/pom.xml
@@ -39,6 +39,10 @@
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
+ <artifactId>james-server-lifecycle-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
<artifactId>james-server-metrics-api</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/ff1f8e99/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
index 2e89060..786045f 100644
--- a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
+++ b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
@@ -19,20 +19,26 @@
package org.apache.james.metrics.dropwizard;
-import javax.inject.Inject;
+import javax.annotation.PreDestroy;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.metrics.api.Metric;
import org.apache.james.metrics.api.MetricFactory;
+import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
-public class DropWizardMetricFactory implements MetricFactory {
+public class DropWizardMetricFactory implements MetricFactory, Configurable {
private final MetricRegistry metricRegistry;
+ private final JmxReporter jmxReporter;
- @Inject
public DropWizardMetricFactory() {
this.metricRegistry = new MetricRegistry();
+ this.jmxReporter = JmxReporter.forRegistry(metricRegistry)
+ .build();
}
@Override
@@ -40,4 +46,14 @@ public class DropWizardMetricFactory implements MetricFactory {
return new DropWizardMetric(metricRegistry.counter(name));
}
+ @Override
+ public void configure(HierarchicalConfiguration config) throws ConfigurationException {
+ jmxReporter.start();
+ }
+
+ @PreDestroy
+ public void stop() {
+ jmxReporter.stop();
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[11/16] james-project git commit: JAMES-1868 Adding a metrics to SMTP
and LMTP
Posted by ro...@apache.org.
JAMES-1868 Adding a metrics to SMTP and LMTP
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/78f7dbb3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/78f7dbb3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/78f7dbb3
Branch: refs/heads/master
Commit: 78f7dbb38b1d753f0b211b69e2c651bb2de8aaf7
Parents: 9d40cb2
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Nov 29 09:31:05 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:32:21 2016 +0700
----------------------------------------------------------------------
.../james/lmtpserver/netty/LMTPMetricsImpl.java | 45 +++++++++++++++++++
.../james/lmtpserver/netty/LMTPServer.java | 6 ++-
.../lmtpserver/netty/LMTPServerFactory.java | 17 ++++----
.../james/lmtpserver/netty/OioLMTPServer.java | 5 +++
.../lmtpserver/netty/OioLMTPServerFactory.java | 10 ++++-
.../META-INF/spring/lmtpserver-context.xml | 5 ++-
server/protocols/protocols-smtp/pom.xml | 9 ++++
.../james/smtpserver/netty/OioSMTPServer.java | 4 ++
.../smtpserver/netty/OioSMTPServerFactory.java | 11 ++++-
.../netty/SMTPChannelUpstreamHandler.java | 27 +++++++++++-
.../james/smtpserver/netty/SMTPServer.java | 7 ++-
.../smtpserver/netty/SMTPServerFactory.java | 25 +++++------
.../james/smtpserver/netty/SmtpMetrics.java | 28 ++++++++++++
.../james/smtpserver/netty/SmtpMetricsImpl.java | 46 ++++++++++++++++++++
.../META-INF/spring/smtpserver-context.xml | 7 +--
.../james/smtpserver/OioSMTPServerTest.java | 5 ++-
.../apache/james/smtpserver/SMTPServerTest.java | 14 ++++--
17 files changed, 230 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPMetricsImpl.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPMetricsImpl.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPMetricsImpl.java
new file mode 100644
index 0000000..92738cf
--- /dev/null
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPMetricsImpl.java
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.lmtpserver.netty;
+
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.smtpserver.netty.SmtpMetrics;
+
+public class LMTPMetricsImpl implements SmtpMetrics {
+ private static final String LMTP_CONNECTIONS = "lmtpConnections";
+ private static final String LMTP_COMMANDS = "lmtpCommands";
+
+ private final MetricFactory metricFactory;
+
+ public LMTPMetricsImpl(MetricFactory metricFactory) {
+ this.metricFactory = metricFactory;
+ }
+
+ @Override
+ public Metric getConnectionMetric() {
+ return metricFactory.generate(LMTP_CONNECTIONS);
+ }
+
+ @Override
+ public Metric getCommandsMetric() {
+ return metricFactory.generate(LMTP_COMMANDS);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServer.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServer.java
index 2a8367c..860a05f 100644
--- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServer.java
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServer.java
@@ -39,8 +39,12 @@ public class LMTPServer extends AbstractProtocolAsyncServer implements LMTPServe
*/
private long maxMessageSize = 0;
private final LMTPConfigurationImpl lmtpConfig = new LMTPConfigurationImpl();
+ private final LMTPMetricsImpl lmtpMetrics;
private String lmtpGreeting;
+ public LMTPServer(LMTPMetricsImpl lmtpMetrics) {
+ this.lmtpMetrics = lmtpMetrics;
+ }
/**
* @see
@@ -138,7 +142,7 @@ public class LMTPServer extends AbstractProtocolAsyncServer implements LMTPServe
@Override
protected ChannelUpstreamHandler createCoreHandler() {
SMTPProtocol protocol = new SMTPProtocol(getProtocolHandlerChain(), lmtpConfig, new ProtocolLoggerAdapter(getLogger()));
- return new SMTPChannelUpstreamHandler(protocol, getLogger());
+ return new SMTPChannelUpstreamHandler(protocol, getLogger(), lmtpMetrics);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
index 5306364..88160d0 100644
--- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
@@ -25,6 +25,7 @@ import javax.inject.Inject;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader;
import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
import org.apache.james.protocols.lib.netty.AbstractServerFactory;
@@ -32,21 +33,19 @@ import org.slf4j.Logger;
public class LMTPServerFactory extends AbstractServerFactory{
- private ProtocolHandlerLoader loader;
- private FileSystem fileSystem;
+ private final ProtocolHandlerLoader loader;
+ private final FileSystem fileSystem;
+ protected final LMTPMetricsImpl lmtpMetrics;
@Inject
- public void setProtocolHandlerLoader(ProtocolHandlerLoader loader) {
+ public LMTPServerFactory(ProtocolHandlerLoader loader, FileSystem fileSystem, MetricFactory metricFactory) {
this.loader = loader;
- }
-
- @Inject
- public final void setFileSystem(FileSystem filesystem) {
- this.fileSystem = filesystem;
+ this.fileSystem = fileSystem;
+ this.lmtpMetrics = new LMTPMetricsImpl(metricFactory);
}
protected LMTPServer createServer() {
- return new LMTPServer();
+ return new LMTPServer(lmtpMetrics);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java
index 73e2a17..0653b24 100644
--- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java
@@ -28,6 +28,11 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
*/
public class OioLMTPServer extends LMTPServer {
+
+ public OioLMTPServer(LMTPMetricsImpl lmtpMetrics) {
+ super(lmtpMetrics);
+ }
+
@Override
protected ServerSocketChannelFactory createSocketChannelFactory() {
return new OioServerSocketChannelFactory(createBossExecutor(), createWorkerExecutor());
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
index a69fb23..53f8918 100644
--- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
@@ -18,11 +18,19 @@
****************************************************************/
package org.apache.james.lmtpserver.netty;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader;
+
public class OioLMTPServerFactory extends LMTPServerFactory{
+ public OioLMTPServerFactory(ProtocolHandlerLoader loader, FileSystem fileSystem, MetricFactory metricFactory) {
+ super(loader, fileSystem, metricFactory);
+ }
+
@Override
protected LMTPServer createServer() {
- return new OioLMTPServer();
+ return new OioLMTPServer(lmtpMetrics);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-lmtp/src/main/resources/META-INF/spring/lmtpserver-context.xml
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/resources/META-INF/spring/lmtpserver-context.xml b/server/protocols/protocols-lmtp/src/main/resources/META-INF/spring/lmtpserver-context.xml
index 8d4a98c..85a7943 100644
--- a/server/protocols/protocols-lmtp/src/main/resources/META-INF/spring/lmtpserver-context.xml
+++ b/server/protocols/protocols-lmtp/src/main/resources/META-INF/spring/lmtpserver-context.xml
@@ -18,8 +18,9 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="lmtpserver" class="org.apache.james.lmtpserver.netty.LMTPServerFactory">
- <property name="protocolHandlerLoader" ref="protocolhandlerloader"/>
- <property name="fileSystem" ref="filesystem"/>
+ <constructor-arg index="0" ref="protocolhandlerloader"/>
+ <constructor-arg index="1" ref="filesystem"/>
+ <constructor-arg index="2" ref="metricFactory"/>
</bean>
</beans>
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/pom.xml b/server/protocols/protocols-smtp/pom.xml
index e437da6..a4e4a3c 100644
--- a/server/protocols/protocols-smtp/pom.xml
+++ b/server/protocols/protocols-smtp/pom.xml
@@ -67,6 +67,10 @@
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
<artifactId>james-server-protocols-library</artifactId>
</dependency>
<dependency>
@@ -196,6 +200,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java
index 7dacf59..03eb423 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java
@@ -28,6 +28,10 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
*/
public class OioSMTPServer extends SMTPServer {
+ public OioSMTPServer(SmtpMetricsImpl smtpMetrics) {
+ super(smtpMetrics);
+ }
+
@Override
protected ServerSocketChannelFactory createSocketChannelFactory() {
return new OioServerSocketChannelFactory(createBossExecutor(), createWorkerExecutor());
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
index 0158076..ea0e112 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
@@ -19,11 +19,20 @@
package org.apache.james.smtpserver.netty;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader;
+
public class OioSMTPServerFactory extends SMTPServerFactory{
+ public OioSMTPServerFactory(DNSService dns, ProtocolHandlerLoader loader, FileSystem fileSystem, MetricFactory metricFactory) {
+ super(dns, loader, fileSystem, metricFactory);
+ }
+
@Override
protected SMTPServer createServer() {
- return new OioSMTPServer();
+ return new OioSMTPServer(smtpMetrics);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
index 74b6b64..64ae9b6 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
@@ -27,7 +27,9 @@ import org.apache.james.protocols.smtp.SMTPSession;
import org.apache.james.smtpserver.SMTPConstants;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
/**
@@ -36,13 +38,34 @@ import org.slf4j.Logger;
@Sharable
public class SMTPChannelUpstreamHandler extends BasicChannelUpstreamHandler {
+ private final SmtpMetrics smtpMetrics;
- public SMTPChannelUpstreamHandler(Protocol protocol, Logger logger, Encryption encryption) {
+ public SMTPChannelUpstreamHandler(Protocol protocol, Logger logger, Encryption encryption, SmtpMetrics smtpMetrics) {
super(protocol, encryption);
+ this.smtpMetrics = smtpMetrics;
}
- public SMTPChannelUpstreamHandler(Protocol protocol, Logger logger) {
+ public SMTPChannelUpstreamHandler(Protocol protocol, Logger logger, SmtpMetrics smtpMetrics) {
super(protocol);
+ this.smtpMetrics = smtpMetrics;
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ super.channelConnected(ctx, e);
+ smtpMetrics.getConnectionMetric().increment();
+ }
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
+ super.messageReceived(ctx, e);
+ smtpMetrics.getCommandsMetric().increment();
+ }
+
+ @Override
+ public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ super.channelClosed(ctx, e);
+ smtpMetrics.getConnectionMetric().decrement();
}
/**
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
index 611fdbc..bacc31a 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
@@ -75,6 +75,7 @@ public class SMTPServer extends AbstractProtocolAsyncServer implements SMTPServe
* The configuration data to be passed to the handler
*/
private final SMTPConfiguration theConfigData = new SMTPHandlerConfigurationDataImpl();
+ private final SmtpMetrics smtpMetrics;
private boolean addressBracketsEnforcement = true;
@@ -85,6 +86,10 @@ public class SMTPServer extends AbstractProtocolAsyncServer implements SMTPServe
private SMTPChannelUpstreamHandler coreHandler;
+ public SMTPServer(SmtpMetrics smtpMetrics) {
+ this.smtpMetrics = smtpMetrics;
+ }
+
@Inject
public void setDnsService(DNSService dns) {
this.dns = dns;
@@ -110,7 +115,7 @@ public class SMTPServer extends AbstractProtocolAsyncServer implements SMTPServe
}
};
- coreHandler = new SMTPChannelUpstreamHandler(transport, getLogger(), getEncryption());
+ coreHandler = new SMTPChannelUpstreamHandler(transport, getLogger(), getEncryption(), smtpMetrics);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
index f7e7938..d85d81f 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
@@ -27,6 +27,7 @@ import javax.inject.Inject;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.dnsservice.api.DNSService;
import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader;
import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
import org.apache.james.protocols.lib.netty.AbstractServerFactory;
@@ -34,27 +35,21 @@ import org.slf4j.Logger;
public class SMTPServerFactory extends AbstractServerFactory {
- private DNSService dns;
- private ProtocolHandlerLoader loader;
- private FileSystem fileSystem;
+ protected final DNSService dns;
+ protected final ProtocolHandlerLoader loader;
+ protected final FileSystem fileSystem;
+ protected final SmtpMetricsImpl smtpMetrics;
- @Inject
- public void setDnsService(DNSService dns) {
- this.dns = dns;
- }
-
@Inject
- public void setProtocolHandlerLoader(ProtocolHandlerLoader loader) {
+ public SMTPServerFactory(DNSService dns, ProtocolHandlerLoader loader, FileSystem fileSystem, MetricFactory metricFactory) {
+ this.dns = dns;
this.loader = loader;
- }
-
- @Inject
- public final void setFileSystem(FileSystem filesystem) {
- this.fileSystem = filesystem;
+ this.fileSystem = fileSystem;
+ this.smtpMetrics = new SmtpMetricsImpl(metricFactory);
}
protected SMTPServer createServer() {
- return new SMTPServer();
+ return new SMTPServer(smtpMetrics);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetrics.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetrics.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetrics.java
new file mode 100644
index 0000000..b2b7f40
--- /dev/null
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetrics.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.smtpserver.netty;
+
+import org.apache.james.metrics.api.Metric;
+
+public interface SmtpMetrics {
+ Metric getConnectionMetric();
+
+ Metric getCommandsMetric();
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetricsImpl.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetricsImpl.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetricsImpl.java
new file mode 100644
index 0000000..a89f5d0
--- /dev/null
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SmtpMetricsImpl.java
@@ -0,0 +1,46 @@
+/****************************************************************
+ * 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.smtpserver.netty;
+
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+
+public class SmtpMetricsImpl implements SmtpMetrics {
+ private static final String SMTP_CONNECTIONS = "smtpConnections";
+ private static final String SMTP_COMMANDS = "smtpCommands";
+
+ private final Metric smtpConnectionMetric;
+ private final Metric smtpCommandsMetric;
+
+ public SmtpMetricsImpl(MetricFactory metricFactory) {
+ this.smtpConnectionMetric = metricFactory.generate(SMTP_CONNECTIONS);
+ this.smtpCommandsMetric = metricFactory.generate(SMTP_COMMANDS);
+ }
+
+ @Override
+ public Metric getConnectionMetric() {
+ return smtpConnectionMetric;
+ }
+
+ @Override
+ public Metric getCommandsMetric() {
+ return smtpCommandsMetric;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/main/resources/META-INF/spring/smtpserver-context.xml
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/resources/META-INF/spring/smtpserver-context.xml b/server/protocols/protocols-smtp/src/main/resources/META-INF/spring/smtpserver-context.xml
index 8933b7e..68fedd9 100644
--- a/server/protocols/protocols-smtp/src/main/resources/META-INF/spring/smtpserver-context.xml
+++ b/server/protocols/protocols-smtp/src/main/resources/META-INF/spring/smtpserver-context.xml
@@ -19,9 +19,10 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="smtpserver" class="org.apache.james.smtpserver.netty.SMTPServerFactory">
- <property name="protocolHandlerLoader" ref="protocolhandlerloader"/>
- <property name="fileSystem" ref="filesystem"/>
- <property name="dnsService" ref="dnsservice"/>
+ <constructor-arg index="0" ref="dnsservice"/>
+ <constructor-arg index="1" ref="protocolhandlerloader"/>
+ <constructor-arg index="2" ref="filesystem"/>
+ <constructor-arg index="3" ref="metricFactory"/>
</bean>
</beans>
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/OioSMTPServerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/OioSMTPServerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/OioSMTPServerTest.java
index 9b65e35..f265d25 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/OioSMTPServerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/OioSMTPServerTest.java
@@ -20,11 +20,12 @@ package org.apache.james.smtpserver;
import org.apache.james.smtpserver.netty.OioSMTPServer;
import org.apache.james.smtpserver.netty.SMTPServer;
+import org.apache.james.smtpserver.netty.SmtpMetricsImpl;
public class OioSMTPServerTest extends SMTPServerTest {
@Override
- protected SMTPServer createSMTPServer() {
- return new OioSMTPServer();
+ protected SMTPServer createSMTPServer(SmtpMetricsImpl smtpMetrics) {
+ return new OioSMTPServer(smtpMetrics);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/78f7dbb3/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
index 3585d50..780e919 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@@ -54,6 +56,7 @@ import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.filesystem.api.mock.MockFileSystem;
import org.apache.james.mailrepository.api.MailRepositoryStore;
import org.apache.james.mailrepository.mock.MockMailRepositoryStore;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.protocols.lib.PortUtil;
import org.apache.james.protocols.lib.mock.MockProtocolHandlerLoader;
import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
@@ -64,6 +67,7 @@ import org.apache.james.rrt.api.RecipientRewriteTable;
import org.apache.james.rrt.api.RecipientRewriteTableException;
import org.apache.james.rrt.lib.Mappings;
import org.apache.james.smtpserver.netty.SMTPServer;
+import org.apache.james.smtpserver.netty.SmtpMetricsImpl;
import org.apache.james.user.api.UsersRepository;
import org.apache.james.user.lib.mock.InMemoryUsersRepository;
import org.apache.mailet.HostAddress;
@@ -193,16 +197,18 @@ public class SMTPServerTest {
setUpSMTPServer();
}
- protected SMTPServer createSMTPServer() {
- return new SMTPServer();
+ protected SMTPServer createSMTPServer(SmtpMetricsImpl smtpMetrics) {
+ return new SMTPServer(smtpMetrics);
}
protected void setUpSMTPServer() {
-
Logger log = LoggerFactory.getLogger("SMTP");
// slf4j can't set programmatically any log level. It's just a facade
// log.setLevel(SimpleLog.LOG_LEVEL_ALL);
- smtpServer = createSMTPServer();
+ SmtpMetricsImpl smtpMetrics = mock(SmtpMetricsImpl.class);
+ when(smtpMetrics.getCommandsMetric()).thenReturn(mock(Metric.class));
+ when(smtpMetrics.getConnectionMetric()).thenReturn(mock(Metric.class));
+ smtpServer = createSMTPServer(smtpMetrics);
smtpServer.setDnsService(dnsServer);
smtpServer.setFileSystem(fileSystem);
smtpServer.setProtocolHandlerLoader(chain);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[13/16] james-project git commit: JAMES-1868 Adding metrics for
outgoing mails
Posted by ro...@apache.org.
JAMES-1868 Adding metrics for outgoing mails
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/67bbb4b6
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/67bbb4b6
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/67bbb4b6
Branch: refs/heads/master
Commit: 67bbb4b6357ca957fc413dde9a33b81e6f8e7fe5
Parents: ff1f8e9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Nov 25 09:13:37 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:32:21 2016 +0700
----------------------------------------------------------------------
server/mailet/mailets/pom.xml | 4 ++++
.../apache/james/transport/mailets/RemoteDelivery.java | 13 +++++++++++++
2 files changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/67bbb4b6/server/mailet/mailets/pom.xml
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/pom.xml b/server/mailet/mailets/pom.xml
index 6b4394a..ea7603c 100644
--- a/server/mailet/mailets/pom.xml
+++ b/server/mailet/mailets/pom.xml
@@ -71,6 +71,10 @@
<artifactId>james-server-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-managesieve</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/67bbb4b6/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
index 8c6637e..fa9ac3d 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
@@ -60,6 +60,8 @@ import org.apache.james.dnsservice.library.MXHostAddressIterator;
import org.apache.james.domainlist.api.DomainList;
import org.apache.james.domainlist.api.DomainListException;
import org.apache.james.lifecycle.api.LifecycleUtil;
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.queue.api.MailPrioritySupport;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueue.MailQueueException;
@@ -158,6 +160,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
private static final String PATTERN_STRING = "\\s*([0-9]*\\s*[\\*])?\\s*([0-9]+)\\s*([a-z,A-Z]*)\\s*";
private static final Pattern PATTERN = Patterns.compilePatternUncheckedException(PATTERN_STRING);
+ private static final String OUTGOING_MAILS = "outgoingMails";
@Inject
private DNSService dnsServer;
@@ -260,6 +263,9 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
private boolean isSSLEnable = false;
+ private MetricFactory metricFactory;
+ private Metric outgoingMailsMetric;
+
@Inject
public void setDomainList(DomainList domainList) {
this.domainList = domainList;
@@ -270,6 +276,11 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
this.queueFactory = queueFactory;
}
+ @Inject
+ public void setMetricFactory(MetricFactory metricFactory) {
+ this.metricFactory = metricFactory;
+ }
+
/**
* Initializes all arguments based on configuration values specified in the
* James configuration file.
@@ -277,6 +288,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
* @throws MessagingException on failure to initialize attributes.
*/
public void init() throws MessagingException {
+ outgoingMailsMetric = metricFactory.generate(OUTGOING_MAILS);
// Set isDebug flag.
isDebug = (getInitParameter("debug") == null) ? false : Boolean.valueOf(getInitParameter("debug"));
@@ -1050,6 +1062,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
logMessageBuffer = new StringBuilder(256).append("Mail (").append(mail.getName()).append(") sent successfully to ").append(outgoingMailServer.getHostName()).append(" at ").append(outgoingMailServer.getHost()).append(" from ").append(props.get("mail.smtp.from")).append(" for ")
.append(mail.getRecipients());
log(logMessageBuffer.toString());
+ outgoingMailsMetric.increment();
return true;
} catch (SendFailedException sfe) {
logSendFailedException(sfe);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[02/16] james-project git commit: JAMES-1868 Propose a new API for
Metrics
Posted by ro...@apache.org.
JAMES-1868 Propose a new API for Metrics
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/43747785
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/43747785
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/43747785
Branch: refs/heads/master
Commit: 4374778551ac2ebd58f883cc141dd06fd043d64f
Parents: 9ce8f34
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Nov 24 11:53:07 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:21:43 2016 +0700
----------------------------------------------------------------------
server/container/metrics/metrics-api/pom.xml | 35 ++++++++++++++++++++
.../org/apache/james/metrics/api/Metric.java | 28 ++++++++++++++++
.../apache/james/metrics/api/MetricFactory.java | 26 +++++++++++++++
server/pom.xml | 20 ++++++++++-
4 files changed, 108 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/43747785/server/container/metrics/metrics-api/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-api/pom.xml b/server/container/metrics/metrics-api/pom.xml
new file mode 100644
index 0000000..800e8a6
--- /dev/null
+++ b/server/container/metrics/metrics-api/pom.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>james-server</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.0.0-beta6-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>james-server-metrics-api</artifactId>
+
+ <name>Apache James :: Server :: Metrics :: API</name>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/43747785/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/Metric.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/Metric.java b/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/Metric.java
new file mode 100644
index 0000000..b8b552f
--- /dev/null
+++ b/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/Metric.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.metrics.api;
+
+public interface Metric {
+
+ void increment();
+
+ void decrement();
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/43747785/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java b/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
new file mode 100644
index 0000000..b007428
--- /dev/null
+++ b/server/container/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.metrics.api;
+
+public interface MetricFactory {
+
+ Metric generate(String name);
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/43747785/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index e0de06a..b56f35d 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -56,13 +56,15 @@
<module>karaf/features</module>
<module>karaf/integration</module>
- <module>container/guice</module>
<module>container/cli</module>
<module>container/core</module>
<module>container/filesystem-api</module>
+ <module>container/guice</module>
<module>container/jetty</module>
<module>container/lifecycle-api</module>
<module>container/mailbox-adapter</module>
+ <module>container/metrics/metrics-api</module>
+ <module>container/metrics/metrics-dropwizard</module>
<module>container/spring</module>
<module>container/util</module>
<module>container/util-java8</module>
@@ -186,6 +188,7 @@
<assertj-3.version>3.3.0</assertj-3.version>
<testcontainers-version>1.0.2</testcontainers-version>
<guavate.version>1.0.0</guavate.version>
+ <metrics.version>3.1.0</metrics.version>
</properties>
<dependencyManagement>
@@ -599,6 +602,16 @@
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-dropwizard</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
<artifactId>james-server-jmap</artifactId>
<version>${project.version}</version>
</dependency>
@@ -1296,6 +1309,11 @@
<artifactId>netty</artifactId>
<version>${netty.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ <version>${metrics.version}</version>
+ </dependency>
<!-- This needed to let the bundle plugin to generate the right import statement -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[09/16] james-project git commit: JAMES-1868 Adding a metric for
Local Delivered emails
Posted by ro...@apache.org.
JAMES-1868 Adding a metric for Local Delivered emails
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9d40cb20
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9d40cb20
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9d40cb20
Branch: refs/heads/master
Commit: 9d40cb205160d05e4caefcfb49885e262a84e3c8
Parents: 6ce3c8e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Nov 25 10:44:34 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:32:21 2016 +0700
----------------------------------------------------------------------
.../james/transport/mailets/LocalDelivery.java | 7 ++++++-
.../james/transport/mailets/ToRecipientFolder.java | 9 ++++++++-
.../transport/mailets/delivery/SimpleMailStore.java | 15 +++++++++++++--
.../mailets/delivery/LocalDeliveryTest.java | 7 ++++++-
.../mailets/delivery/SieveIntegrationTest.java | 2 +-
.../mailets/delivery/SimpleMailStoreTest.java | 2 ++
.../mailets/delivery/ToRecipientFolderTest.java | 6 +++++-
7 files changed, 41 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/9d40cb20/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
index 70a193e..130bf91 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
@@ -28,6 +28,7 @@ import org.apache.james.domainlist.api.DomainList;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.transport.mailets.delivery.MailDispatcher;
import org.apache.james.transport.mailets.delivery.MailboxAppender;
import org.apache.james.transport.mailets.delivery.SimpleMailStore;
@@ -46,14 +47,17 @@ import org.apache.mailet.base.GenericMailet;
*/
public class LocalDelivery extends GenericMailet {
+ public static final String LOCAL_DELIVERED_MAILS_METRIC_NAME = "localDeliveredMails";
private final UsersRepository usersRepository;
private final MailboxManager mailboxManager;
private final RecipientRewriteTable recipientRewriteTable;
+ private final MetricFactory metricFactory;
private MailDispatcher mailDispatcher;
@Inject
public LocalDelivery(org.apache.james.rrt.api.RecipientRewriteTable rrt, UsersRepository usersRepository,
- @Named("mailboxmanager") MailboxManager mailboxManager, DomainList domainList) {
+ @Named("mailboxmanager") MailboxManager mailboxManager, DomainList domainList, MetricFactory metricFactory) {
+ this.metricFactory = metricFactory;
this.usersRepository = usersRepository;
this.mailboxManager = mailboxManager;
this.recipientRewriteTable = new RecipientRewriteTable(rrt, domainList);
@@ -82,6 +86,7 @@ public class LocalDelivery extends GenericMailet {
.mailboxAppender(new MailboxAppender(mailboxManager, getMailetContext().getLogger()))
.usersRepository(usersRepository)
.folder(MailboxConstants.INBOX)
+ .metric(metricFactory.generate(LOCAL_DELIVERED_MAILS_METRIC_NAME))
.log(log)
.build())
.consume(getInitParameter("consume", true))
http://git-wip-us.apache.org/repos/asf/james-project/blob/9d40cb20/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRecipientFolder.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRecipientFolder.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRecipientFolder.java
index 9cebeb1..bba8ed2 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRecipientFolder.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRecipientFolder.java
@@ -18,6 +18,8 @@
****************************************************************/
package org.apache.james.transport.mailets;
+import static org.apache.james.transport.mailets.LocalDelivery.LOCAL_DELIVERED_MAILS_METRIC_NAME;
+
import javax.inject.Inject;
import javax.inject.Named;
import javax.mail.MessagingException;
@@ -25,6 +27,7 @@ import javax.mail.MessagingException;
import org.apache.commons.logging.Log;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.transport.mailets.delivery.MailDispatcher;
import org.apache.james.transport.mailets.delivery.MailboxAppender;
import org.apache.james.transport.mailets.delivery.SimpleMailStore;
@@ -56,10 +59,13 @@ public class ToRecipientFolder extends GenericMailet {
private final MailboxManager mailboxManager;
private final UsersRepository usersRepository;
+ private final MetricFactory metricFactory;
private MailDispatcher mailDispatcher;
@Inject
- public ToRecipientFolder(@Named("mailboxmanager")MailboxManager mailboxManager, UsersRepository usersRepository) {
+ public ToRecipientFolder(@Named("mailboxmanager")MailboxManager mailboxManager, UsersRepository usersRepository,
+ MetricFactory metricFactory) {
+ this.metricFactory = metricFactory;
this.mailboxManager = mailboxManager;
this.usersRepository = usersRepository;
}
@@ -81,6 +87,7 @@ public class ToRecipientFolder extends GenericMailet {
.mailboxAppender(new MailboxAppender(mailboxManager, getMailetContext().getLogger()))
.usersRepository(usersRepository)
.folder(getInitParameter(FOLDER_PARAMETER, MailboxConstants.INBOX))
+ .metric(metricFactory.generate(LOCAL_DELIVERED_MAILS_METRIC_NAME))
.log(log)
.build())
.consume(getInitParameter(CONSUME_PARAMETER, false))
http://git-wip-us.apache.org/repos/asf/james-project/blob/9d40cb20/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SimpleMailStore.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SimpleMailStore.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SimpleMailStore.java
index d693065..7f2783e 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SimpleMailStore.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SimpleMailStore.java
@@ -22,6 +22,7 @@ package org.apache.james.transport.mailets.delivery;
import javax.mail.MessagingException;
import org.apache.commons.logging.Log;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.user.api.UsersRepository;
import org.apache.james.user.api.UsersRepositoryException;
import org.apache.mailet.Mail;
@@ -39,6 +40,7 @@ public class SimpleMailStore implements MailStore {
private UsersRepository usersRepos;
private MailboxAppender mailboxAppender;
private String folder;
+ private Metric metric;
private Log log;
public Builder folder(String folder) {
@@ -61,23 +63,31 @@ public class SimpleMailStore implements MailStore {
return this;
}
+ public Builder metric(Metric metric) {
+ this.metric = metric;
+ return this;
+ }
+
public SimpleMailStore build() throws MessagingException {
Preconditions.checkNotNull(usersRepos);
Preconditions.checkNotNull(folder);
Preconditions.checkNotNull(log);
Preconditions.checkNotNull(mailboxAppender);
- return new SimpleMailStore(mailboxAppender, usersRepos, log, folder);
+ Preconditions.checkNotNull(metric);
+ return new SimpleMailStore(mailboxAppender, usersRepos, metric, log, folder);
}
}
private final MailboxAppender mailboxAppender;
private final UsersRepository usersRepository;
+ private final Metric metric;
private final Log log;
private final String folder;
- private SimpleMailStore(MailboxAppender mailboxAppender, UsersRepository usersRepository, Log log, String folder) {
+ private SimpleMailStore(MailboxAppender mailboxAppender, UsersRepository usersRepository, Metric metric, Log log, String folder) {
this.mailboxAppender = mailboxAppender;
this.usersRepository = usersRepository;
+ this.metric = metric;
this.log = log;
this.folder = folder;
}
@@ -89,6 +99,7 @@ public class SimpleMailStore implements MailStore {
String locatedFolder = locateFolder(username, mail);
mailboxAppender.append(mail.getMessage(), username, locatedFolder);
+ metric.increment();
log.info("Local delivered mail " + mail.getName() + " successfully from " + DeliveryUtils.prettyPrint(mail.getSender())
+ " to " + DeliveryUtils.prettyPrint(recipient) + " in folder " + locatedFolder);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/9d40cb20/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
index 61d842b..84d2e50 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
@@ -20,6 +20,7 @@
package org.apache.james.transport.mailets.delivery;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -46,6 +47,8 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.rrt.api.RecipientRewriteTable;
import org.apache.james.transport.mailets.LocalDelivery;
import org.apache.james.user.api.UsersRepository;
@@ -77,7 +80,9 @@ public class LocalDeliveryTest {
DomainList domainList = mock(DomainList.class);
- testee = new LocalDelivery(recipientRewriteTable, usersRepository, mailboxManager, domainList);
+ MetricFactory metricFactory = mock(MetricFactory.class);
+ when(metricFactory.generate(anyString())).thenReturn(mock(Metric.class));
+ testee = new LocalDelivery(recipientRewriteTable, usersRepository, mailboxManager, domainList, metricFactory);
user = mock(MailboxSession.User.class);
MailboxSession session = mock(MailboxSession.class);
http://git-wip-us.apache.org/repos/asf/james-project/blob/9d40cb20/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
index 0e669e9..97556de 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
@@ -88,7 +88,7 @@ public class SieveIntegrationTest {
fakeMailContext = FakeMailContext.builder().logger(mock(Logger.class)).build();
testee = new Sieve(usersRepository, resourceLocator);
- testee.init(new FakeMailetConfig("Sieve", fakeMailContext));
+ testee.init(FakeMailetConfig.builder().mailetName("Sieve").mailetContext(fakeMailContext).build());
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/9d40cb20/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SimpleMailStoreTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SimpleMailStoreTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SimpleMailStoreTest.java
index 42d09f2..15cac3f 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SimpleMailStoreTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SimpleMailStoreTest.java
@@ -36,6 +36,7 @@ import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
import org.apache.commons.logging.Log;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.user.api.UsersRepository;
import org.apache.james.user.api.UsersRepositoryException;
import org.apache.mailet.MailAddress;
@@ -60,6 +61,7 @@ public class SimpleMailStoreTest {
.usersRepository(usersRepository)
.mailboxAppender(mailboxAppender)
.folder(FOLDER)
+ .metric(mock(Metric.class))
.log(mock(Log.class))
.build();
http://git-wip-us.apache.org/repos/asf/james-project/blob/9d40cb20/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
index 48306f3..f166c09 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets.delivery;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -46,6 +47,7 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.transport.mailets.ToRecipientFolder;
import org.apache.james.user.api.UsersRepository;
@@ -86,7 +88,9 @@ public class ToRecipientFolderTest {
user = mock(MailboxSession.User.class);
- testee = new ToRecipientFolder(mailboxManager, usersRepository, mock(MetricFactory.class));
+ MetricFactory metricFactory = mock(MetricFactory.class);
+ when(metricFactory.generate(anyString())).thenReturn(mock(Metric.class));
+ testee = new ToRecipientFolder(mailboxManager, usersRepository, metricFactory);
MailboxSession session = mock(MailboxSession.class);
when(session.getPathDelimiter()).thenReturn('.');
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[05/16] james-project git commit: JAMES-1868 Add metrics for Queues
Posted by ro...@apache.org.
JAMES-1868 Add metrics for Queues
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/197cc76f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/197cc76f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/197cc76f
Branch: refs/heads/master
Commit: 197cc76f0ca84db592a03499a3fd5696b9cd3952
Parents: 8e52e76
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Nov 24 11:56:55 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:29:36 2016 +0700
----------------------------------------------------------------------
server/queue/queue-activemq/pom.xml | 4 ++++
.../apache/james/queue/activemq/ActiveMQMailQueue.java | 9 +++++----
.../james/queue/activemq/ActiveMQMailQueueFactory.java | 7 ++++---
.../james/queue/activemq/ActiveMQMailQueueTest.java | 13 +++++++++----
server/queue/queue-jms/pom.xml | 10 +++++++---
.../java/org/apache/james/queue/jms/JMSMailQueue.java | 6 +++++-
.../apache/james/queue/jms/JMSMailQueueFactory.java | 12 ++++++++----
.../james/queue/jms/AbstractJMSMailQueueTest.java | 4 +++-
8 files changed, 45 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-activemq/pom.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/pom.xml b/server/queue/queue-activemq/pom.xml
index b265406..9f8c0fe 100644
--- a/server/queue/queue-activemq/pom.xml
+++ b/server/queue/queue-activemq/pom.xml
@@ -122,6 +122,10 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
index 068a7bb..d45a89e 100644
--- a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
+++ b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
@@ -43,6 +43,7 @@ import org.apache.activemq.util.JMSExceptionSupport;
import org.apache.james.core.MimeMessageCopyOnWriteProxy;
import org.apache.james.core.MimeMessageInputStream;
import org.apache.james.core.MimeMessageSource;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.jms.JMSMailQueue;
@@ -92,8 +93,8 @@ public class ActiveMQMailQueue extends JMSMailQueue implements ActiveMQSupport {
* Construct a {@link ActiveMQMailQueue} which only use {@link BlobMessage}
*
*/
- public ActiveMQMailQueue(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queuename, Logger logger) {
- this(connectionFactory, mailQueueItemDecoratorFactory, queuename, true, logger);
+ public ActiveMQMailQueue(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queuename, Metric enqueuedMailsMetric, Logger logger) {
+ this(connectionFactory, mailQueueItemDecoratorFactory, queuename, true, enqueuedMailsMetric, logger);
}
/**
@@ -104,8 +105,8 @@ public class ActiveMQMailQueue extends JMSMailQueue implements ActiveMQSupport {
* @param useBlob
* @param logger
*/
- public ActiveMQMailQueue(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queuename, boolean useBlob, Logger logger) {
- super(connectionFactory, mailQueueItemDecoratorFactory, queuename, logger);
+ public ActiveMQMailQueue(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queuename, boolean useBlob, Metric enqueuedMailsMetric, Logger logger) {
+ super(connectionFactory, mailQueueItemDecoratorFactory, queuename, enqueuedMailsMetric, logger);
this.useBlob = useBlob;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
index 6547be3..430222e 100644
--- a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
+++ b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
@@ -21,6 +21,7 @@ package org.apache.james.queue.activemq;
import javax.inject.Inject;
import javax.jms.ConnectionFactory;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.MailQueueFactory;
@@ -35,8 +36,8 @@ public class ActiveMQMailQueueFactory extends JMSMailQueueFactory {
private boolean useBlob = true;
@Inject
- public ActiveMQMailQueueFactory(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory) {
- super(connectionFactory, mailQueueItemDecoratorFactory);
+ public ActiveMQMailQueueFactory(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, MetricFactory metricFactory) {
+ super(connectionFactory, mailQueueItemDecoratorFactory, metricFactory);
}
public void setUseBlobMessages(boolean useBlob) {
@@ -45,6 +46,6 @@ public class ActiveMQMailQueueFactory extends JMSMailQueueFactory {
@Override
protected MailQueue createMailQueue(String name) {
- return new ActiveMQMailQueue(connectionFactory, mailQueueItemDecoratorFactory, name, useBlob, log);
+ return new ActiveMQMailQueue(connectionFactory, mailQueueItemDecoratorFactory, name, useBlob, metricFactory.generate("enqueuedMails:" + name), log);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java b/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
index b490d5d..1203c74 100644
--- a/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
+++ b/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
@@ -18,11 +18,18 @@
****************************************************************/
package org.apache.james.queue.activemq;
+import static org.mockito.Mockito.mock;
+
+import java.util.Arrays;
+
+import javax.jms.ConnectionFactory;
+
import org.apache.activemq.broker.BrokerPlugin;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.plugin.StatisticsBrokerPlugin;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.jms.AbstractJMSMailQueueTest;
import org.apache.james.queue.jms.JMSMailQueue;
@@ -31,9 +38,6 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.jms.ConnectionFactory;
-import java.util.Arrays;
-
public abstract class ActiveMQMailQueueTest extends AbstractJMSMailQueueTest {
private static BrokerService brokerService;
@@ -74,7 +78,8 @@ public abstract class ActiveMQMailQueueTest extends AbstractJMSMailQueueTest {
@Override
protected JMSMailQueue createQueue(ConnectionFactory factory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queueName) {
Logger log = LoggerFactory.getLogger(ActiveMQMailQueueTest.class);
- return new ActiveMQMailQueue(factory, mailQueueItemDecoratorFactory, queueName, useBlobMessages(), log);
+
+ return new ActiveMQMailQueue(factory, mailQueueItemDecoratorFactory, queueName, useBlobMessages(), mock(Metric.class), log);
}
protected boolean useBlobMessages() {
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-jms/pom.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/pom.xml b/server/queue/queue-jms/pom.xml
index b1aea5c..8e1850c 100644
--- a/server/queue/queue-jms/pom.xml
+++ b/server/queue/queue-jms/pom.xml
@@ -35,7 +35,11 @@
<dependencies>
<dependency>
<groupId>org.apache.james</groupId>
- <artifactId>james-server-queue-api</artifactId>
+ <artifactId>apache-mailet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
@@ -43,11 +47,11 @@
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
- <artifactId>james-server-core</artifactId>
+ <artifactId>james-server-metrics-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
- <artifactId>apache-mailet-api</artifactId>
+ <artifactId>james-server-queue-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
index 1634354..f3ce680 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
@@ -49,6 +49,7 @@ import javax.mail.internet.MimeMessage;
import org.apache.james.core.MailImpl;
import org.apache.james.core.MimeMessageCopyOnWriteProxy;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.queue.api.MailPrioritySupport;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
@@ -73,13 +74,15 @@ public class JMSMailQueue implements ManageableMailQueue, JMSSupport, MailPriori
protected final String queueName;
protected final ConnectionFactory connectionFactory;
protected final MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory;
+ protected final Metric enqueuedMailsMetric;
protected final Logger logger;
public final static String FORCE_DELIVERY = "FORCE_DELIVERY";
- public JMSMailQueue(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queueName, Logger logger) {
+ public JMSMailQueue(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queueName, Metric enqueuedMailsMetric, Logger logger) {
this.connectionFactory = connectionFactory;
this.mailQueueItemDecoratorFactory = mailQueueItemDecoratorFactory;
this.queueName = queueName;
+ this.enqueuedMailsMetric = enqueuedMailsMetric;
this.logger = logger;
}
@@ -204,6 +207,7 @@ public class JMSMailQueue implements ManageableMailQueue, JMSSupport, MailPriori
produceMail(session, props, msgPrio, mail);
+ enqueuedMailsMetric.increment();
} catch (Exception e) {
if (session != null) {
try {
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
index 897b80a..eea2319 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
@@ -21,6 +21,8 @@ package org.apache.james.queue.jms;
import javax.inject.Inject;
import javax.jms.ConnectionFactory;
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueueFactory;
@@ -31,18 +33,20 @@ import org.apache.james.queue.library.AbstractMailQueueFactory;
*/
public class JMSMailQueueFactory extends AbstractMailQueueFactory {
- protected ConnectionFactory connectionFactory;
- protected MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory;
+ protected final ConnectionFactory connectionFactory;
+ protected final MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory;
+ protected final MetricFactory metricFactory;
@Inject
- public JMSMailQueueFactory(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory) {
+ public JMSMailQueueFactory(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, MetricFactory metricFactory) {
this.connectionFactory = connectionFactory;
this.mailQueueItemDecoratorFactory = mailQueueItemDecoratorFactory;
+ this.metricFactory = metricFactory;
}
@Override
protected MailQueue createMailQueue(String name) {
- return new JMSMailQueue(connectionFactory, mailQueueItemDecoratorFactory, name, log);
+ return new JMSMailQueue(connectionFactory, mailQueueItemDecoratorFactory, name, metricFactory.generate("enqueuedMail:" + name), log);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/197cc76f/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java b/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
index 7d15da6..f4af982 100644
--- a/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
+++ b/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
import java.io.IOException;
import java.util.Arrays;
@@ -39,6 +40,7 @@ import javax.mail.internet.MimeMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.james.core.MailImpl;
+import org.apache.james.metrics.api.Metric;
import org.apache.james.protocols.smtp.MailAddressException;
import org.apache.james.queue.api.MailQueue.MailQueueItem;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
@@ -69,7 +71,7 @@ public abstract class AbstractJMSMailQueueTest {
protected JMSMailQueue createQueue(ConnectionFactory factory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queueName) {
Logger log = LoggerFactory.getLogger(AbstractJMSMailQueueTest.class);
- return new JMSMailQueue(factory, mailQueueItemDecoratorFactory, queueName, log);
+ return new JMSMailQueue(factory, mailQueueItemDecoratorFactory, queueName, mock(Metric.class), log);
}
@Before
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[04/16] james-project git commit: JAMES-1868 Add support for
DropWizard metrics in Guice
Posted by ro...@apache.org.
JAMES-1868 Add support for DropWizard metrics in Guice
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/69769e04
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/69769e04
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/69769e04
Branch: refs/heads/master
Commit: 69769e044eafb07ea43ba5876e3b242d67ec1fa0
Parents: 197cc76
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Nov 24 11:57:44 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:29:36 2016 +0700
----------------------------------------------------------------------
server/container/guice/guice-common/pom.xml | 8 +++++
.../james/modules/CommonServicesModule.java | 2 ++
.../modules/server/DropWizardMetricsModule.java | 36 ++++++++++++++++++++
3 files changed, 46 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/69769e04/server/container/guice/guice-common/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/pom.xml b/server/container/guice/guice-common/pom.xml
index 983b637..9fb7eb8 100644
--- a/server/container/guice/guice-common/pom.xml
+++ b/server/container/guice/guice-common/pom.xml
@@ -192,6 +192,14 @@
<artifactId>james-server-mailetcontainer-camel</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-metrics-dropwizard</artifactId>
+ </dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>james-server-protocols-imap4</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/69769e04/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
index df0d349..60d1f41 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
@@ -33,6 +33,7 @@ import org.apache.james.filesystem.api.JamesDirectoriesProvider;
import org.apache.james.modules.server.AsyncTasksExecutorModule;
import org.apache.james.modules.server.ConfigurationProviderModule;
import org.apache.james.modules.server.DNSServiceModule;
+import org.apache.james.modules.server.DropWizardMetricsModule;
import org.apache.james.onami.lifecycle.PreDestroyModule;
import com.google.inject.AbstractModule;
@@ -55,6 +56,7 @@ public class CommonServicesModule extends AbstractModule {
install(new PreDestroyModule());
install(new DNSServiceModule());
install(new AsyncTasksExecutorModule());
+ install(new DropWizardMetricsModule());
bind(FileSystemImpl.class).in(Scopes.SINGLETON);
http://git-wip-us.apache.org/repos/asf/james-project/blob/69769e04/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
new file mode 100644
index 0000000..31f66fa
--- /dev/null
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.modules.server;
+
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.dropwizard.DropWizardMetricFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+
+public class DropWizardMetricsModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+ bind(DropWizardMetricFactory.class).in(Scopes.SINGLETON);
+ bind(MetricFactory.class).to(DropWizardMetricFactory.class);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[16/16] james-project git commit: JAMES-1868 DropWizardFactory should
not be Configurable, otherwise Spring fails
Posted by ro...@apache.org.
JAMES-1868 DropWizardFactory should not be Configurable, otherwise Spring fails
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7bcc6201
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7bcc6201
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7bcc6201
Branch: refs/heads/master
Commit: 7bcc6201bac978106381a6b431796c6f62704786
Parents: 6c9c5e6
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Nov 30 09:59:01 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 17:36:41 2016 +0700
----------------------------------------------------------------------
.../modules/server/DropWizardMetricsModule.java | 24 ++++++++++++++++----
.../dropwizard/DropWizardMetricFactory.java | 7 ++----
2 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bcc6201/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
index 8e77370..e3ac9f7 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
@@ -50,17 +50,17 @@ public class DropWizardMetricsModule extends AbstractModule {
public static class DropWizardConfigurationPerformer implements ConfigurationPerformer {
public static final HierarchicalConfiguration NO_CONFIGURATION = null;
- private final DropWizardMetricFactory metricFactory;
+ private final DropWizardInitializer dropWizardInitializer;
@Inject
- public DropWizardConfigurationPerformer(DropWizardMetricFactory metricFactory) {
- this.metricFactory = metricFactory;
+ public DropWizardConfigurationPerformer(DropWizardInitializer dropWizardInitializer) {
+ this.dropWizardInitializer = dropWizardInitializer;
}
@Override
public void initModule() {
try {
- metricFactory.configure(NO_CONFIGURATION);
+ dropWizardInitializer.configure(NO_CONFIGURATION);
} catch (ConfigurationException e) {
throw Throwables.propagate(e);
}
@@ -68,7 +68,21 @@ public class DropWizardMetricsModule extends AbstractModule {
@Override
public List<Class<? extends Configurable>> forClasses() {
- return ImmutableList.of(DropWizardMetricFactory.class);
+ return ImmutableList.of(DropWizardInitializer.class);
+ }
+ }
+
+ public static class DropWizardInitializer implements Configurable {
+ private final DropWizardMetricFactory dropWizardMetricFactory;
+
+ @Inject
+ public DropWizardInitializer(DropWizardMetricFactory dropWizardMetricFactory) {
+ this.dropWizardMetricFactory = dropWizardMetricFactory;
+ }
+
+ @Override
+ public void configure(HierarchicalConfiguration config) throws ConfigurationException {
+ dropWizardMetricFactory.start();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bcc6201/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
index 786045f..8c7f731 100644
--- a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
+++ b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
@@ -22,15 +22,13 @@ package org.apache.james.metrics.dropwizard;
import javax.annotation.PreDestroy;
import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.metrics.api.Metric;
import org.apache.james.metrics.api.MetricFactory;
import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
-public class DropWizardMetricFactory implements MetricFactory, Configurable {
+public class DropWizardMetricFactory implements MetricFactory {
private final MetricRegistry metricRegistry;
private final JmxReporter jmxReporter;
@@ -46,8 +44,7 @@ public class DropWizardMetricFactory implements MetricFactory, Configurable {
return new DropWizardMetric(metricRegistry.counter(name));
}
- @Override
- public void configure(HierarchicalConfiguration config) throws ConfigurationException {
+ public void start() throws ConfigurationException {
jmxReporter.start();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[08/16] james-project git commit: JAMES-1868 Adding metrics as a
Mailet
Posted by ro...@apache.org.
JAMES-1868 Adding metrics as a Mailet
I changed mailetContainer.xml for cassandra docker in order to count :
- errors of the mail pipeline
- relay denied
- localAddressErrors
- spam
- bounces
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6ce3c8ec
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6ce3c8ec
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6ce3c8ec
Branch: refs/heads/master
Commit: 6ce3c8ecdcb34091d34581d8cadc9f1b42c04c9a
Parents: 7a9c438
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Nov 25 09:45:51 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Nov 30 16:32:21 2016 +0700
----------------------------------------------------------------------
.../guice/destination/conf/mailetcontainer.xml | 15 ++++
.../james/transport/mailets/MetricsMailet.java | 76 ++++++++++++++++++++
.../transport/mailets/MetricsMailetTest.java | 76 ++++++++++++++++++++
.../mailets/delivery/ToRecipientFolderTest.java | 3 +-
4 files changed, 169 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ce3c8ec/dockerfiles/run/guice/destination/conf/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/destination/conf/mailetcontainer.xml
index 5008caa..25d02d4 100644
--- a/dockerfiles/run/guice/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/destination/conf/mailetcontainer.xml
@@ -64,6 +64,9 @@
</processor>
<processor state="error" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>mailetContainerErrors</metricName>
+ </mailet>
<mailet match="All" class="Bounce"/>
<mailet match="All" class="ToRepository">
<repositoryPath>file://var/mail/error/</repositoryPath>
@@ -108,12 +111,18 @@
</processor>
<processor state="spam" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>mailetContainerSpam</metricName>
+ </mailet>
<mailet match="All" class="ToRepository">
<repositoryPath>file://var/mail/spam/</repositoryPath>
</mailet>
</processor>
<processor state="local-address-error" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>mailetContainerLocalAddressError</metricName>
+ </mailet>
<mailet match="All" class="Bounce">
<attachment>none</attachment>
</mailet>
@@ -123,6 +132,9 @@
</processor>
<processor state="relay-denied" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>mailetContainerRelayDenied</metricName>
+ </mailet>
<mailet match="All" class="Bounce">
<attachment>none</attachment>
</mailet>
@@ -133,6 +145,9 @@
</processor>
<processor state="bounces" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>bounces</metricName>
+ </mailet>
<mailet match="All" class="DSNBounce">
<passThrough>false</passThrough>
</mailet>
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ce3c8ec/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/MetricsMailet.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/MetricsMailet.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/MetricsMailet.java
new file mode 100644
index 0000000..22f5461
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/MetricsMailet.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * 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.transport.mailets;
+
+import javax.inject.Inject;
+import javax.mail.MessagingException;
+
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * This Metrics mailet increments a counter on every incoming emails.
+ *
+ * This counter is accessible via JMX.
+ *
+ * Example :
+ *
+ * <mailet matcher="all" class="MetricsMailet">
+ * <metricName>relayDenied</metricName>
+ * </mailet>
+ *
+ * Will increment a counter relay denied
+ */
+public class MetricsMailet extends GenericMailet {
+ public static final String METRIC_NAME = "metricName";
+
+ private final MetricFactory metricFactory;
+ private Metric metric;
+
+ @Inject
+ public MetricsMailet(MetricFactory metricFactory) {
+ this.metricFactory = metricFactory;
+ }
+
+ @Override
+ public void init() throws MessagingException {
+ String metricName = getInitParameter(METRIC_NAME);
+ init(metricName);
+ }
+
+ private void init(String metricName) {
+ Preconditions.checkNotNull(metricName);
+ metric = metricFactory.generate(metricName);
+ }
+
+ @Override
+ public void service(Mail mail) throws MessagingException {
+ metric.increment();
+ }
+
+ @Override
+ public String getMailetInfo() {
+ return "Metrics mailet";
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ce3c8ec/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java
new file mode 100644
index 0000000..29032ab
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * 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.transport.mailets;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailetConfig;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class MetricsMailetTest {
+
+ public static final String MAILET_NAME = "Metric test";
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private MetricFactory metricFactory;
+ private Metric metric;
+ private MetricsMailet mailet;
+
+ @Before
+ public void setUp() throws Exception {
+ metricFactory = mock(MetricFactory.class);
+ metric = mock(Metric.class);
+ when(metricFactory.generate(anyString())).thenReturn(metric);
+
+ mailet = new MetricsMailet(metricFactory);
+ }
+
+ @Test
+ public void initShouldThrowWhenMetricNameIsNotGiven() throws Exception {
+ expectedException.expect(NullPointerException.class);
+
+ mailet.init(FakeMailetConfig.builder().mailetName(MAILET_NAME).build());
+ }
+
+ @Test
+ public void serviceShouldIncrementMetricCounter() throws Exception {
+ mailet.init(FakeMailetConfig.builder()
+ .mailetName(MAILET_NAME)
+ .setProperty(MetricsMailet.METRIC_NAME, "metricName")
+ .build());
+
+ mailet.service(FakeMail.builder().build());
+
+ verify(metric).increment();
+ verifyNoMoreInteractions(metric);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ce3c8ec/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
index 6ae5aa2..48306f3 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
@@ -46,6 +46,7 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.transport.mailets.ToRecipientFolder;
import org.apache.james.user.api.UsersRepository;
import org.apache.mailet.Mail;
@@ -85,7 +86,7 @@ public class ToRecipientFolderTest {
user = mock(MailboxSession.User.class);
- testee = new ToRecipientFolder(mailboxManager, usersRepository);
+ testee = new ToRecipientFolder(mailboxManager, usersRepository, mock(MetricFactory.class));
MailboxSession session = mock(MailboxSession.class);
when(session.getPathDelimiter()).thenReturn('.');
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org