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 10c53bc8a00d22891f1b04bf77714bdc664e60e2 Author: Benoit Tellier <[email protected]> AuthorDate: Sat May 8 14:59:24 2021 +0700 JAMES-3138 ListeningCurrentQuotaUpdater should base itself on the mailboxPath to determine quotaRoot --- .../mailbox/store/quota/ListeningCurrentQuotaUpdater.java | 5 ++--- .../james/mailbox/store/quota/StoreQuotaManager.java | 1 - .../store/quota/ListeningCurrentQuotaUpdaterTest.java | 14 +++++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) 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 cfe2d80..e6b158e 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 @@ -45,7 +45,6 @@ import org.reactivestreams.Publisher; import com.google.common.collect.ImmutableSet; import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; public class ListeningCurrentQuotaUpdater implements EventListener.ReactiveGroupEventListener, QuotaUpdater { public static class ListeningCurrentQuotaUpdaterGroup extends Group { @@ -82,11 +81,11 @@ public class ListeningCurrentQuotaUpdater implements EventListener.ReactiveGroup public Publisher<Void> reactiveEvent(Event event) { if (event instanceof Added) { Added addedEvent = (Added) event; - return Mono.from(quotaRootResolver.getQuotaRootReactive(addedEvent.getMailboxId())) + return Mono.from(quotaRootResolver.getQuotaRootReactive(addedEvent.getMailboxPath())) .flatMap(quotaRoot -> handleAddedEvent(addedEvent, quotaRoot)); } else if (event instanceof Expunged) { Expunged expungedEvent = (Expunged) event; - return Mono.from(quotaRootResolver.getQuotaRootReactive(expungedEvent.getMailboxId())) + return Mono.from(quotaRootResolver.getQuotaRootReactive(expungedEvent.getMailboxPath())) .flatMap(quotaRoot -> handleExpungedEvent(expungedEvent, quotaRoot)); } else if (event instanceof MailboxDeletion) { MailboxDeletion mailboxDeletionEvent = (MailboxDeletion) event; diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/StoreQuotaManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/StoreQuotaManager.java index aa010bc..24ca588 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/StoreQuotaManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/StoreQuotaManager.java @@ -37,7 +37,6 @@ import org.apache.james.mailbox.quota.QuotaManager; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; /** * Default implementation for the Quota Manager. 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 26452e2..f71cba2 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 @@ -46,6 +46,7 @@ import org.apache.james.mailbox.events.MailboxEvents.Added; import org.apache.james.mailbox.events.MailboxEvents.Expunged; import org.apache.james.mailbox.events.MailboxEvents.MailboxDeletion; import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageMetaData; import org.apache.james.mailbox.model.QuotaOperation; import org.apache.james.mailbox.model.QuotaRoot; @@ -67,6 +68,7 @@ class ListeningCurrentQuotaUpdaterTest { static final MailboxId MAILBOX_ID = TestId.of(42); static final String BENWA = "benwa"; static final Username USERNAME_BENWA = Username.of(BENWA); + static final MailboxPath MAILBOX_PATH = MailboxPath.forUser(USERNAME_BENWA, "path"); static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot(BENWA, Optional.empty()); static final QuotaOperation QUOTA = new QuotaOperation(QUOTA_ROOT, QuotaCountUsage.count(2), QuotaSizeUsage.size(2 * SIZE)); @@ -80,8 +82,10 @@ class ListeningCurrentQuotaUpdaterTest { mockedCurrentQuotaManager = mock(CurrentQuotaManager.class); EventBus eventBus = mock(EventBus.class); when(eventBus.dispatch(any(Event.class), anySet())).thenReturn(Mono.empty()); + QuotaManager quotaManager = mock(QuotaManager.class); + when(quotaManager.getQuotasReactive(eq(QUOTA_ROOT))).thenReturn(Mono.empty()); testee = new ListeningCurrentQuotaUpdater(mockedCurrentQuotaManager, mockedQuotaRootResolver, - eventBus, mock(QuotaManager.class)); + eventBus, quotaManager); } @Test @@ -94,11 +98,13 @@ class ListeningCurrentQuotaUpdaterTest { void addedEventShouldIncreaseCurrentQuotaValues() throws Exception { Added added = mock(Added.class); when(added.getMailboxId()).thenReturn(MAILBOX_ID); + when(added.getMailboxPath()).thenReturn(MAILBOX_PATH); when(added.getMetaData(MessageUid.of(36))).thenReturn(new MessageMetaData(MessageUid.of(36), ModSeq.first(),new Flags(), SIZE, new Date(), new DefaultMessageId())); when(added.getMetaData(MessageUid.of(38))).thenReturn(new MessageMetaData(MessageUid.of(38), ModSeq.first(),new Flags(), SIZE, new Date(), new DefaultMessageId())); when(added.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38))); when(added.getUsername()).thenReturn(USERNAME_BENWA); when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_ID))).thenReturn(Mono.just(QUOTA_ROOT)); + when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_PATH))).thenReturn(Mono.just(QUOTA_ROOT)); when(mockedCurrentQuotaManager.increase(QUOTA)).thenAnswer(any -> Mono.empty()); testee.event(added); @@ -114,6 +120,8 @@ class ListeningCurrentQuotaUpdaterTest { when(expunged.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38))); when(expunged.getMailboxId()).thenReturn(MAILBOX_ID); when(expunged.getUsername()).thenReturn(USERNAME_BENWA); + when(expunged.getMailboxPath()).thenReturn(MAILBOX_PATH); + when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_PATH))).thenReturn(Mono.just(QUOTA_ROOT)); when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_ID))).thenReturn(Mono.just(QUOTA_ROOT)); when(mockedCurrentQuotaManager.decrease(QUOTA)).thenAnswer(any -> Mono.empty()); @@ -128,6 +136,8 @@ class ListeningCurrentQuotaUpdaterTest { when(expunged.getUids()).thenReturn(Lists.<MessageUid>newArrayList()); when(expunged.getMailboxId()).thenReturn(MAILBOX_ID); when(expunged.getUsername()).thenReturn(USERNAME_BENWA); + when(expunged.getMailboxPath()).thenReturn(MAILBOX_PATH); + when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_PATH))).thenReturn(Mono.just(QUOTA_ROOT)); when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_ID))).thenReturn(Mono.just(QUOTA_ROOT)); testee.event(expunged); @@ -141,6 +151,8 @@ class ListeningCurrentQuotaUpdaterTest { when(added.getUids()).thenReturn(Lists.<MessageUid>newArrayList()); when(added.getMailboxId()).thenReturn(MAILBOX_ID); when(added.getUsername()).thenReturn(USERNAME_BENWA); + when(added.getMailboxPath()).thenReturn(MAILBOX_PATH); + when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_PATH))).thenReturn(Mono.just(QUOTA_ROOT)); when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_ID))).thenReturn(Mono.just(QUOTA_ROOT)); testee.event(added); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
