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 2015/09/22 12:19:23 UTC

svn commit: r1704529 - in /james/mailbox/trunk/memory/src: main/java/org/apache/james/mailbox/inmemory/quota/ test/java/org/apache/james/mailbox/inmemory/quota/

Author: btellier
Date: Tue Sep 22 10:19:20 2015
New Revision: 1704529

URL: http://svn.apache.org/viewvc?rev=1704529&view=rev
Log:
MAILBOX-64 In memory implementation for max quota manager

Added:
    james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/
    james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java
    james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/
    james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManagerTest.java

Added: james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java?rev=1704529&view=auto
==============================================================================
--- james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java (added)
+++ james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java Tue Sep 22 10:19:20 2015
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.inmemory.quota;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
+
+public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager {
+
+    private long maxMessage = Quota.UNLIMITED;
+    private long maxStorage = Quota.UNLIMITED;
+
+    private Map<String, Long> userMaxStorage = new ConcurrentHashMap<String, Long>();
+    private Map<String, Long> userMaxMessage = new ConcurrentHashMap<String, Long>();
+
+    @Override
+    public void setDefaultMaxStorage(long maxStorage) throws MailboxException {
+        this.maxStorage = maxStorage;
+    }
+
+    @Override
+    public void setDefaultMaxMessage(long maxMessage) throws MailboxException {
+        this.maxMessage = maxMessage;
+    }
+
+    @Override
+    public long getMaxStorage(QuotaRoot quotaRoot) throws MailboxException {
+        Long max = userMaxStorage.get(quotaRoot.getValue());
+        if (max == null) {
+            return maxStorage;
+        }
+        return max;
+    }
+
+    @Override
+    public long getMaxMessage(QuotaRoot quotaRoot) throws MailboxException {
+        Long max = userMaxMessage.get(quotaRoot.getValue());
+        if (max == null) {
+            return maxMessage;
+        }
+        return max;
+    }
+
+    @Override
+    public void setMaxStorage(QuotaRoot user, long maxStorageQuota) {
+        userMaxStorage.put(user.getValue(), maxStorageQuota);
+    }
+
+    @Override
+    public void setMaxMessage(QuotaRoot quotaRoot, long maxMessageCount) {
+        userMaxMessage.put(quotaRoot.getValue(), maxMessageCount);
+    }
+
+}

Added: james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManagerTest.java?rev=1704529&view=auto
==============================================================================
--- james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManagerTest.java (added)
+++ james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManagerTest.java Tue Sep 22 10:19:20 2015
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.inmemory.quota;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.store.quota.QuotaRootImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+public class InMemoryPerUserMaxQuotaManagerTest {
+
+    private InMemoryPerUserMaxQuotaManager perUserMaxQuotaManager;
+    private QuotaRoot quotaRoot;
+
+    @Before
+    public void setUp() {
+        perUserMaxQuotaManager = new InMemoryPerUserMaxQuotaManager();
+        quotaRoot = QuotaRootImpl.quotaRoot("benwa");
+    }
+
+    @Test
+    public void getMaxMessageShouldReturnUnlimitedWhenNoDefaultValue() throws Exception {
+        assertThat(perUserMaxQuotaManager.getMaxMessage(quotaRoot)).isEqualTo(Quota.UNLIMITED);
+    }
+
+    @Test
+    public void getMaxStorageShouldReturnUnlimitedWhenNoDefaultValue() throws Exception {
+        assertThat(perUserMaxQuotaManager.getMaxStorage(quotaRoot)).isEqualTo(Quota.UNLIMITED);
+    }
+
+    @Test
+    public void getMaxMessageShouldReturnDefaultWhenNoValue() throws Exception {
+        perUserMaxQuotaManager.setDefaultMaxMessage(36);
+        assertThat(perUserMaxQuotaManager.getMaxMessage(quotaRoot)).isEqualTo(36);
+    }
+
+    @Test
+    public void getMaxStorageShouldReturnDefaultWhenNoValue() throws Exception {
+        perUserMaxQuotaManager.setDefaultMaxStorage(36);
+        assertThat(perUserMaxQuotaManager.getMaxStorage(quotaRoot)).isEqualTo(36);
+    }
+
+    @Test
+    public void getMaxMessageShouldReturnProvidedValue() throws Exception {
+        perUserMaxQuotaManager.setMaxMessage(quotaRoot, 36);
+        assertThat(perUserMaxQuotaManager.getMaxMessage(quotaRoot)).isEqualTo(36);
+    }
+
+    @Test
+    public void getMaxStorageShouldReturnProvidedValue() throws Exception {
+        perUserMaxQuotaManager.setMaxStorage(quotaRoot, 36);
+        assertThat(perUserMaxQuotaManager.getMaxStorage(quotaRoot)).isEqualTo(36);
+    }
+
+}



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