JAMES-3138 ListeningCurrentQuotaUpdater should base itself on the mailboxPath to determine quotaRoot
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 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 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.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.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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);