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 2018/08/21 02:44:54 UTC

[5/5] james-project git commit: JAMES-2468 Don't update quota when deleting empty mailboxes

JAMES-2468 Don't update quota when deleting empty mailboxes

This triggers an error while updating quota


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0a8e0a9d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0a8e0a9d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0a8e0a9d

Branch: refs/heads/master
Commit: 0a8e0a9dd2407430c7e1781c74bb424e2754fcca
Parents: f72d73d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 15 16:15:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Aug 21 09:44:04 2018 +0700

----------------------------------------------------------------------
 .../store/quota/ListeningCurrentQuotaUpdater.java    |  5 ++++-
 .../quota/ListeningCurrentQuotaUpdaterTest.java      | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0a8e0a9d/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index a6c8308..86d67c3 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -111,9 +111,12 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
     }
 
     private void handleMailboxDeletionEvent(MailboxDeletion mailboxDeletionEvent) throws MailboxException {
-        currentQuotaManager.decrease(mailboxDeletionEvent.getQuotaRoot(),
+        boolean mailboxContainedMessages = mailboxDeletionEvent.getDeletedMessageCount().asLong() > 0;
+        if (mailboxContainedMessages) {
+            currentQuotaManager.decrease(mailboxDeletionEvent.getQuotaRoot(),
                 mailboxDeletionEvent.getDeletedMessageCount().asLong(),
                 mailboxDeletionEvent.getTotalDeletedSize().asLong());
+        }
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/0a8e0a9d/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index f2f2385..2c5de61 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.store.quota;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
 import java.util.Date;
@@ -118,4 +119,18 @@ public class ListeningCurrentQuotaUpdaterTest {
         testee.event(deletion);
         verify(mockedCurrentQuotaManager).decrease(QUOTA_ROOT, 10, 5);
     }
+
+    @Test
+    public void mailboxDeletionEventShouldDoNothingWhenEmptyMailbox() throws Exception {
+        MailboxListener.MailboxDeletion deletion = mock(MailboxListener.MailboxDeletion.class);
+        when(deletion.getMailboxPath()).thenReturn(MAILBOX_PATH);
+        when(deletion.getQuotaRoot()).thenReturn(QUOTA_ROOT);
+        when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(0));
+        when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(0));
+        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+
+        testee.event(deletion);
+
+        verifyZeroInteractions(mockedCurrentQuotaManager);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org