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 2020/02/20 03:27:46 UTC
[james-project] 04/08: JAMES-3056 Consistency test on failing
deleting
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 c31b05994f7a74d1ff2c3d334d4d690e550e15df
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Feb 14 10:20:06 2020 +0700
JAMES-3056 Consistency test on failing deleting
---
.../CassandraMailboxManagerConsistencyTest.java | 288 ++++++++++++++++++++-
1 file changed, 287 insertions(+), 1 deletion(-)
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java
index e2977fc..2278c2a 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java
@@ -368,7 +368,293 @@ class CassandraMailboxManagerConsistencyTest {
@Nested
class FailsOnDelete {
- // TODO
+
+ @Nested
+ class DeleteOnce {
+ @Disabled("JAMES-3056 allMailboxesSearchQuery returns empty list")
+ @Test
+ void deleteMailboxByPathShouldBeConsistentWhenMailboxDaoFails() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .when(mailboxDAO)
+ .delete(any(CassandraId.class));
+
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+
+ @Disabled("JAMES-3056 allMailboxesSearchQuery returns empty list")
+ @Test
+ void deleteMailboxByIdShouldBeConsistentWhenMailboxDaoFails() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .when(mailboxDAO)
+ .delete(any(CassandraId.class));
+
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+
+ @Test
+ void deleteMailboxByPathShouldBeConsistentWhenMailboxPathDaoFails() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .when(mailboxPathV2DAO)
+ .delete(inboxPath);
+
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+
+ @Test
+ void deleteMailboxByIdShouldBeConsistentWhenMailboxPathDaoFails() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .when(mailboxPathV2DAO)
+ .delete(inboxPath);
+
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+ }
+
+ @Nested
+ class DeleteTwice {
+
+ @Disabled("JAMES-3056 list() returns one element with inboxPath")
+ @Test
+ void deleteMailboxByPathShouldDeleteWhenMailboxDaoFails() throws Exception {
+ testee.createMailbox(inboxPath, mailboxSession);
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxDAO)
+ .delete(any(CassandraId.class));
+
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .isEmpty();
+ softly.assertThat(testee.list(mailboxSession))
+ .isEmpty();
+ }));
+ }
+
+ @Test
+ void deleteMailboxByIdShouldDeleteWhenMailboxDaoFails() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxDAO)
+ .delete(any(CassandraId.class));
+
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .isEmpty();
+ softly.assertThat(testee.list(mailboxSession))
+ .isEmpty();
+ }));
+ }
+
+ @Test
+ void deleteMailboxByPathShouldDeleteWhenMailboxPathDaoFails() throws Exception {
+ testee.createMailbox(inboxPath, mailboxSession);
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxPathV2DAO)
+ .delete(inboxPath);
+
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .isEmpty();
+ softly.assertThat(testee.list(mailboxSession))
+ .isEmpty();
+ }));
+ }
+
+ @Test
+ void deleteMailboxByIdShouldDeleteWhenMailboxPathDaoFails() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxPathV2DAO)
+ .delete(inboxPath);
+
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .isEmpty();
+ softly.assertThat(testee.list(mailboxSession))
+ .isEmpty();
+ }));
+ }
+ }
+
+ @Nested
+ class DeleteTwiceThenCreate {
+
+ @Disabled("JAMES-3056 list() returns two element with inboxPath being duplicated")
+ @Test
+ void createMailboxShouldCreateWhenMailboxDaoFailsOnDeleteByPath() throws Exception {
+ testee.createMailbox(inboxPath, mailboxSession);
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxDAO)
+ .delete(any(CassandraId.class));
+
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+
+ @Test
+ void createMailboxShouldCreateWhenMailboxDaoFailsOnDeleteById() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxDAO)
+ .delete(any(CassandraId.class));
+
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+ MailboxId inboxNewId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+
+ @Test
+ void createMailboxShouldCreateWhenMailboxPathDaoFailsOnDeleteByPath() throws Exception {
+ testee.createMailbox(inboxPath, mailboxSession);
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxPathV2DAO)
+ .delete(inboxPath);
+
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+ MailboxId inboxNewId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+
+ @Test
+ void createMailboxShouldCreateWhenMailboxPathDaoFailsOnDeleteById() throws Exception {
+ MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ doReturn(Mono.error(new RuntimeException("mock exception")))
+ .doCallRealMethod()
+ .when(mailboxPathV2DAO)
+ .delete(inboxPath);
+
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+ doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+ MailboxId inboxNewId = testee.createMailbox(inboxPath, mailboxSession)
+ .get();
+
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+ .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+ softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
+ softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+ });
+ softly.assertThat(testee.list(mailboxSession))
+ .containsExactly(inboxPath);
+ }));
+ }
+ }
}
private void doQuietly(ThrowingRunnable runnable) {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org