You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/01/19 12:07:21 UTC
[07/14] james-project git commit: JAMES-2289 MailQueue factories
should return created mail queues
JAMES-2289 MailQueue factories should return created mail 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/7fa66076
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7fa66076
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7fa66076
Branch: refs/heads/master
Commit: 7fa66076ea091853b34149db3005058efa14383d
Parents: c47bf36
Author: benwa <bt...@linagora.com>
Authored: Thu Jan 18 17:58:54 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Jan 19 18:56:09 2018 +0700
----------------------------------------------------------------------
.../apache/james/jmap/send/MailSpoolTest.java | 5 +-
.../activemq/ActiveMQMailQueueFactoryTest.java | 58 ++++++++++++++++++
.../james/queue/api/MailQueueFactory.java | 4 ++
.../queue/api/MailQueueFactoryContract.java | 63 ++++++++++++++++++++
.../james/queue/file/FileMailQueueFactory.java | 8 +++
.../queue/file/FileMailQueueFactoryTest.java | 48 +++++++++++++++
.../queue/library/AbstractMailQueueFactory.java | 6 ++
.../queue/jms/JMSMailQueueFactoryTest.java | 58 ++++++++++++++++++
.../queue/memory/MemoryMailQueueFactory.java | 6 ++
.../memory/MemoryMailQueueFactoryTest.java | 9 ++-
10 files changed, 262 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
index 3bc50b0..5912196 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
@@ -41,9 +41,10 @@ public class MailSpoolTest {
@Before
public void setup() {
- myQueue = new MemoryMailQueueFactory.MemoryMailQueue(MailQueueFactory.SPOOL, new RawMailQueueItemDecoratorFactory());
+ MemoryMailQueueFactory mailQueueFactory = new MemoryMailQueueFactory(new RawMailQueueItemDecoratorFactory());
+ myQueue = mailQueueFactory.getQueue(MailQueueFactory.SPOOL);
- mailSpool = new MailSpool(name -> myQueue);
+ mailSpool = new MailSpool(mailQueueFactory);
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactoryTest.java b/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactoryTest.java
new file mode 100644
index 0000000..0af1569
--- /dev/null
+++ b/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactoryTest.java
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.queue.activemq;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.MailQueueFactoryContract;
+import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
+import org.apache.james.queue.jms.BrokerExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(BrokerExtension.class)
+public class ActiveMQMailQueueFactoryTest implements MailQueueFactoryContract {
+
+ private ActiveMQMailQueueFactory mailQueueFactory;
+
+ @BeforeEach
+ public void setUp(BrokerService brokerService) throws Exception {
+ ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false");
+ RawMailQueueItemDecoratorFactory mailQueueItemDecoratorFactory = new RawMailQueueItemDecoratorFactory();
+ NoopMetricFactory metricFactory = new NoopMetricFactory();
+ mailQueueFactory = new ActiveMQMailQueueFactory(connectionFactory, mailQueueItemDecoratorFactory, metricFactory);
+ mailQueueFactory.setUseJMX(false);
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ mailQueueFactory.destroy();
+ }
+
+ @Override
+ public MailQueueFactory getMailQueueFactory() {
+ return mailQueueFactory;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueFactory.java b/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueFactory.java
index 0e56d50..2bec132 100644
--- a/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueFactory.java
+++ b/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueFactory.java
@@ -19,6 +19,8 @@
package org.apache.james.queue.api;
+import java.util.List;
+
/**
* Factory for {@link MailQueue}
*/
@@ -36,4 +38,6 @@ public interface MailQueueFactory {
* @return queue
*/
MailQueue getQueue(String name);
+
+ List<MailQueue> getUsedMailQueues();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueFactoryContract.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueFactoryContract.java b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueFactoryContract.java
new file mode 100644
index 0000000..f1c556f
--- /dev/null
+++ b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueFactoryContract.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.queue.api;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+public interface MailQueueFactoryContract {
+
+ String NAME_1 = "name1";
+ String NAME_2 = "name2";
+
+ MailQueueFactory getMailQueueFactory();
+
+ @Test
+ default void getUsedMailQueuesShouldReturnWhenNoMailQueue() {
+ assertThat(getMailQueueFactory().getUsedMailQueues())
+ .isEmpty();
+ }
+
+ @Test
+ default void getUsedMailQueuesShouldReturnPreviouslyCreatedMailQueues() {
+ MailQueueFactory mailQueueFactory = getMailQueueFactory();
+
+ mailQueueFactory.getQueue(NAME_1);
+ mailQueueFactory.getQueue(NAME_2);
+
+ assertThat(mailQueueFactory.getUsedMailQueues())
+ .extracting(MailQueue::getMailQueueName)
+ .containsOnly(NAME_1, NAME_2);
+ }
+
+ @Test
+ default void getUsedMailQueuesShouldNotReturnDuplicate() {
+ MailQueueFactory mailQueueFactory = getMailQueueFactory();
+
+ mailQueueFactory.getQueue(NAME_1);
+ mailQueueFactory.getQueue(NAME_1);
+
+ assertThat(mailQueueFactory.getUsedMailQueues())
+ .extracting(MailQueue::getMailQueueName)
+ .containsOnly(NAME_1);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java b/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
index 440ba3c..a65f9b7 100644
--- a/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
+++ b/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
@@ -20,6 +20,7 @@ package org.apache.james.queue.file;
import java.io.IOException;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.inject.Inject;
@@ -29,6 +30,8 @@ import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueueFactory;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
+import com.google.common.collect.ImmutableList;
+
/**
* {@link MailQueueFactory} implementation which returns {@link FileMailQueue} instances
*/
@@ -45,6 +48,11 @@ public class FileMailQueueFactory implements MailQueueFactory {
this.mailQueueActionItemDecoratorFactory = mailQueueItemDecoratorFactory;
}
+ @Override
+ public List<MailQueue> getUsedMailQueues() {
+ return ImmutableList.copyOf(queues.values());
+ }
+
/**
* If <code>true</code> the later created {@link FileMailQueue} will call <code>fsync</code> after each message {@link FileMailQueue#enQueue(org.apache.mailet.Mail)} call. This
* is needed to be fully RFC conform but gives a performance penalty. If you are brave enough you man set it to <code>false</code>
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-file/src/test/java/org/apache/james/queue/file/FileMailQueueFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-file/src/test/java/org/apache/james/queue/file/FileMailQueueFactoryTest.java b/server/queue/queue-file/src/test/java/org/apache/james/queue/file/FileMailQueueFactoryTest.java
new file mode 100644
index 0000000..a6e5c0d
--- /dev/null
+++ b/server/queue/queue-file/src/test/java/org/apache/james/queue/file/FileMailQueueFactoryTest.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.queue.file;
+
+import org.apache.james.filesystem.api.mock.MockFileSystem;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.MailQueueFactoryContract;
+import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+
+public class FileMailQueueFactoryTest implements MailQueueFactoryContract {
+ private FileMailQueueFactory mailQueueFactory;
+ private MockFileSystem fileSystem;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ fileSystem = new MockFileSystem();
+ mailQueueFactory = new FileMailQueueFactory(fileSystem, new RawMailQueueItemDecoratorFactory());
+ }
+
+ @AfterEach
+ void teardown() {
+ fileSystem.clear();
+ }
+
+ @Override
+ public MailQueueFactory getMailQueueFactory() {
+ return mailQueueFactory;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-jms/src/main/java/org/apache/james/queue/library/AbstractMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/library/AbstractMailQueueFactory.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/library/AbstractMailQueueFactory.java
index 6d91b95..3e93292 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/library/AbstractMailQueueFactory.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/library/AbstractMailQueueFactory.java
@@ -38,6 +38,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
/**
* {@link MailQueueFactory} abstract base class which take care of register the
@@ -67,6 +68,11 @@ public abstract class AbstractMailQueueFactory implements MailQueueFactory {
mbeanServer = ManagementFactory.getPlatformMBeanServer();
}
+ @Override
+ public List<MailQueue> getUsedMailQueues() {
+ return ImmutableList.copyOf(queues.values());
+ }
+
@PreDestroy
public synchronized void destroy() {
for (String mbean : mbeans) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/JMSMailQueueFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/JMSMailQueueFactoryTest.java b/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/JMSMailQueueFactoryTest.java
new file mode 100644
index 0000000..98b9ac1
--- /dev/null
+++ b/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/JMSMailQueueFactoryTest.java
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.queue.jms;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.MailQueueFactoryContract;
+import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+
+@ExtendWith(BrokerExtension.class)
+public class JMSMailQueueFactoryTest implements MailQueueFactoryContract {
+
+ private JMSMailQueueFactory mailQueueFactory;
+
+ @BeforeEach
+ public void setUp(BrokerService broker) throws Exception {
+ ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false");
+ RawMailQueueItemDecoratorFactory mailQueueItemDecoratorFactory = new RawMailQueueItemDecoratorFactory();
+ NoopMetricFactory metricFactory = new NoopMetricFactory();
+ mailQueueFactory = new JMSMailQueueFactory(connectionFactory, mailQueueItemDecoratorFactory, metricFactory);
+ mailQueueFactory.setUseJMX(false);
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ mailQueueFactory.destroy();
+ }
+
+ @Override
+ public MailQueueFactory getMailQueueFactory() {
+ return mailQueueFactory;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-memory/src/main/java/org/apache/james/queue/memory/MemoryMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-memory/src/main/java/org/apache/james/queue/memory/MemoryMailQueueFactory.java b/server/queue/queue-memory/src/main/java/org/apache/james/queue/memory/MemoryMailQueueFactory.java
index 95266d5..b72a02d 100644
--- a/server/queue/queue-memory/src/main/java/org/apache/james/queue/memory/MemoryMailQueueFactory.java
+++ b/server/queue/queue-memory/src/main/java/org/apache/james/queue/memory/MemoryMailQueueFactory.java
@@ -20,6 +20,7 @@
package org.apache.james.queue.memory;
import java.util.Iterator;
+import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
@@ -56,6 +57,11 @@ public class MemoryMailQueueFactory implements MailQueueFactory {
}
@Override
+ public List<MailQueue> getUsedMailQueues() {
+ return ImmutableList.copyOf(mailQueues.values());
+ }
+
+ @Override
public MailQueue getQueue(String name) {
return Optional.ofNullable(mailQueues.get(name))
.orElseGet(() -> tryInsertNewMailQueue(name));
http://git-wip-us.apache.org/repos/asf/james-project/blob/7fa66076/server/queue/queue-memory/src/test/java/org/apache/james/queue/memory/MemoryMailQueueFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-memory/src/test/java/org/apache/james/queue/memory/MemoryMailQueueFactoryTest.java b/server/queue/queue-memory/src/test/java/org/apache/james/queue/memory/MemoryMailQueueFactoryTest.java
index e4fa1e3..f9a3ca3 100644
--- a/server/queue/queue-memory/src/test/java/org/apache/james/queue/memory/MemoryMailQueueFactoryTest.java
+++ b/server/queue/queue-memory/src/test/java/org/apache/james/queue/memory/MemoryMailQueueFactoryTest.java
@@ -21,11 +21,13 @@ package org.apache.james.queue.memory;
import static org.assertj.core.api.Assertions.assertThat;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.MailQueueFactoryContract;
import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class MemoryMailQueueFactoryTest {
+public class MemoryMailQueueFactoryTest implements MailQueueFactoryContract {
private static final String KEY = "key";
private static final String BIS = "keyBis";
@@ -51,4 +53,9 @@ public class MemoryMailQueueFactoryTest {
public void getQueueShouldNotReturnTheSameQueueForTwoDifferentNames() {
assertThat(memoryMailQueueFactory.getQueue(KEY)).isNotEqualTo(memoryMailQueueFactory.getQueue(BIS));
}
+
+ @Override
+ public MailQueueFactory getMailQueueFactory() {
+ return memoryMailQueueFactory;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org