JAMES-2103 Add failing tests for StoreMessageIdManager Quota management

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

Branch: refs/heads/master
Commit: 69cef15f708a7caf6dde96b1347e2367ab9d2de4
Parents: 56beed2
Author: benwa <btell...@linagora.com>
Authored: Fri Jul 28 11:23:30 2017 +0700
Committer: benwa <btell...@linagora.com>
Committed: Tue Aug 8 10:39:51 2017 +0700

----------------------------------------------------------------------
 .../CassandraMessageIdManagerQuotaTest.java     |  62 +++++++++
 .../CassandraMessageIdManagerTestSystem.java    |  40 +++++-
 .../cassandra/CassandraTestSystemFixture.java   |  53 +++++--
 .../InMemoryMessageIdManagerTestSystem.java     |   8 +-
 .../AbstractMessageIdManagerQuotaTest.java      | 137 +++++++++++++++++++
 .../store/MessageIdManagerTestSystem.java       |   2 +
 .../store/StoreMessageIdManagerTestSystem.java  |   5 +
 7 files changed, 288 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/69cef15f/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java
new file mode 100644
index 0000000..423af97
--- /dev/null
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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.cassandra;
+
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.store.AbstractMessageIdManagerQuotaTest;
+import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
+import org.apache.james.mailbox.store.quota.StoreQuotaManager;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class CassandraMessageIdManagerQuotaTest extends 
AbstractMessageIdManagerQuotaTest {
+
+    @BeforeClass
+    public static void init() {
+        CassandraMessageIdManagerTestSystem.initWithQuota();
+    }
+
+    @AfterClass
+    public static void close() {
+        CassandraMessageIdManagerTestSystem.stop();
+    }
+
+    @Override
+    protected MessageIdManagerTestSystem createTestSystem(QuotaManager 
quotaManager, CurrentQuotaManager currentQuotaManager) throws Exception {
+        return 
CassandraMessageIdManagerTestSystem.createTestingDataWithQuota(quotaManager, 
currentQuotaManager);
+    }
+
+    @Override
+    protected MaxQuotaManager createMaxQuotaManager() {
+        return CassandraTestSystemFixture.createMaxQuotaManager();
+    }
+
+    @Override
+    protected QuotaManager createQuotaManager(MaxQuotaManager maxQuotaManager, 
CurrentQuotaManager currentQuotaManager) {
+        return new StoreQuotaManager(currentQuotaManager, maxQuotaManager);
+    }
+
+    @Override
+    protected CurrentQuotaManager createCurrentQuotaManager() {
+        return CassandraTestSystemFixture.createCurrentQuotaManager();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/69cef15f/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
index 73c2b5d..2d4c6c1 100644
--- 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
@@ -32,19 +32,28 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
+import org.apache.james.mailbox.store.SimpleMessageMetaData;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
+import org.apache.james.mailbox.store.quota.StoreCurrentQuotaManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Charsets;
 import com.google.common.base.Throwables;
 
 public class CassandraMessageIdManagerTestSystem extends 
MessageIdManagerTestSystem {
 
+    private static final byte[] MESSAGE_CONTENT = "subject: 
any\n\nbody".getBytes(Charsets.UTF_8);
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CassandraMessageIdManagerTestSystem.class);
+
     public static MessageIdManagerTestSystem createTestingData(QuotaManager 
quotaManager, MailboxEventDispatcher dispatcher) throws Exception {
         CassandraMailboxSessionMapperFactory mapperFactory = 
CassandraTestSystemFixture.createMapperFactory();
 
@@ -54,6 +63,20 @@ public class CassandraMessageIdManagerTestSystem extends 
MessageIdManagerTestSys
             CassandraTestSystemFixture.createMailboxManager(mapperFactory));
     }
 
+    public static MessageIdManagerTestSystem 
createTestingDataWithQuota(QuotaManager quotaManager, CurrentQuotaManager 
currentQuotaManager) throws Exception {
+        CassandraMailboxSessionMapperFactory mapperFactory = 
CassandraTestSystemFixture.createMapperFactory();
+
+        CassandraMailboxManager mailboxManager = 
CassandraTestSystemFixture.createMailboxManager(mapperFactory);
+        ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new 
ListeningCurrentQuotaUpdater(
+            (StoreCurrentQuotaManager) currentQuotaManager,
+            mailboxManager.getQuotaRootResolver());
+        mailboxManager.addGlobalListener(listeningCurrentQuotaUpdater, 
mailboxManager.createSystemSession("System", LOGGER));
+        return new 
CassandraMessageIdManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory,
 quotaManager, mailboxManager.getEventDispatcher()),
+            new CassandraMessageId.Factory(),
+            mapperFactory,
+            mailboxManager);
+    }
+
     private final CassandraMessageId.Factory messageIdFactory;
     private final CassandraMailboxSessionMapperFactory mapperFactory;
     private final CassandraMailboxManager cassandraMailboxManager;
@@ -76,7 +99,9 @@ public class CassandraMessageIdManagerTestSystem extends 
MessageIdManagerTestSys
         try {
             CassandraMessageId messageId = messageIdFactory.generate();
             Mailbox mailbox = 
mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
-            mapperFactory.getMessageMapper(mailboxSession).add(mailbox, 
createMessage(mailboxId, flags, messageId, uid));
+            MailboxMessage message = createMessage(mailboxId, flags, 
messageId, uid);
+            mapperFactory.getMessageMapper(mailboxSession).add(mailbox, 
message);
+            cassandraMailboxManager.getEventDispatcher().added(mailboxSession, 
new SimpleMessageMetaData(message), mailbox);
             return messageId;
         } catch (Exception e) {
             throw Throwables.propagate(e);
@@ -104,8 +129,8 @@ public class CassandraMessageIdManagerTestSystem extends 
MessageIdManagerTestSys
     }
 
     private static MailboxMessage createMessage(MailboxId mailboxId, Flags 
flags, MessageId messageId, MessageUid uid) {
-        MailboxMessage mailboxMessage = new SimpleMailboxMessage(messageId, 
new Date(), 1596, 1256,
-            new SharedByteArrayInputStream("subject: 
any\n\nbody".getBytes(Charsets.UTF_8)), flags, new PropertyBuilder(), 
mailboxId);
+        MailboxMessage mailboxMessage = new SimpleMailboxMessage(messageId, 
new Date(), MESSAGE_CONTENT.length, 1256,
+            new SharedByteArrayInputStream(MESSAGE_CONTENT), flags, new 
PropertyBuilder(), mailboxId);
         mailboxMessage.setModSeq(CassandraTestSystemFixture.MOD_SEQ);
         mailboxMessage.setUid(uid);
         return mailboxMessage;
@@ -115,9 +140,16 @@ public class CassandraMessageIdManagerTestSystem extends 
MessageIdManagerTestSys
         CassandraTestSystemFixture.init();
     }
 
+    public static void initWithQuota() {
+        CassandraTestSystemFixture.initWithQuota();
+    }
+
     public static void stop() {
         CassandraTestSystemFixture.stop();
     }
 
-
+    @Override
+    public int getConstantMessageSize() {
+        return MESSAGE_CONTENT.length;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/69cef15f/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
index de5c0ad..8e1a5bd 100644
--- 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
@@ -50,7 +50,12 @@ import 
org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
 import 
org.apache.james.mailbox.cassandra.modules.CassandraMailboxRecentsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
+import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManager;
+import 
org.apache.james.mailbox.cassandra.quota.CassandraPerUserMaxQuotaManager;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
@@ -59,10 +64,25 @@ import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver;
+import org.apache.james.mailbox.store.quota.StoreQuotaManager;
 
 public class CassandraTestSystemFixture {
     
     public static final int MOD_SEQ = 452;
+    public static final CassandraModuleComposite BASE_MAILBOX_MODULES = new 
CassandraModuleComposite(
+        new CassandraAclModule(),
+        new CassandraMailboxModule(),
+        new CassandraMessageModule(),
+        new CassandraBlobModule(),
+        new CassandraMailboxCounterModule(),
+        new CassandraMailboxRecentsModule(),
+        new CassandraFirstUnseenModule(),
+        new CassandraDeletedMessageModule(),
+        new CassandraUidModule(),
+        new CassandraModSeqModule(),
+        new CassandraAttachmentModule(),
+        new CassandraAnnotationModule(),
+        new CassandraApplicableFlagsModule());
     private static CassandraCluster cassandra;
     
     public static CassandraMailboxSessionMapperFactory createMapperFactory() {
@@ -115,26 +135,31 @@ public class CassandraTestSystemFixture {
             new DefaultQuotaRootResolver(mapperFactory));
     }
 
+    public static MaxQuotaManager createMaxQuotaManager() {
+        return new CassandraPerUserMaxQuotaManager(cassandra.getConf());
+    }
+
+    public static CurrentQuotaManager createCurrentQuotaManager() {
+        return new CassandraCurrentQuotaManager(cassandra.getConf());
+    }
+
+    public static QuotaManager createQuotaManager(MaxQuotaManager 
maxQuotaManager) {
+        return new StoreQuotaManager(new 
CassandraCurrentQuotaManager(cassandra.getConf()), maxQuotaManager);
+    }
+
     public static void clean() {
         cassandra.clearAllTables();
     }
 
     public static void init() {
+        cassandra = CassandraCluster.create(BASE_MAILBOX_MODULES);
+    }
+
+    public static void initWithQuota() {
         cassandra = CassandraCluster.create(
-                new CassandraModuleComposite(
-                    new CassandraAclModule(),
-                    new CassandraMailboxModule(),
-                    new CassandraMessageModule(),
-                    new CassandraBlobModule(),
-                    new CassandraMailboxCounterModule(),
-                    new CassandraMailboxRecentsModule(),
-                    new CassandraFirstUnseenModule(),
-                    new CassandraDeletedMessageModule(),
-                    new CassandraUidModule(),
-                    new CassandraModSeqModule(),
-                    new CassandraAttachmentModule(),
-                    new CassandraAnnotationModule(),
-                    new CassandraApplicableFlagsModule()));
+            new CassandraModuleComposite(
+                BASE_MAILBOX_MODULES,
+                new CassandraQuotaModule()));
     }
 
     public static void stop() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/69cef15f/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git 
a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
 
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
index 649f6cb..1bd6068 100644
--- 
a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
+++ 
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
@@ -37,6 +37,7 @@ import 
org.apache.james.mailbox.store.MessageIdManagerTestSystem;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 
+import com.google.common.base.Charsets;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.base.Throwables;
@@ -47,6 +48,7 @@ public class InMemoryMessageIdManagerTestSystem extends 
MessageIdManagerTestSyst
     private static final MessageId FIRST_MESSAGE_ID = InMemoryMessageId.of(1);
     private static final long ONE_HUNDRED = 100;
     private static final int UID_VALIDITY = 1024;
+    public static final byte[] CONTENT = "Subject: 
test\r\n\r\ntestmail".getBytes(Charsets.UTF_8);
 
     private final MailboxManager mailboxManager;
     private Optional<MessageId> lastMessageIdUsed;
@@ -68,7 +70,7 @@ public class InMemoryMessageIdManagerTestSystem extends 
MessageIdManagerTestSyst
     public MessageId persist(MailboxId mailboxId, MessageUid uid, Flags flags, 
MailboxSession session) {
         try {
             MessageManager messageManager = 
mailboxManager.getMailbox(mailboxId, session);
-            MessageId messageId = messageManager.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), 
session, false, flags)
+            MessageId messageId = messageManager.appendMessage(new 
ByteArrayInputStream(CONTENT), new Date(), session, false, flags)
                     .getMessageId();
             lastMessageIdUsed = Optional.of(messageId);
             return messageId;
@@ -112,4 +114,8 @@ public class InMemoryMessageIdManagerTestSystem extends 
MessageIdManagerTestSyst
 
     }
 
+    @Override
+    public int getConstantMessageSize() {
+        return CONTENT.length;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/69cef15f/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java
new file mode 100644
index 0000000..bfc59d6
--- /dev/null
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java
@@ -0,0 +1,137 @@
+/****************************************************************
+ * 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.store;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageIdManager;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.exception.OverQuotaException;
+import org.apache.james.mailbox.manager.MailboxManagerFixture;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.common.collect.ImmutableList;
+
+public abstract class AbstractMessageIdManagerQuotaTest {
+    private static final MessageUid messageUid1 = MessageUid.of(111);
+
+    public static final Flags FLAGS = new Flags();
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    private MessageIdManager messageIdManager;
+    private MailboxSession session;
+    private Mailbox mailbox1;
+    private Mailbox mailbox2;
+    private Mailbox mailbox3;
+    private MessageIdManagerTestSystem testingData;
+    private MaxQuotaManager maxQuotaManager;
+
+    protected abstract MessageIdManagerTestSystem 
createTestSystem(QuotaManager quotaManager, CurrentQuotaManager 
currentQuotaManager) throws Exception;
+
+    protected abstract MaxQuotaManager createMaxQuotaManager();
+    protected abstract CurrentQuotaManager createCurrentQuotaManager();
+    protected abstract QuotaManager createQuotaManager(MaxQuotaManager 
maxQuotaManager, CurrentQuotaManager currentQuotaManager);
+
+    @Before
+    public void setUp() throws Exception {
+        maxQuotaManager = createMaxQuotaManager();
+        CurrentQuotaManager currentQuotaManager = createCurrentQuotaManager();
+        QuotaManager quotaManager = createQuotaManager(maxQuotaManager, 
currentQuotaManager);
+
+        session = new MockMailboxSession("user");
+        testingData = createTestSystem(quotaManager, currentQuotaManager);
+        messageIdManager = testingData.getMessageIdManager();
+
+        mailbox1 = 
testingData.createMailbox(MailboxManagerFixture.MAILBOX_PATH1, session);
+        mailbox2 = 
testingData.createMailbox(MailboxManagerFixture.MAILBOX_PATH2, session);
+        mailbox3 = 
testingData.createMailbox(MailboxManagerFixture.MAILBOX_PATH3, session);
+    }
+
+    @After
+    public void tearDown() {
+        testingData.clean();
+    }
+
+    @Test
+    public void setInMailboxesShouldNotThrowWhenMessageQuotaNotExceeded() 
throws Exception {
+        maxQuotaManager.setDefaultMaxMessage(1);
+
+        MessageId messageId = testingData.persist(mailbox2.getMailboxId(), 
messageUid1, FLAGS, session);
+
+        messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId()), session);
+    }
+
+    @Test
+    public void setInMailboxesShouldNotThrowWhenStorageQuotaNotExceeded() 
throws Exception {
+        
maxQuotaManager.setDefaultMaxStorage(testingData.getConstantMessageSize());
+
+        MessageId messageId = testingData.persist(mailbox2.getMailboxId(), 
messageUid1, FLAGS, session);
+
+        messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId()), session);
+    }
+
+    @Test
+    public void setInMailboxesShouldThrowWhenStorageQuotaExceeded() throws 
Exception {
+        maxQuotaManager.setDefaultMaxStorage(2 * 
testingData.getConstantMessageSize());
+
+        testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, 
session);
+        MessageId messageId = testingData.persist(mailbox2.getMailboxId(), 
messageUid1, FLAGS, session);
+
+        expectedException.expect(OverQuotaException.class);
+        messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
+    }
+
+    @Ignore
+    @Test
+    public void 
setInMailboxesShouldThrowWhenStorageQuotaExceededWhenCopiedToMultipleMailboxes()
 throws Exception {
+        maxQuotaManager.setDefaultMaxStorage(2 * 
testingData.getConstantMessageSize());
+
+        MessageId messageId = testingData.persist(mailbox1.getMailboxId(), 
messageUid1, FLAGS, session);
+
+        expectedException.expect(OverQuotaException.class);
+        messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId(), 
mailbox3.getMailboxId()), session);
+    }
+
+    @Test
+    public void setInMailboxesShouldThrowWhenStorageMessageExceeded() throws 
Exception {
+        maxQuotaManager.setDefaultMaxMessage(2);
+
+        testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, 
session);
+        MessageId messageId = testingData.persist(mailbox2.getMailboxId(), 
messageUid1, FLAGS, session);
+
+        expectedException.expect(OverQuotaException.class);
+        messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId(), 
mailbox3.getMailboxId()), session);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/69cef15f/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
index eeae592..ecb45d8e 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
@@ -61,4 +61,6 @@ public abstract class MessageIdManagerTestSystem {
     public abstract void deleteMailbox(MailboxId mailboxId, MailboxSession 
session);
 
     public abstract void clean();
+
+    public abstract int getConstantMessageSize();
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/69cef15f/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
index 90883fc..2f68685 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
@@ -104,4 +104,9 @@ public class StoreMessageIdManagerTestSystem extends 
MessageIdManagerTestSystem
         when(mailboxMessage.createFlags()).thenReturn(flags);
         return mailboxMessage;
     }
+
+    @Override
+    public int getConstantMessageSize() {
+        throw new NotImplementedException();
+    }
 }


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

Reply via email to