Author: btellier
Date: Sat Nov 28 13:08:02 2015
New Revision: 1716965
URL: http://svn.apache.org/viewvc?rev=1716965&view=rev
Log:
Mailbox-211 Integration tests for Cassandra based registration event system
Added:
james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/event/distributed/CassandraBasedRegisteredDistributedMailboxDelegatingListenerTest.java
james/project/trunk/protocols/smtp/dependency-reduced-pom.xml
james/project/trunk/q
Added:
james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/event/distributed/CassandraBasedRegisteredDistributedMailboxDelegatingListenerTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/event/distributed/CassandraBasedRegisteredDistributedMailboxDelegatingListenerTest.java?rev=1716965&view=auto
==============================================================================
---
james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/event/distributed/CassandraBasedRegisteredDistributedMailboxDelegatingListenerTest.java
(added)
+++
james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/event/distributed/CassandraBasedRegisteredDistributedMailboxDelegatingListenerTest.java
Sat Nov 28 13:08:02 2015
@@ -0,0 +1,153 @@
+/****************************************************************
+ * 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.mailbox.cassandra.event.distributed;
+
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.cassandra.modules.CassandraRegistrationModule;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.TestId;
+import org.apache.james.mailbox.store.TestIdDeserializer;
+import org.apache.james.mailbox.store.event.EventFactory;
+import
org.apache.james.mailbox.store.event.distributed.DistantMailboxPathRegister;
+import org.apache.james.mailbox.store.event.distributed.PublisherReceiver;
+import
org.apache.james.mailbox.store.event.distributed.RegisteredDelegatingMailboxListener;
+import org.apache.james.mailbox.store.json.MessagePackEventSerializer;
+import org.apache.james.mailbox.store.json.event.EventConverter;
+import org.apache.james.mailbox.store.json.event.MailboxConverter;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.apache.james.mailbox.util.EventCollector;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.TreeMap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ Integration tests for RegisteredDelegatingMailboxListener using a cassandra
back-end.
+
+ We simulate communications using message queues in memory and check the
Listener works as intended.
+ */
+public class CassandraBasedRegisteredDistributedMailboxDelegatingListenerTest {
+
+ public static final MailboxPath MAILBOX_PATH_1 = new
MailboxPath("#private", "user", "mbx");
+ public static final MailboxPath MAILBOX_PATH_2 = new
MailboxPath("#private", "user", "mbx.other");
+ public static final int CASSANDRA_TIME_OUT_IN_S = 10;
+ public static final int SCHEDULER_PERIOD_IN_S = 20;
+
+ private CassandraCluster cassandraClusterSingleton =
CassandraCluster.create(new CassandraRegistrationModule());
+ private RegisteredDelegatingMailboxListener
registeredDelegatingMailboxListener1;
+ private RegisteredDelegatingMailboxListener
registeredDelegatingMailboxListener2;
+ private RegisteredDelegatingMailboxListener
registeredDelegatingMailboxListener3;
+ private EventCollector eventCollectorMailbox1;
+ private EventCollector eventCollectorMailbox2;
+ private EventCollector eventCollectorMailbox3;
+ private EventCollector eventCollectorOnce1;
+ private EventCollector eventCollectorOnce2;
+ private EventCollector eventCollectorOnce3;
+ private MailboxSession mailboxSession;
+
+ @Before
+ public void setUp() throws Exception {
+ PublisherReceiver publisherReceiver = new PublisherReceiver();
+ DistantMailboxPathRegister mailboxPathRegister1 = new
DistantMailboxPathRegister(
+ new CassandraMailboxPathRegisterMapper(
+ cassandraClusterSingleton.getConf(),
+ cassandraClusterSingleton.getTypesProvider(),
+ CASSANDRA_TIME_OUT_IN_S),
+ SCHEDULER_PERIOD_IN_S);
+ registeredDelegatingMailboxListener1 = new
RegisteredDelegatingMailboxListener(
+ new MessagePackEventSerializer<>(
+ new EventConverter<>(new MailboxConverter<>(new
TestIdDeserializer()))
+ ),
+ publisherReceiver,
+ publisherReceiver,
+ mailboxPathRegister1);
+ DistantMailboxPathRegister mailboxPathRegister2 = new
DistantMailboxPathRegister(
+ new CassandraMailboxPathRegisterMapper(
+ cassandraClusterSingleton.getConf(),
+ cassandraClusterSingleton.getTypesProvider(),
+ CASSANDRA_TIME_OUT_IN_S),
+ SCHEDULER_PERIOD_IN_S);
+ registeredDelegatingMailboxListener2 = new
RegisteredDelegatingMailboxListener(
+ new MessagePackEventSerializer<>(
+ new EventConverter<>(new MailboxConverter<>(new
TestIdDeserializer()))
+ ),
+ publisherReceiver,
+ publisherReceiver,
+ mailboxPathRegister2);
+ DistantMailboxPathRegister mailboxPathRegister3 = new
DistantMailboxPathRegister(
+ new CassandraMailboxPathRegisterMapper(
+ cassandraClusterSingleton.getConf(),
+ cassandraClusterSingleton.getTypesProvider(),
+ CASSANDRA_TIME_OUT_IN_S),
+ SCHEDULER_PERIOD_IN_S);
+ registeredDelegatingMailboxListener3 = new
RegisteredDelegatingMailboxListener(
+ new MessagePackEventSerializer<>(
+ new EventConverter<>(new MailboxConverter<>(new
TestIdDeserializer()))
+ ),
+ publisherReceiver,
+ publisherReceiver,
+ mailboxPathRegister3);
+ eventCollectorMailbox1 = new
EventCollector(MailboxListener.ListenerType.MAILBOX);
+ eventCollectorMailbox2 = new
EventCollector(MailboxListener.ListenerType.MAILBOX);
+ eventCollectorMailbox3 = new
EventCollector(MailboxListener.ListenerType.MAILBOX);
+ eventCollectorOnce1 = new
EventCollector(MailboxListener.ListenerType.ONCE);
+ eventCollectorOnce2 = new
EventCollector(MailboxListener.ListenerType.ONCE);
+ eventCollectorOnce3 = new
EventCollector(MailboxListener.ListenerType.ONCE);
+ mailboxSession = new MockMailboxSession("Test");
+
registeredDelegatingMailboxListener1.addGlobalListener(eventCollectorOnce1,
mailboxSession);
+
registeredDelegatingMailboxListener2.addGlobalListener(eventCollectorOnce2,
mailboxSession);
+
registeredDelegatingMailboxListener3.addGlobalListener(eventCollectorOnce3,
mailboxSession);
+ registeredDelegatingMailboxListener1.addListener(MAILBOX_PATH_1,
eventCollectorMailbox1, mailboxSession);
+ registeredDelegatingMailboxListener2.addListener(MAILBOX_PATH_1,
eventCollectorMailbox2, mailboxSession);
+ registeredDelegatingMailboxListener3.addListener(MAILBOX_PATH_2,
eventCollectorMailbox3, mailboxSession);
+ }
+
+ @Test
+ public void mailboxEventListenersShouldBeTriggeredIfRegistered() throws
Exception {
+ SimpleMailbox<TestId> simpleMailbox = new
SimpleMailbox<>(MAILBOX_PATH_1, 42);
+ simpleMailbox.setMailboxId(TestId.of(52));
+ final MailboxListener.Event event = new
EventFactory<TestId>().added(mailboxSession, new TreeMap<>(), simpleMailbox);
+
+ registeredDelegatingMailboxListener1.event(event);
+
+ assertThat(eventCollectorMailbox1.getEvents()).hasSize(1);
+ assertThat(eventCollectorMailbox2.getEvents()).hasSize(1);
+ assertThat(eventCollectorMailbox3.getEvents()).isEmpty();
+ }
+
+ @Test
+ public void onceEventListenersShouldBeTriggeredOnceAcrossTheCluster() {
+ SimpleMailbox<TestId> simpleMailbox = new
SimpleMailbox<>(MAILBOX_PATH_1, 42);
+ simpleMailbox.setMailboxId(TestId.of(52));
+ final MailboxListener.Event event = new
EventFactory<TestId>().added(mailboxSession, new TreeMap<>(), simpleMailbox);
+
+ registeredDelegatingMailboxListener1.event(event);
+
+ assertThat(eventCollectorOnce1.getEvents()).hasSize(1);
+ assertThat(eventCollectorOnce2.getEvents()).isEmpty();
+ assertThat(eventCollectorOnce3.getEvents()).isEmpty();
+ }
+
+}
Added: james/project/trunk/protocols/smtp/dependency-reduced-pom.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/protocols/smtp/dependency-reduced-pom.xml?rev=1716965&view=auto
==============================================================================
--- james/project/trunk/protocols/smtp/dependency-reduced-pom.xml (added)
+++ james/project/trunk/protocols/smtp/dependency-reduced-pom.xml Sat Nov 28
13:08:02 2015
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>protocols</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>1.6.4-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.james.protocols</groupId>
+ <artifactId>protocols-smtp</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache James :: Protocols :: SMTP</name>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <artifactSet>
+ <includes>
+ <include>commons-codec:commons-codec</include>
+ </includes>
+ </artifactSet>
+ <filters>
+ <filter>
+ <artifact>commons-codec:commons-codec</artifact>
+ <excludes>
+ <exclude>org/apache/commons/codec/*</exclude>
+ </excludes>
+ <includes>
+ <include>org/apache/commons/codec/binary/*</include>
+ </includes>
+ </filter>
+ </filters>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.commons.codec.binary</pattern>
+
<shadedPattern>org.apache.james.protocols.smtp.util</shadedPattern>
+ </relocation>
+ </relocations>
+ <transformers>
+ <transformer />
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.james.protocols</groupId>
+ <artifactId>protocols-api</artifactId>
+ <version>1.6.4-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>3.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james.protocols</groupId>
+ <artifactId>protocols-api</artifactId>
+ <version>1.6.4-SNAPSHOT</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james.protocols</groupId>
+ <artifactId>protocols-netty</artifactId>
+ <version>1.6.4-SNAPSHOT</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>netty</artifactId>
+ <groupId>io.netty</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>hamcrest-core</artifactId>
+ <groupId>org.hamcrest</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.javamail</groupId>
+ <artifactId>geronimo-javamail_1.4_mail</artifactId>
+ <version>1.8.3</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]