You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2020/11/30 12:12:30 UTC
[james-project] 04/07: JAMES-3458 Allow grouping max quota reads
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 1329641fea7387c908de09dfcbb1622607ec4993
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Nov 27 10:19:39 2020 +0700
JAMES-3458 Allow grouping max quota reads
---
.../james/mailbox/quota/MaxQuotaManager.java | 22 ++++++++++++++++++++++
.../mailbox/store/quota/StoreQuotaManager.java | 11 +++++------
.../AbstractMessageIdManagerSideEffectTest.java | 17 ++++++++---------
.../imap/processor/GetQuotaProcessorTest.java | 9 +++++----
.../imap/processor/GetQuotaRootProcessorTest.java | 5 +++--
5 files changed, 43 insertions(+), 21 deletions(-)
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
index adf979e..b105b42 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
@@ -152,6 +152,10 @@ public interface MaxQuotaManager {
Map<Quota.Scope, QuotaSizeLimit> listMaxStorageDetails(QuotaRoot quotaRoot);
+ default QuotaDetails quotaDetails(QuotaRoot quotaRoot) {
+ return new QuotaDetails(listMaxMessagesDetails(quotaRoot), listMaxStorageDetails(quotaRoot));
+ }
+
Optional<QuotaCountLimit> getDomainMaxMessage(Domain domain);
void setDomainMaxMessage(Domain domain, QuotaCountLimit count) throws MailboxException;
@@ -181,4 +185,22 @@ public interface MaxQuotaManager {
.flatMap(Optional::stream)
.findFirst();
}
+
+ class QuotaDetails {
+ private final Map<Quota.Scope, QuotaCountLimit> maxMessageDetails;
+ private final Map<Quota.Scope, QuotaSizeLimit> maxStorageDetails;
+
+ public QuotaDetails(Map<Scope, QuotaCountLimit> maxMessageDetails, Map<Scope, QuotaSizeLimit> maxStorageDetails) {
+ this.maxMessageDetails = maxMessageDetails;
+ this.maxStorageDetails = maxStorageDetails;
+ }
+
+ public Map<Scope, QuotaCountLimit> getMaxMessageDetails() {
+ return maxMessageDetails;
+ }
+
+ public Map<Scope, QuotaSizeLimit> getMaxStorageDetails() {
+ return maxStorageDetails;
+ }
+ }
}
\ No newline at end of file
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 6e4d42d..17d80e7 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
@@ -76,19 +76,18 @@ public class StoreQuotaManager implements QuotaManager {
@Override
public Quotas getQuotas(QuotaRoot quotaRoot) throws MailboxException {
- Map<Scope, QuotaSizeLimit> maxStorageDetails = maxQuotaManager.listMaxStorageDetails(quotaRoot);
- Map<Scope, QuotaCountLimit> maxMessageDetails = maxQuotaManager.listMaxMessagesDetails(quotaRoot);
+ MaxQuotaManager.QuotaDetails quotaDetails = maxQuotaManager.quotaDetails(quotaRoot);
CurrentQuotas currentQuotas = Mono.from(currentQuotaManager.getCurrentQuotas(quotaRoot)).block();
return new Quotas(
Quota.<QuotaCountLimit, QuotaCountUsage>builder()
.used(currentQuotas.count())
- .computedLimit(maxQuotaManager.getMaxMessage(maxMessageDetails).orElse(QuotaCountLimit.unlimited()))
- .limitsByScope(maxMessageDetails)
+ .computedLimit(maxQuotaManager.getMaxMessage(quotaDetails.getMaxMessageDetails()).orElse(QuotaCountLimit.unlimited()))
+ .limitsByScope(quotaDetails.getMaxMessageDetails())
.build(),
Quota.<QuotaSizeLimit, QuotaSizeUsage>builder()
.used(currentQuotas.size())
- .computedLimit(maxQuotaManager.getMaxStorage(maxStorageDetails).orElse(QuotaSizeLimit.unlimited()))
- .limitsByScope(maxStorageDetails)
+ .computedLimit(maxQuotaManager.getMaxStorage(quotaDetails.getMaxStorageDetails()).orElse(QuotaSizeLimit.unlimited()))
+ .limitsByScope(quotaDetails.getMaxStorageDetails())
.build());
}
}
\ No newline at end of file
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
index e351d9a..751704b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
@@ -357,11 +357,10 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
void setInMailboxesShouldThrowExceptionWhenOverQuota() throws Exception {
MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
- when(quotaManager.getStorageQuota(any(QuotaRoot.class))).thenReturn(
- Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(2)).computedLimit(QuotaSizeLimit.unlimited()).build());
- when(quotaManager.getMessageQuota(any(QuotaRoot.class))).thenReturn(OVER_QUOTA);
- when(quotaManager.getStorageQuota(any(QuotaRoot.class))).thenReturn(
- Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(2)).computedLimit(QuotaSizeLimit.unlimited()).build());
+ when(quotaManager.getQuotas(any(QuotaRoot.class)))
+ .thenReturn(new QuotaManager.Quotas(
+ OVER_QUOTA,
+ Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(2)).computedLimit(QuotaSizeLimit.unlimited()).build()));
assertThatThrownBy(() -> messageIdManager.setInMailboxes(messageId,
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()),
@@ -526,9 +525,9 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
}
protected void givenUnlimitedQuota() throws MailboxException {
- when(quotaManager.getMessageQuota(any(QuotaRoot.class))).thenReturn(
- Quota.<QuotaCountLimit, QuotaCountUsage>builder().used(QuotaCountUsage.count(2)).computedLimit(QuotaCountLimit.unlimited()).build());
- when(quotaManager.getStorageQuota(any(QuotaRoot.class))).thenReturn(
- Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(2)).computedLimit(QuotaSizeLimit.unlimited()).build());
+ when(quotaManager.getQuotas(any(QuotaRoot.class)))
+ .thenReturn(new QuotaManager.Quotas(
+ Quota.<QuotaCountLimit, QuotaCountUsage>builder().used(QuotaCountUsage.count(2)).computedLimit(QuotaCountLimit.unlimited()).build(),
+ Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(2)).computedLimit(QuotaSizeLimit.unlimited()).build()));
}
}
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
index 3bf1c3d..c6c11ae 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
@@ -21,6 +21,7 @@ package org.apache.james.imap.processor;
import static org.apache.james.imap.ImapFixture.TAG;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -105,8 +106,8 @@ public class GetQuotaProcessorTest {
.thenReturn(Flux.just(mailbox));
when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession))
.thenReturn(true);
- when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(MESSAGE_QUOTA);
- when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(STORAGE_QUOTA);
+ when(mockedQuotaManager.getQuotas(any(QuotaRoot.class)))
+ .thenReturn(new QuotaManager.Quotas(MESSAGE_QUOTA, STORAGE_QUOTA));
QuotaResponse storageQuotaResponse = new QuotaResponse("STORAGE", "plop", STORAGE_QUOTA);
QuotaResponse messageQuotaResponse = new QuotaResponse("MESSAGE", "plop", MESSAGE_QUOTA);
@@ -132,8 +133,8 @@ public class GetQuotaProcessorTest {
.thenReturn(Flux.just((mailbox)));
when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession))
.thenReturn(true);
- when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenThrow(new MailboxException());
- when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(STORAGE_QUOTA);
+ when(mockedQuotaManager.getQuotas(any(QuotaRoot.class)))
+ .thenThrow(new MailboxException());
testee.doProcess(getQuotaRequest, mockedResponder, imapSession);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
index 440e5b5..28d95eb 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
@@ -22,6 +22,7 @@ package org.apache.james.imap.processor;
import static org.apache.james.imap.ImapFixture.TAG;
import static org.apache.james.imap.api.message.response.StatusResponse.Type.OK;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.times;
@@ -98,8 +99,8 @@ public class GetQuotaRootProcessorTest {
imapSession.setMailboxSession(mailboxSession);
when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession)).thenReturn(true);
- when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(MESSAGE_QUOTA);
- when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(STORAGE_QUOTA);
+ when(mockedQuotaManager.getQuotas(any(QuotaRoot.class)))
+ .thenReturn(new QuotaManager.Quotas(MESSAGE_QUOTA, STORAGE_QUOTA));
final QuotaResponse storageQuotaResponse = new QuotaResponse("STORAGE", "plop", STORAGE_QUOTA);
final QuotaResponse messageQuotaResponse = new QuotaResponse("MESSAGE", "plop", MESSAGE_QUOTA);
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org