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 2019/12/06 02:34:27 UTC
[james-project] 17/21: JAMES-2991
MetaDataHoldingEvent::getMessageIds
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit c63f29e548dfb74158a6572e9c797d66b0c3dac8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Dec 2 18:09:47 2019 +0700
JAMES-2991 MetaDataHoldingEvent::getMessageIds
Allows writing unit in a clean fashion, without relying on "@VisibleForTesting"
---
.../james/mailbox/events/MailboxListener.java | 8 ++++
.../java/org/apache/james/mailbox/EventTest.java | 54 ++++++++++++++++++++++
.../ComputeMessageFastViewProjectionListener.java | 13 +-----
3 files changed, 63 insertions(+), 12 deletions(-)
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/events/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/events/MailboxListener.java
index 7c71968..e3614c2 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/events/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/events/MailboxListener.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.acl.ACLDiff;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.Quota;
import org.apache.james.mailbox.model.QuotaRoot;
@@ -44,6 +45,7 @@ import org.apache.james.mailbox.model.UpdatedFlags;
import com.github.steveash.guavate.Guavate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
/**
@@ -424,6 +426,12 @@ public interface MailboxListener {
*/
public abstract MessageMetaData getMetaData(MessageUid uid);
+ public ImmutableSet<MessageId> getMessageIds() {
+ return getUids()
+ .stream()
+ .map(uid -> getMetaData(uid).getMessageId())
+ .collect(Guavate.toImmutableSet());
+ }
}
class Expunged extends MetaDataHoldingEvent {
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/EventTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/EventTest.java
index 94530c6..6c1c687 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/EventTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/EventTest.java
@@ -21,15 +21,27 @@ package org.apache.james.mailbox;
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.Date;
import java.util.UUID;
+import javax.mail.Flags;
+
+import org.apache.james.core.Username;
import org.apache.james.mailbox.events.Event;
+import org.apache.james.mailbox.events.MailboxListener;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
import org.junit.jupiter.api.Test;
+import com.google.common.collect.ImmutableSortedMap;
+
import nl.jqno.equalsverifier.EqualsVerifier;
class EventTest {
private static final UUID UUID_1 = UUID.fromString("6e0dd59d-660e-4d9b-b22f-0354479f47b4");
+ public static final Username BOB = Username.of("BOB");
@Test
void eventIdShouldMatchBeanContract() {
@@ -41,4 +53,46 @@ class EventTest {
assertThat(Event.EventId.of(UUID_1.toString()))
.isEqualTo(Event.EventId.of(UUID_1));
}
+
+ @Test
+ void getMessageIdsShouldReturnEmptyWhenAddedEmpty() {
+ MailboxListener.Added added = new MailboxListener.Added(MailboxSession.SessionId.of(36), BOB, MailboxPath.inbox(BOB), TestId.of(48), ImmutableSortedMap.of(), Event.EventId.of(UUID_1));
+
+ assertThat(added.getMessageIds()).isEmpty();
+ }
+
+ @Test
+ void getMessageIdsShouldReturnDistinctValues() {
+ MessageUid uid1 = MessageUid.of(36);
+ MessageUid uid2 = MessageUid.of(37);
+ TestMessageId messageId1 = TestMessageId.of(45);
+ TestMessageId messageId2 = TestMessageId.of(46);
+ MessageMetaData metaData1 = new MessageMetaData(uid1, ModSeq.of(85), new Flags(), 36, new Date(), messageId1);
+ MessageMetaData metaData2 = new MessageMetaData(uid2, ModSeq.of(85), new Flags(), 36, new Date(), messageId2);
+
+ MailboxListener.Added added = new MailboxListener.Added(MailboxSession.SessionId.of(36), BOB, MailboxPath.inbox(BOB), TestId.of(48),
+ ImmutableSortedMap.of(
+ uid1, metaData1,
+ uid2, metaData2),
+ Event.EventId.of(UUID_1));
+
+ assertThat(added.getMessageIds()).containsOnly(messageId1, messageId2);
+ }
+
+ @Test
+ void getMessageIdsShouldNotReturnDuplicates() {
+ MessageUid uid1 = MessageUid.of(36);
+ MessageUid uid2 = MessageUid.of(37);
+ TestMessageId messageId = TestMessageId.of(45);
+ MessageMetaData metaData1 = new MessageMetaData(uid1, ModSeq.of(85), new Flags(), 36, new Date(), messageId);
+ MessageMetaData metaData2 = new MessageMetaData(uid2, ModSeq.of(85), new Flags(), 36, new Date(), messageId);
+
+ MailboxListener.Added added = new MailboxListener.Added(MailboxSession.SessionId.of(36), BOB, MailboxPath.inbox(BOB), TestId.of(48),
+ ImmutableSortedMap.of(
+ uid1, metaData1,
+ uid2, metaData2),
+ Event.EventId.of(UUID_1));
+
+ assertThat(added.getMessageIds()).containsExactly(messageId);
+ }
}
\ No newline at end of file
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListener.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListener.java
index 4db7a1c..9c7b2be 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListener.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListener.java
@@ -20,7 +20,6 @@
package org.apache.james.jmap.event;
import java.io.IOException;
-import java.util.List;
import javax.inject.Inject;
@@ -37,13 +36,11 @@ import org.apache.james.mailbox.events.Group;
import org.apache.james.mailbox.events.MailboxListener;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.FetchGroup;
-import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.store.SessionProvider;
import org.parboiled.common.ImmutableList;
import com.github.fge.lambdas.Throwing;
-import com.github.steveash.guavate.Guavate;
import com.google.common.annotations.VisibleForTesting;
import reactor.core.publisher.Flux;
@@ -85,7 +82,7 @@ public class ComputeMessageFastViewProjectionListener implements MailboxListener
}
private void handleAddedEvent(Added addedEvent, MailboxSession session) throws MailboxException {
- Flux.fromIterable(messageIdManager.getMessages(getEventMessageIds(addedEvent), FetchGroup.BODY_CONTENT, session))
+ Flux.fromIterable(messageIdManager.getMessages(addedEvent.getMessageIds().asList(), FetchGroup.BODY_CONTENT, session))
.publishOn(Schedulers.boundedElastic())
.map(Throwing.function(messageResult -> Pair.of(messageResult.getMessageId(), computeFastViewPrecomputedProperties(messageResult))))
.flatMap(message -> messageFastViewProjection.store(message.getKey(), message.getValue()))
@@ -93,14 +90,6 @@ public class ComputeMessageFastViewProjectionListener implements MailboxListener
.block();
}
- private List<MessageId> getEventMessageIds(Added addedEvent) {
- return addedEvent.getUids()
- .stream()
- .map(uid -> addedEvent.getMetaData(uid).getMessageId())
- .collect(Guavate.toImmutableSet())
- .asList();
- }
-
@VisibleForTesting
MessageFastViewPrecomputedProperties computeFastViewPrecomputedProperties(MessageResult messageResult) throws MailboxException, IOException {
MessageFullView message = messageFullViewFactory.fromMessageResults(ImmutableList.of(messageResult));
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org