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 d5023dad59d450cc06d2d4b4b343bb56ef52bdd7 Author: Benoit Tellier <[email protected]> AuthorDate: Sun Apr 12 11:25:14 2020 +0700 [REFACTORING] CassandraMessageDAO::retrieveAllMessageIdAttachmentIds is no longer called by production code Since we required a Cassandra schema version of 5, the task to populate attachmentId -> messages no longer exist. --- .../cassandra/mail/CassandraMessageDAO.java | 73 +--------- .../cassandra/mail/CassandraMessageDAOTest.java | 154 --------------------- 2 files changed, 1 insertion(+), 226 deletions(-) diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java index 58e25e3..63b617a 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java @@ -44,9 +44,7 @@ import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.T import java.io.IOException; import java.util.List; -import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -69,7 +67,6 @@ import org.apache.james.mailbox.model.Cid; import org.apache.james.mailbox.model.ComposedMessageId; import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData; import org.apache.james.mailbox.model.MessageAttachment; -import org.apache.james.mailbox.model.MessageId; import org.apache.james.mailbox.store.mail.MessageMapper.FetchType; import org.apache.james.mailbox.store.mail.model.MailboxMessage; import org.apache.james.mailbox.store.mail.model.Property; @@ -84,13 +81,9 @@ import com.datastax.driver.core.UDTValue; import com.datastax.driver.core.querybuilder.QueryBuilder; import com.github.steveash.guavate.Guavate; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Bytes; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.util.function.Tuple2; @@ -173,8 +166,7 @@ public class CassandraMessageDAO { public Mono<Void> save(MailboxMessage message) throws MailboxException { return saveContent(message) - .flatMap(pair -> cassandraAsyncExecutor.executeVoid(boundWriteStatement(message, pair))) - .then(); + .flatMap(pair -> cassandraAsyncExecutor.executeVoid(boundWriteStatement(message, pair))); } private Mono<Tuple2<BlobId, BlobId>> saveContent(MailboxMessage message) throws MailboxException { @@ -362,67 +354,4 @@ public class CassandraMessageDAO { private Mono<byte[]> getFieldContent(String field, Row row) { return Mono.from(blobStore.readBytes(blobStore.getDefaultBucketName(), blobIdFactory.from(row.getString(field)))); } - - public Flux<MessageIdAttachmentIds> retrieveAllMessageIdAttachmentIds() { - return cassandraAsyncExecutor.executeRows( - selectAllMessagesWithAttachment.bind() - .setReadTimeoutMillis(configuration.getMessageAttachmentIdsReadTimeout())) - .map(this::fromRow) - .filter(MessageIdAttachmentIds::hasAttachment); - } - - private MessageIdAttachmentIds fromRow(Row row) { - MessageId messageId = messageIdFactory.of(row.getUUID(MESSAGE_ID)); - Set<AttachmentId> attachmentIds = attachmentByIds(row.getList(ATTACHMENTS, UDTValue.class)) - .map(MessageAttachmentRepresentation::getAttachmentId) - .collect(Guavate.toImmutableSet()); - return new MessageIdAttachmentIds(messageId, attachmentIds); - } - - public static class MessageIdAttachmentIds { - private final MessageId messageId; - private final Set<AttachmentId> attachmentIds; - - public MessageIdAttachmentIds(MessageId messageId, Set<AttachmentId> attachmentIds) { - Preconditions.checkNotNull(messageId); - Preconditions.checkNotNull(attachmentIds); - this.messageId = messageId; - this.attachmentIds = ImmutableSet.copyOf(attachmentIds); - } - - public MessageId getMessageId() { - return messageId; - } - - public Set<AttachmentId> getAttachmentId() { - return attachmentIds; - } - - public boolean hasAttachment() { - return ! attachmentIds.isEmpty(); - } - - @Override - public final boolean equals(Object o) { - if (o instanceof MessageIdAttachmentIds) { - MessageIdAttachmentIds other = (MessageIdAttachmentIds) o; - return Objects.equals(messageId, other.messageId) - && Objects.equals(attachmentIds, other.attachmentIds); - } - return false; - } - - @Override - public final int hashCode() { - return Objects.hash(messageId, attachmentIds); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("messageId", messageId) - .add("attachmentIds", attachmentIds) - .toString(); - } - } } diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java index d7fe3da..e1ca868 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java @@ -19,14 +19,12 @@ package org.apache.james.mailbox.cassandra.mail; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Date; import java.util.List; -import java.util.stream.Stream; import javax.mail.Flags; import javax.mail.util.SharedByteArrayInputStream; @@ -43,9 +41,7 @@ import org.apache.james.mailbox.MessageUid; import org.apache.james.mailbox.ModSeq; import org.apache.james.mailbox.cassandra.ids.CassandraId; import org.apache.james.mailbox.cassandra.ids.CassandraMessageId; -import org.apache.james.mailbox.cassandra.mail.CassandraMessageDAO.MessageIdAttachmentIds; import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule; -import org.apache.james.mailbox.model.Attachment; import org.apache.james.mailbox.model.ComposedMessageId; import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData; import org.apache.james.mailbox.model.MessageAttachment; @@ -58,10 +54,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Bytes; -import nl.jqno.equalsverifier.EqualsVerifier; import reactor.core.publisher.Mono; class CassandraMessageDAOTest { @@ -192,152 +186,4 @@ class CassandraMessageDAOTest { return read.blockOptional() .orElseThrow(() -> new IllegalStateException("Collection is not supposed to be empty")); } - - @Test - void retrieveAllMessageIdAttachmentIdsShouldReturnEmptyWhenNone() { - Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().toStream(); - - assertThat(actual).isEmpty(); - } - - @Test - void retrieveAllMessageIdAttachmentIdsShouldReturnOneWhenStored() throws Exception { - //Given - MessageAttachment attachment = MessageAttachment.builder() - .attachment(Attachment.builder() - .bytes("content".getBytes(StandardCharsets.UTF_8)) - .type("type") - .build()) - .build(); - SimpleMailboxMessage message1 = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment)); - testee.save(message1).block(); - MessageIdAttachmentIds expected = new MessageIdAttachmentIds(messageId, ImmutableSet.of(attachment.getAttachmentId())); - - //When - Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().toStream(); - - //Then - assertThat(actual).containsOnly(expected); - } - - @Test - void retrieveAllMessageIdAttachmentIdsShouldReturnOneWhenStoredWithTwoAttachments() throws Exception { - //Given - MessageAttachment attachment1 = MessageAttachment.builder() - .attachment(Attachment.builder() - .bytes("content".getBytes(StandardCharsets.UTF_8)) - .type("type") - .build()) - .build(); - MessageAttachment attachment2 = MessageAttachment.builder() - .attachment(Attachment.builder() - .bytes("other content".getBytes(StandardCharsets.UTF_8)) - .type("type") - .build()) - .build(); - SimpleMailboxMessage message1 = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment1, attachment2)); - testee.save(message1).block(); - MessageIdAttachmentIds expected = new MessageIdAttachmentIds(messageId, ImmutableSet.of(attachment1.getAttachmentId(), attachment2.getAttachmentId())); - - //When - Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().toStream(); - - //Then - assertThat(actual).containsOnly(expected); - } - - @Test - void retrieveAllMessageIdAttachmentIdsShouldReturnAllWhenStoredWithAttachment() throws Exception { - //Given - MessageId messageId1 = messageIdFactory.generate(); - MessageId messageId2 = messageIdFactory.generate(); - MessageAttachment attachment1 = MessageAttachment.builder() - .attachment(Attachment.builder() - .bytes("content".getBytes(StandardCharsets.UTF_8)) - .type("type") - .build()) - .build(); - MessageAttachment attachment2 = MessageAttachment.builder() - .attachment(Attachment.builder() - .bytes("other content".getBytes(StandardCharsets.UTF_8)) - .type("type") - .build()) - .build(); - SimpleMailboxMessage message1 = createMessage(messageId1, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment1)); - SimpleMailboxMessage message2 = createMessage(messageId2, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment2)); - testee.save(message1).block(); - testee.save(message2).block(); - MessageIdAttachmentIds expected1 = new MessageIdAttachmentIds(messageId1, ImmutableSet.of(attachment1.getAttachmentId())); - MessageIdAttachmentIds expected2 = new MessageIdAttachmentIds(messageId2, ImmutableSet.of(attachment2.getAttachmentId())); - - //When - Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().toStream(); - - //Then - assertThat(actual).containsOnly(expected1, expected2); - } - - @Test - void retrieveAllMessageIdAttachmentIdsShouldReturnEmtpyWhenStoredWithoutAttachment() throws Exception { - //Given - SimpleMailboxMessage message1 = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); - testee.save(message1).block(); - - //When - Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().toStream(); - - //Then - assertThat(actual).isEmpty(); - } - - @Test - void retrieveAllMessageIdAttachmentIdsShouldFilterMessagesWithoutAttachment() throws Exception { - //Given - MessageId messageId1 = messageIdFactory.generate(); - MessageId messageId2 = messageIdFactory.generate(); - MessageId messageId3 = messageIdFactory.generate(); - MessageAttachment attachmentFor1 = MessageAttachment.builder() - .attachment(Attachment.builder() - .bytes("content".getBytes(StandardCharsets.UTF_8)) - .type("type") - .build()) - .build(); - MessageAttachment attachmentFor3 = MessageAttachment.builder() - .attachment(Attachment.builder() - .bytes("other content".getBytes(StandardCharsets.UTF_8)) - .type("type") - .build()) - .build(); - SimpleMailboxMessage message1 = createMessage(messageId1, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachmentFor1)); - SimpleMailboxMessage message2 = createMessage(messageId2, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); - SimpleMailboxMessage message3 = createMessage(messageId3, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachmentFor3)); - testee.save(message1).block(); - testee.save(message2).block(); - testee.save(message3).block(); - - //When - Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().toStream(); - - //Then - assertThat(actual).extracting(MessageIdAttachmentIds::getMessageId) - .containsOnly(messageId1, messageId3); - } - - @Test - void messageIdAttachmentIdsShouldMatchBeanContract() { - EqualsVerifier.forClass(MessageIdAttachmentIds.class) - .verify(); - } - - @Test - void messageIdAttachmentIdsShouldThrowOnNullMessageId() { - assertThatThrownBy(() -> new MessageIdAttachmentIds(null, ImmutableSet.of())) - .isInstanceOf(NullPointerException.class); - } - - @Test - void messageIdAttachmentIdsShouldThrowOnNullAttachmentIds() { - assertThatThrownBy(() -> new MessageIdAttachmentIds(messageIdFactory.generate(), null)) - .isInstanceOf(NullPointerException.class); - } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
