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/05/10 02:31:11 UTC
[04/15] james-project git commit: MAILBOX-331 Testing quota threshold
configuration changes
MAILBOX-331 Testing quota threshold configuration changes
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4b9c3f7b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4b9c3f7b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4b9c3f7b
Branch: refs/heads/master
Commit: 4b9c3f7b6fdb16e2a2ce6eba25d6311c79d78e34
Parents: 8542f4a
Author: benwa <bt...@linagora.com>
Authored: Mon May 7 15:39:15 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu May 10 09:13:23 2018 +0700
----------------------------------------------------------------------
...yQuotaThresholdConfigurationChangesTest.java | 29 +++
.../QuotaThresholdConfigurationChangesTest.java | 248 +++++++++++++++++++
2 files changed, 277 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4b9c3f7b/mailbox/plugin/quota-mailing-memory/src/test/java/org/apache/james/mailbox/quota/memory/listeners/InMemoryQuotaThresholdConfigurationChangesTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing-memory/src/test/java/org/apache/james/mailbox/quota/memory/listeners/InMemoryQuotaThresholdConfigurationChangesTest.java b/mailbox/plugin/quota-mailing-memory/src/test/java/org/apache/james/mailbox/quota/memory/listeners/InMemoryQuotaThresholdConfigurationChangesTest.java
new file mode 100644
index 0000000..ba65405
--- /dev/null
+++ b/mailbox/plugin/quota-mailing-memory/src/test/java/org/apache/james/mailbox/quota/memory/listeners/InMemoryQuotaThresholdConfigurationChangesTest.java
@@ -0,0 +1,29 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.quota.memory.listeners;
+
+import org.apache.james.eventsourcing.InMemoryEventStoreExtension;
+import org.apache.james.mailbox.quota.mailing.listeners.QuotaThresholdConfigurationChangesTest;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(InMemoryEventStoreExtension.class)
+public class InMemoryQuotaThresholdConfigurationChangesTest implements QuotaThresholdConfigurationChangesTest {
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/4b9c3f7b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
new file mode 100644
index 0000000..135b84c
--- /dev/null
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
@@ -0,0 +1,248 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.quota.mailing.listeners;
+
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.BOB_SESSION;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.GRACE_PERIOD;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.NOW;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.QUOTAROOT;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture._50;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture._75;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.mailetContext;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.eventsourcing.EventStore;
+import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
+import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
+import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Counts;
+import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Sizes;
+import org.apache.james.mailbox.quota.model.QuotaThresholds;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public interface QuotaThresholdConfigurationChangesTest {
+
+ @Test
+ default void shouldNotSendMailWhenNoNewExceededThresholdAfterThresholdIncrease(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldNotSendMailAfterThresholdDecreaseWhenAboveAll(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldSendMailWhenNewExceededThresholdAfterThresholdIncrease(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).hasSize(1);
+ }
+
+ @Test
+ default void shouldNotSendMailAfterThresholdIncreaseWhenBelowAll(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldNotSendMailAfterThresholdDecreaseWhenBelowAll(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldSendMailWhenNewExceededThresholdAfterThresholdDecrease(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).hasSize(1);
+ }
+
+ @Test
+ default void shouldSendEmailWhenAddingANewHighestExceededThreshold(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50, _75)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).hasSize(1);
+ }
+
+ @Test
+ default void shouldNotSendEmailWhenAddingAHighestNonExceededThreshold(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50, _75)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldNotSendEmailWhenAddingANonHighestExceededThreshold(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50, _75)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldNotSendEmailWhenRemovingANonHighestExceededThreshold(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50, _75)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_75)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldNotSendEmailWhenRemovingHighestExceededThreshold(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50, _75)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+ @Test
+ default void shouldNotSendEmailWhenRemovingHighestNonExceededThreshold(EventStore store) throws Exception {
+ FakeMailContext mailetContext = mailetContext();
+ QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50, _75)), GRACE_PERIOD));
+
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+ testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
+ new QuotaMailingListenerConfiguration(new QuotaThresholds(ImmutableList.of(_50)), GRACE_PERIOD));
+
+ mailetContext.resetSentMails();
+ testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+ assertThat(mailetContext.getSentMails()).isEmpty();
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org