Repository: james-project Updated Branches: refs/heads/master ef7c00f2a -> 95ef65170
http://git-wip-us.apache.org/repos/asf/james-project/blob/46c2a279/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/DistantMailboxPathRegisterTest.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/DistantMailboxPathRegisterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/DistantMailboxPathRegisterTest.java deleted file mode 100644 index 195d63a..0000000 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/DistantMailboxPathRegisterTest.java +++ /dev/null @@ -1,345 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mailbox.store.event.distributed; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.model.MailboxPath; -import org.apache.james.mailbox.store.publisher.Topic; -import org.junit.Before; -import org.junit.Test; - -import com.google.common.collect.Sets; - -public class DistantMailboxPathRegisterTest { - - private static final MailboxPath MAILBOX_PATH = new MailboxPath("namespace", "user", "name"); - private static final MailboxPath NEW_MAILBOX_PATH = new MailboxPath("namespace_new", "user_new", "name_new"); - private static final String TOPIC = "topic"; - - private DistantMailboxPathRegisterMapper mockedMapper; - private DistantMailboxPathRegister register; - - @Before - public void setUp() { - mockedMapper = mock(DistantMailboxPathRegisterMapper.class); - register = new DistantMailboxPathRegister(mockedMapper, 1); - } - - @Test(expected = MailboxException.class) - public void doRenameShouldThrowIfTryingToRenameNonExistingPath() throws Exception { - register.doRename(MAILBOX_PATH, NEW_MAILBOX_PATH); - verifyNoMoreInteractions(mockedMapper); - } - - @Test - public void getTopicsShouldWork() { - final Set<Topic> result = Sets.newHashSet(new Topic(TOPIC)); - when(mockedMapper.getTopics(MAILBOX_PATH)).thenReturn(result); - assertThat(register.getTopics(MAILBOX_PATH)).isEqualTo(result); - } - - @Test - public void registerShouldWork() throws MailboxException { - register.register(MAILBOX_PATH); - verify(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - verifyNoMoreInteractions(mockedMapper); - } - - @Test - public void registerShouldCallMapperOnce() throws MailboxException { - register.register(MAILBOX_PATH); - verify(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - register.register(MAILBOX_PATH); - verifyNoMoreInteractions(mockedMapper); - } - - @Test - public void unregisterShouldWork() throws MailboxException { - register.register(MAILBOX_PATH); - verify(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - register.unregister(MAILBOX_PATH); - verify(mockedMapper).doUnRegister(MAILBOX_PATH, register.getLocalTopic()); - verifyNoMoreInteractions(mockedMapper); - } - - - @Test - public void unregisterShouldNotCallMapperIfListenersAreStillPresent() throws MailboxException { - register.register(MAILBOX_PATH); - verify(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - register.register(MAILBOX_PATH); - register.unregister(MAILBOX_PATH); - verifyNoMoreInteractions(mockedMapper); - verifyNoMoreInteractions(mockedMapper); - } - - @Test - public void unregisterShouldWorkWhenMultipleListenersWereRegistered() throws MailboxException { - register.register(MAILBOX_PATH); - verify(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - register.register(MAILBOX_PATH); - register.unregister(MAILBOX_PATH); - verifyNoMoreInteractions(mockedMapper); - register.unregister(MAILBOX_PATH); - verify(mockedMapper).doUnRegister(MAILBOX_PATH, register.getLocalTopic()); - verifyNoMoreInteractions(mockedMapper); - } - - @Test - public void doRenameShouldWork() throws Exception { - register.register(MAILBOX_PATH); - verify(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - register.doRename(MAILBOX_PATH, NEW_MAILBOX_PATH); - verify(mockedMapper).doRegister(NEW_MAILBOX_PATH, register.getLocalTopic()); - verify(mockedMapper).doUnRegister(MAILBOX_PATH, register.getLocalTopic()); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(NEW_MAILBOX_PATH, 1L); - verifyNoMoreInteractions(mockedMapper); - } - - @Test - public void doRenameShouldWorkWhenEntryAlreadyExists() throws Exception { - register.register(MAILBOX_PATH); - verify(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - register.register(NEW_MAILBOX_PATH); - verify(mockedMapper).doRegister(NEW_MAILBOX_PATH, register.getLocalTopic()); - register.doRename(MAILBOX_PATH, NEW_MAILBOX_PATH); - verify(mockedMapper).doUnRegister(MAILBOX_PATH, register.getLocalTopic()); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(NEW_MAILBOX_PATH, 2L); - verifyNoMoreInteractions(mockedMapper); - } - - @Test - public void mapShouldBeEmptyInitially() { - assertThat(register.getRegisteredMailboxPathCount()).isEmpty(); - } - - @Test - public void mapShouldContainOneListenerOnPathAfterRegister() throws MailboxException { - register.register(MAILBOX_PATH); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(MAILBOX_PATH, 1L); - } - - @Test - public void mapShouldContainTwoListenerOnPathAfterTwoRegister() throws MailboxException { - register.register(MAILBOX_PATH); - register.register(MAILBOX_PATH); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(MAILBOX_PATH, 2L); - } - - @Test - public void mapListenerCountShouldBeOkAfterTwoRegisterAndOneUnregister() throws MailboxException { - register.register(MAILBOX_PATH); - register.register(MAILBOX_PATH); - register.unregister(MAILBOX_PATH); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(MAILBOX_PATH, 1L); - } - - @Test - public void mapListenerCountShouldBeEmptyAfterTwoRegisterAndOneUnregister() throws MailboxException { - register.register(MAILBOX_PATH); - register.unregister(MAILBOX_PATH); - assertThat(register.getRegisteredMailboxPathCount()).isEmpty(); - } - - @Test - public void mapListenerCountShouldBeEmptyAfterDoCompleteUnregister() throws MailboxException { - register.register(MAILBOX_PATH); - register.doCompleteUnRegister(MAILBOX_PATH); - assertThat(register.getRegisteredMailboxPathCount()).isEmpty(); - } - - @Test - public void mapListenerCountShouldHandleRename() throws Exception { - register.register(MAILBOX_PATH); - register.doRename(MAILBOX_PATH, NEW_MAILBOX_PATH); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(NEW_MAILBOX_PATH, 1L); - } - - @Test - public void mapListenerCountShouldHandleRenameWhenEntryAlreadyExists() throws Exception { - register.register(MAILBOX_PATH); - register.register(NEW_MAILBOX_PATH); - register.doRename(MAILBOX_PATH, NEW_MAILBOX_PATH); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(NEW_MAILBOX_PATH, 2L); - } - - @Test - public void registerShouldNotBeAffectedByMapperError() throws MailboxException { - doThrow(new RuntimeException()).when(mockedMapper).doRegister(MAILBOX_PATH, register.getLocalTopic()); - try { - register.register(MAILBOX_PATH); - fail("Register should have thrown"); - } catch (RuntimeException e) { - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(MAILBOX_PATH, 1L); - } - } - - @Test - public void unregisterShouldNotBeAffectedByMapperErrors() throws MailboxException { - register.register(MAILBOX_PATH); - doThrow(new RuntimeException()).when(mockedMapper).doUnRegister(MAILBOX_PATH, register.getLocalTopic()); - try { - register.unregister(MAILBOX_PATH); - fail("Register should have thrown"); - } catch (RuntimeException e) { - assertThat(register.getRegisteredMailboxPathCount()).isEmpty(); - } - } - - @Test - public void renameShouldNotBeAffectedByMapperErrors() throws MailboxException { - register.register(MAILBOX_PATH); - doThrow(new RuntimeException()).when(mockedMapper).doRegister(NEW_MAILBOX_PATH, register.getLocalTopic()); - try { - register.doRename(MAILBOX_PATH, NEW_MAILBOX_PATH); - fail("Register should have thrown"); - } catch (RuntimeException e) { - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(NEW_MAILBOX_PATH, 1L) - .doesNotContainKey(MAILBOX_PATH); - } - } - - @Test - public void completeUnregisterShouldNotBeAffectedByMapperErrors() throws MailboxException { - register.register(MAILBOX_PATH); - doThrow(new RuntimeException()).when(mockedMapper).doUnRegister(MAILBOX_PATH, register.getLocalTopic()); - try { - register.doCompleteUnRegister(MAILBOX_PATH); - fail("Register should have thrown"); - } catch (RuntimeException e) { - assertThat(register.getRegisteredMailboxPathCount()).isEmpty(); - } - } - - @Test - public void registerShouldWorkInAConcurrentEnvironment() throws Exception { - int numTask = 2; - final long increments = 100; - ExecutorService executorService = Executors.newFixedThreadPool(numTask); - for (int i = 0; i < numTask; i++) { - executorService.submit(() -> { - try { - int j = 0; - while (j < increments) { - register.register(MAILBOX_PATH); - j++; - } - } catch (Exception e) { - fail("Exception caught in thread", e); - } - }); - } - executorService.shutdown(); - executorService.awaitTermination(10, TimeUnit.SECONDS); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(MAILBOX_PATH, numTask * increments); - } - - @Test - public void unregisterShouldWorkInAConcurrentEnvironment() throws Exception { - int numTask = 2; - final long increments = 100; - for (int i = 0; i < numTask * increments; i++) { - register.register(MAILBOX_PATH); - } - ExecutorService executorService = Executors.newFixedThreadPool(numTask); - for (int i = 0; i < numTask; i++) { - executorService.submit(() -> { - try { - int j = 0; - while (j < increments) { - register.unregister(MAILBOX_PATH); - j++; - } - } catch (Exception e) { - fail("Exception caught in thread", e); - } - }); - } - executorService.shutdown(); - executorService.awaitTermination(10, TimeUnit.SECONDS); - assertThat(register.getRegisteredMailboxPathCount()).isEmpty(); - } - - @Test - public void unregisterMixedWithRegisterShouldWorkInAConcurrentEnvironment() throws Exception { - int numTask = 2; - final long increments = 100; - for (int i = 0; i < increments; i++) { - register.register(MAILBOX_PATH); - } - ExecutorService executorService = Executors.newFixedThreadPool(2 * numTask); - for (int i = 0; i < numTask; i++) { - executorService.submit(() -> { - try { - int j = 0; - while (j < increments) { - register.register(MAILBOX_PATH); - j++; - } - } catch (Exception e) { - fail("Exception caught in thread", e); - } - }); - executorService.submit(() -> { - try { - int j = 0; - while (j < increments) { - register.unregister(MAILBOX_PATH); - j++; - } - } catch (Exception e) { - fail("Exception caught in thread", e); - } - }); - } - executorService.shutdown(); - executorService.awaitTermination(10, TimeUnit.SECONDS); - assertThat(register.getRegisteredMailboxPathCount()).containsEntry(MAILBOX_PATH, increments); - } - - @Test - public void schedulerShouldWork() throws Exception { - register.register(MAILBOX_PATH); - try { - register.init(); - Thread.sleep(1050); - - } finally { - register.destroy(); - } - verify(mockedMapper, times(3)).doRegister(MAILBOX_PATH, register.getLocalTopic()); - verifyNoMoreInteractions(mockedMapper); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/46c2a279/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/PublisherReceiver.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/PublisherReceiver.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/PublisherReceiver.java deleted file mode 100644 index d6a03f4..0000000 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/PublisherReceiver.java +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mailbox.store.event.distributed; - -import org.apache.james.mailbox.store.publisher.MessageConsumer; -import org.apache.james.mailbox.store.publisher.MessageReceiver; -import org.apache.james.mailbox.store.publisher.Publisher; -import org.apache.james.mailbox.store.publisher.Topic; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - -public class PublisherReceiver implements Publisher, MessageConsumer { - - private final Multimap<Topic, MessageReceiver> messageReceiverMultimap; - // Test code is mutable. Agree, this is not nice, but quite convenient . MessageConsumer is designed to handle only one message receiver. - // Here we want to emulate a complete event systems, across multiple servers... - private MessageReceiver messageReceiver; - - public PublisherReceiver() { - this.messageReceiverMultimap = HashMultimap.create(); - } - - @Override - public void close() { - - } - - @Override - public void publish(Topic topic, byte[] message) { - for (MessageReceiver messageReceiver : messageReceiverMultimap.get(topic)) { - messageReceiver.receiveSerializedEvent(message); - } - } - - @Override - public void init() { - - } - - @Override - public void setMessageReceiver(MessageReceiver messageReceiver) { - this.messageReceiver = messageReceiver; - } - - @Override - public void init(Topic topic) throws Exception { - messageReceiverMultimap.put(topic, messageReceiver); - } - - @Override - public void destroy() throws Exception { - - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/46c2a279/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java deleted file mode 100644 index b904e53..0000000 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mailbox.store.event.distributed; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import java.util.Optional; - -import org.apache.james.core.quota.QuotaCount; -import org.apache.james.core.quota.QuotaSize; -import org.apache.james.mailbox.MailboxListener; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.mock.MockMailboxSession; -import org.apache.james.mailbox.model.MailboxPath; -import org.apache.james.mailbox.model.QuotaRoot; -import org.apache.james.mailbox.store.event.EventSerializer; -import org.apache.james.mailbox.store.publisher.MessageConsumer; -import org.apache.james.mailbox.store.publisher.Publisher; -import org.apache.james.mailbox.store.publisher.Topic; -import org.apache.james.mailbox.util.EventCollector; -import org.junit.Before; -import org.junit.Test; - -import com.google.common.collect.Sets; - -public class RegisteredDelegatingMailboxListenerTest { - - private static final MailboxPath MAILBOX_PATH = new MailboxPath("namespace", "user", "name"); - private static final MailboxPath MAILBOX_PATH_NEW = new MailboxPath("namespace_new", "user_new", "name_new"); - private static final Topic TOPIC = new Topic("topic"); - private static final Topic TOPIC_2 = new Topic("topic_2"); - private static final byte[] BYTES = new byte[0]; - - private RegisteredDelegatingMailboxListener testee; - private MailboxPathRegister mockedMailboxPathRegister; - private EventSerializer mockedEventSerializer; - private Publisher mockedPublisher; - private EventCollector mailboxEventCollector; - private EventCollector eachEventCollector; - private EventCollector onceEventCollector; - private MailboxSession mailboxSession; - private MailboxListener.MailboxEvent event; - - @Before - public void setUp() throws Exception { - mailboxSession = new MockMailboxSession("benwa"); - event = new MailboxListener.MailboxEvent(mailboxSession, MAILBOX_PATH) {}; - - mockedEventSerializer = mock(EventSerializer.class); - mockedPublisher = mock(Publisher.class); - mockedMailboxPathRegister = mock(MailboxPathRegister.class); - MessageConsumer messageConsumer = mock(MessageConsumer.class); - testee = new RegisteredDelegatingMailboxListener(mockedEventSerializer, mockedPublisher, messageConsumer, mockedMailboxPathRegister); - mailboxEventCollector = new EventCollector(MailboxListener.ListenerType.MAILBOX); - eachEventCollector = new EventCollector(MailboxListener.ListenerType.EACH_NODE); - onceEventCollector = new EventCollector(MailboxListener.ListenerType.ONCE); - } - - @Test - public void eventShouldBeLocallyDeliveredIfThereIsNoOtherRegisteredServers() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxEventCollector, mailboxSession); - verify(mockedMailboxPathRegister).register(MAILBOX_PATH); - when(mockedMailboxPathRegister.getTopics(MAILBOX_PATH)).thenReturn(Sets.newHashSet(TOPIC)); - when(mockedMailboxPathRegister.getLocalTopic()).thenReturn(TOPIC); - testee.event(event); - assertThat(mailboxEventCollector.getEvents()).containsOnly(event); - verify(mockedMailboxPathRegister, times(2)).getLocalTopic(); - verify(mockedMailboxPathRegister).getTopics(MAILBOX_PATH); - verifyNoMoreInteractions(mockedEventSerializer); - verifyNoMoreInteractions(mockedPublisher); - verifyNoMoreInteractions(mockedMailboxPathRegister); - } - - @Test - public void eventShouldBeRemotelySent() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxEventCollector, mailboxSession); - verify(mockedMailboxPathRegister).register(MAILBOX_PATH); - when(mockedMailboxPathRegister.getTopics(MAILBOX_PATH)).thenReturn(Sets.newHashSet(TOPIC, TOPIC_2)); - when(mockedMailboxPathRegister.getLocalTopic()).thenReturn(TOPIC); - when(mockedEventSerializer.serializeEvent(event)).thenReturn(BYTES); - testee.event(event); - assertThat(mailboxEventCollector.getEvents()).containsOnly(event); - verify(mockedMailboxPathRegister, times(2)).getLocalTopic(); - verify(mockedMailboxPathRegister).getTopics(MAILBOX_PATH); - verify(mockedEventSerializer).serializeEvent(event); - verify(mockedPublisher).publish(TOPIC_2, BYTES); - verifyNoMoreInteractions(mockedEventSerializer); - verifyNoMoreInteractions(mockedPublisher); - verifyNoMoreInteractions(mockedMailboxPathRegister); - } - - @Test - public void onceListenersShouldBeTriggered() throws Exception { - MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(mailboxSession, MAILBOX_PATH) {}; - testee.addGlobalListener(onceEventCollector, mailboxSession); - when(mockedMailboxPathRegister.getTopics(MAILBOX_PATH)).thenReturn(Sets.newHashSet(TOPIC)); - when(mockedMailboxPathRegister.getLocalTopic()).thenReturn(TOPIC); - testee.event(event); - assertThat(onceEventCollector.getEvents()).containsOnly(event); - verify(mockedMailboxPathRegister, times(2)).getLocalTopic(); - verify(mockedMailboxPathRegister).getTopics(MAILBOX_PATH); - verifyNoMoreInteractions(mockedEventSerializer); - verifyNoMoreInteractions(mockedPublisher); - verifyNoMoreInteractions(mockedMailboxPathRegister); - } - - @Test(expected = MailboxException.class) - public void eachNodeListenersShouldBeRejected() throws Exception { - testee.addGlobalListener(eachEventCollector, mailboxSession); - } - - @Test - public void distantEventShouldBeLocallyDelivered() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxEventCollector, mailboxSession); - verify(mockedMailboxPathRegister).register(MAILBOX_PATH); - when(mockedEventSerializer.deSerializeEvent(BYTES)).thenReturn(event); - testee.receiveSerializedEvent(BYTES); - assertThat(mailboxEventCollector.getEvents()).containsOnly(event); - verify(mockedMailboxPathRegister).getLocalTopic(); - verify(mockedEventSerializer).deSerializeEvent(BYTES); - verifyNoMoreInteractions(mockedEventSerializer); - verifyNoMoreInteractions(mockedPublisher); - verifyNoMoreInteractions(mockedMailboxPathRegister); - } - - - @Test - public void distantEventShouldNotBeDeliveredToOnceGlobalListeners() throws Exception { - testee.addGlobalListener(onceEventCollector, mailboxSession); - when(mockedEventSerializer.deSerializeEvent(BYTES)).thenReturn(event); - testee.receiveSerializedEvent(BYTES); - assertThat(onceEventCollector.getEvents()).isEmpty(); - verify(mockedMailboxPathRegister).getLocalTopic(); - verify(mockedEventSerializer).deSerializeEvent(BYTES); - verifyNoMoreInteractions(mockedEventSerializer); - verifyNoMoreInteractions(mockedPublisher); - verifyNoMoreInteractions(mockedMailboxPathRegister); - } - - @Test - public void deletionEventsShouldBeWellHandled() throws Exception { - QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty()); - QuotaCount quotaCount = QuotaCount.count(123); - QuotaSize quotaSize = QuotaSize.size(456); - MailboxListener.MailboxEvent event = new MailboxListener.MailboxDeletion(mailboxSession, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize); - testee.addListener(MAILBOX_PATH, mailboxEventCollector, mailboxSession); - verify(mockedMailboxPathRegister).register(MAILBOX_PATH); - when(mockedMailboxPathRegister.getTopics(MAILBOX_PATH)).thenReturn(Sets.newHashSet(TOPIC, TOPIC_2)); - when(mockedMailboxPathRegister.getLocalTopic()).thenReturn(TOPIC); - when(mockedEventSerializer.serializeEvent(event)).thenReturn(BYTES); - testee.event(event); - assertThat(mailboxEventCollector.getEvents()).containsOnly(event); - verify(mockedMailboxPathRegister, times(2)).getLocalTopic(); - verify(mockedMailboxPathRegister).getTopics(MAILBOX_PATH); - verify(mockedMailboxPathRegister).doCompleteUnRegister(MAILBOX_PATH); - verify(mockedEventSerializer).serializeEvent(event); - verify(mockedPublisher).publish(TOPIC_2, BYTES); - verifyNoMoreInteractions(mockedEventSerializer); - verifyNoMoreInteractions(mockedPublisher); - verifyNoMoreInteractions(mockedMailboxPathRegister); - } - - @Test - public void renameEventsShouldBeWellHandled() throws Exception { - MailboxListener.MailboxEvent event = new MailboxListener.MailboxRenamed(mailboxSession, MAILBOX_PATH) { - @Override - public MailboxPath getNewPath() { - return MAILBOX_PATH_NEW; - } - }; - testee.addListener(MAILBOX_PATH, mailboxEventCollector, mailboxSession); - verify(mockedMailboxPathRegister).register(MAILBOX_PATH); - when(mockedMailboxPathRegister.getTopics(MAILBOX_PATH)).thenReturn(Sets.newHashSet(TOPIC, TOPIC_2)); - when(mockedMailboxPathRegister.getLocalTopic()).thenReturn(TOPIC); - when(mockedEventSerializer.serializeEvent(event)).thenReturn(BYTES); - testee.event(event); - assertThat(mailboxEventCollector.getEvents()).containsOnly(event); - verify(mockedMailboxPathRegister, times(2)).getLocalTopic(); - verify(mockedMailboxPathRegister).getTopics(MAILBOX_PATH); - verify(mockedMailboxPathRegister).doRename(MAILBOX_PATH, MAILBOX_PATH_NEW); - verify(mockedEventSerializer).serializeEvent(event); - verify(mockedPublisher).publish(TOPIC_2, BYTES); - verifyNoMoreInteractions(mockedEventSerializer); - verifyNoMoreInteractions(mockedPublisher); - verifyNoMoreInteractions(mockedMailboxPathRegister); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
