This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 52d55c59941ae3a1256a088009a6c1b9477ae6ca Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Tue Apr 7 11:34:31 2020 +0700 JAMES-3136 Failure tests for CassandraMessageIdMapper --- .../cassandra/mail/CassandraMessageIdMapper.java | 5 +- .../mail/CassandraMessageIdMapperTest.java | 132 +++++++++++++++++++++ .../store/mail/model/MessageIdMapperTest.java | 6 +- 3 files changed, 136 insertions(+), 7 deletions(-) diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java index 0eeca22..4d88c9a 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java @@ -127,9 +127,8 @@ public class CassandraMessageIdMapper implements MessageIdMapper { mailboxMapper.findMailboxById(mailboxId); ComposedMessageIdWithMetaData composedMessageIdWithMetaData = createMetadataFor(mailboxMessage); messageDAO.save(mailboxMessage) - .thenMany(Flux.merge( - imapUidDAO.insert(composedMessageIdWithMetaData), - messageIdDAO.insert(composedMessageIdWithMetaData))) + .thenEmpty(imapUidDAO.insert(composedMessageIdWithMetaData)) + .thenEmpty(messageIdDAO.insert(composedMessageIdWithMetaData)) .thenEmpty(indexTableHandler.updateIndexOnAdd(mailboxMessage, mailboxId)) .block(); } diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapperTest.java index 98ef169..582569a 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapperTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapperTest.java @@ -19,10 +19,13 @@ package org.apache.james.mailbox.cassandra.mail; +import static org.apache.james.backends.cassandra.Scenario.Builder.fail; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import java.util.Optional; +import org.apache.james.backends.cassandra.CassandraCluster; import org.apache.james.backends.cassandra.CassandraClusterExtension; import org.apache.james.backends.cassandra.init.configuration.CassandraConfiguration; import org.apache.james.core.Username; @@ -30,13 +33,18 @@ import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSessionUtil; import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory; import org.apache.james.mailbox.cassandra.TestCassandraMailboxSessionMapperFactory; +import org.apache.james.mailbox.cassandra.ids.CassandraId; import org.apache.james.mailbox.cassandra.ids.CassandraMessageId; +import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.store.mail.MessageMapper; import org.apache.james.mailbox.store.mail.model.MailboxMessage; import org.apache.james.mailbox.store.mail.model.MessageIdMapperTest; +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import com.github.fge.lambdas.Throwing; import com.google.common.collect.ImmutableList; class CassandraMessageIdMapperTest extends MessageIdMapperTest { @@ -73,4 +81,128 @@ class CassandraMessageIdMapperTest extends MessageIdMapperTest { assertThat(messages) .containsOnly(message1, message2, message3, message4); } + + @Nested + class FailureTest { + @Test + void retrieveMessagesShouldNotReturnMessagesWhenFailToPersistInMessageDAO(CassandraCluster cassandra) { + cassandra.getConf() + .registerScenario(fail() + .forever() + .whenQueryStartsWith("INSERT INTO messageV2 (messageId,internalDate,bodyStartOctet,fullContentOctets,bodyOctets,bodyContent,headerContent,properties,textualLineCount,attachments)")); + + try { + message1.setUid(mapperProvider.generateMessageUid()); + message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); + sut.save(message1); + } catch (Exception e) { + // ignoring expected error + } + + CassandraMessageIdDAO messageIdDAO = new CassandraMessageIdDAO(cassandra.getConf(), new CassandraMessageId.Factory()); + SoftAssertions.assertSoftly(Throwing.consumer(softly -> { + softly.assertThat(sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Metadata)) + .isEmpty(); + softly.assertThat(messageIdDAO.retrieveMessages((CassandraId) benwaInboxMailbox.getMailboxId(), MessageRange.all()).collectList().block()) + .isEmpty(); + })); + } + + @Test + void retrieveMessagesShouldNotReturnMessagesWhenFailsToPersistBlobParts(CassandraCluster cassandra) { + cassandra.getConf() + .registerScenario(fail() + .forever() + .whenQueryStartsWith("INSERT INTO blobParts (id,chunkNumber,data) VALUES (:id,:chunkNumber,:data);")); + + try { + message1.setUid(mapperProvider.generateMessageUid()); + message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); + sut.save(message1); + } catch (Exception e) { + // ignoring expected error + } + + CassandraMessageIdDAO messageIdDAO = new CassandraMessageIdDAO(cassandra.getConf(), new CassandraMessageId.Factory()); + SoftAssertions.assertSoftly(Throwing.consumer(softly -> { + softly.assertThat(sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Metadata)) + .isEmpty(); + softly.assertThat(messageIdDAO.retrieveMessages((CassandraId) benwaInboxMailbox.getMailboxId(), MessageRange.all()).collectList().block()) + .isEmpty(); + })); + } + + @Test + void retrieveMessagesShouldNotReturnMessagesWhenFailsToPersistBlobs(CassandraCluster cassandra) { + cassandra.getConf() + .registerScenario(fail() + .forever() + .whenQueryStartsWith("INSERT INTO blobs (id,position) VALUES (:id,:position);")); + + try { + message1.setUid(mapperProvider.generateMessageUid()); + message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); + sut.save(message1); + } catch (Exception e) { + // ignoring expected error + } + + CassandraMessageIdDAO messageIdDAO = new CassandraMessageIdDAO(cassandra.getConf(), new CassandraMessageId.Factory()); + SoftAssertions.assertSoftly(Throwing.consumer(softly -> { + softly.assertThat(sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Metadata)) + .isEmpty(); + softly.assertThat(messageIdDAO.retrieveMessages((CassandraId) benwaInboxMailbox.getMailboxId(), MessageRange.all()).collectList().block()) + .isEmpty(); + })); + } + + @Test + void retrieveMessagesShouldNotReturnMessagesWhenFailsToPersistInImapUidTable(CassandraCluster cassandra) { + cassandra.getConf() + .registerScenario(fail() + .forever() + .whenQueryStartsWith("INSERT INTO imapUidTable (messageId,mailboxId,uid,modSeq,flagAnswered,flagDeleted,flagDraft,flagFlagged,flagRecent,flagSeen,flagUser,userFlags)")); + + try { + message1.setUid(mapperProvider.generateMessageUid()); + message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); + sut.save(message1); + } catch (Exception e) { + // ignoring expected error + } + + CassandraMessageIdDAO messageIdDAO = new CassandraMessageIdDAO(cassandra.getConf(), new CassandraMessageId.Factory()); + SoftAssertions.assertSoftly(Throwing.consumer(softly -> { + softly.assertThat(sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Metadata)) + .isEmpty(); + softly.assertThat(messageIdDAO.retrieveMessages((CassandraId) benwaInboxMailbox.getMailboxId(), MessageRange.all()).collectList().block()) + .isEmpty(); + })); + } + + @Test + void addShouldPersistInTableOfTruthWhenMessageIdTableWritesFails(CassandraCluster cassandra) { + cassandra.getConf() + .registerScenario(fail() + .forever() + .whenQueryStartsWith("INSERT INTO messageIdTable (mailboxId,uid,modSeq,messageId,flagAnswered,flagDeleted,flagDraft,flagFlagged,flagRecent,flagSeen,flagUser,userFlags)")); + + try { + message1.setUid(mapperProvider.generateMessageUid()); + message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); + sut.save(message1); + } catch (Exception e) { + // ignoring expected error + } + + CassandraMessageIdToImapUidDAO imapUidDAO = new CassandraMessageIdToImapUidDAO(cassandra.getConf(), new CassandraMessageId.Factory()); + + SoftAssertions.assertSoftly(Throwing.consumer(softly -> { + softly.assertThat(sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Metadata)) + .hasSize(1); + softly.assertThat(imapUidDAO.retrieve((CassandraMessageId) message1.getMessageId(), Optional.empty()).collectList().block()) + .hasSize(1); + })); + } + } } diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java index 0c9fc61..57b90f9 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java @@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.time.Duration; import java.util.Date; import java.util.List; -import java.util.Map; import javax.mail.Flags; import javax.mail.Flags.Flag; @@ -42,7 +41,6 @@ import org.apache.james.mailbox.model.Mailbox; 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.UidValidity; import org.apache.james.mailbox.model.UpdatedFlags; import org.apache.james.mailbox.store.mail.MailboxMapper; @@ -71,7 +69,7 @@ public abstract class MessageIdMapperTest { private MessageMapper messageMapper; private MailboxMapper mailboxMapper; - private MessageIdMapper sut; + protected MessageIdMapper sut; protected Mailbox benwaInboxMailbox; private Mailbox benwaWorkMailbox; @@ -81,7 +79,7 @@ public abstract class MessageIdMapperTest { protected SimpleMailboxMessage message3; protected SimpleMailboxMessage message4; - private MapperProvider mapperProvider; + protected MapperProvider mapperProvider; protected abstract MapperProvider provideMapper(); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org