james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieu...@apache.org
Subject svn commit: r1164981 [5/5] - in /james/mailbox/trunk: ./ hbase/ hbase/src/ hbase/src/main/ hbase/src/main/config/ hbase/src/main/java/ hbase/src/main/java/org/ hbase/src/main/java/org/apache/ hbase/src/main/java/org/apache/james/ hbase/src/main/java/or...
Date Sun, 04 Sep 2011 09:49:16 GMT
Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseClusterSingleton.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseClusterSingleton.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseClusterSingleton.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseClusterSingleton.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,94 @@
+/****************************************************************
+ * 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.hbase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+
+import static org.apache.james.mailbox.hbase.HBaseNames.*;
+
+/**
+ * Class that will creates a single connection to a HBaseCluster.
+ */
+public class HBaseClusterSingleton {
+
+    private static HBaseClusterSingleton cluster = null;
+    private MiniHBaseCluster hbaseCluster;
+    private Configuration conf;
+    /** Set this to false if you wish to test it against a real cluster.
+     * In that case you should provide the configuration file for the real
+     * cluster on the classpath. 
+     */
+    public static boolean useMiniCluster = true;
+
+    public static synchronized Configuration build() throws Exception {
+        if (cluster == null) {
+            cluster = new HBaseClusterSingleton(useMiniCluster);
+        }
+        return cluster.getConf();
+    }
+
+    public HBaseClusterSingleton(boolean useMiniCluster) throws Exception {
+        if (useMiniCluster) {
+            HBaseTestingUtility htu = new HBaseTestingUtility();
+            htu.getConfiguration().setBoolean("dfs.support.append", true);
+            try {
+                hbaseCluster = htu.startMiniCluster();
+                conf = hbaseCluster.getConfiguration();
+            } catch (Exception e) {
+                throw new Exception("Error starting MiniCluster ", e);
+            }
+        } else {
+            conf = HBaseConfiguration.create();
+        }
+    }
+
+    public Configuration getConf() {
+        return conf;
+    }
+
+    public static void resetTables(Configuration conf) throws Exception {
+        HBaseAdmin hbaseAdmin = new HBaseAdmin(conf);
+        if (hbaseAdmin.tableExists(MAILBOXES_TABLE)) {
+            hbaseAdmin.disableTable(MAILBOXES_TABLE);
+            hbaseAdmin.deleteTable(MAILBOXES_TABLE);
+        }
+        if (hbaseAdmin.tableExists(MESSAGES_TABLE)) {
+            hbaseAdmin.disableTable(MESSAGES_TABLE);
+            hbaseAdmin.deleteTable(MESSAGES_TABLE);
+        }
+        if (hbaseAdmin.tableExists(SUBSCRIPTIONS_TABLE)) {
+            hbaseAdmin.disableTable(SUBSCRIPTIONS_TABLE);
+            hbaseAdmin.deleteTable(SUBSCRIPTIONS_TABLE);
+        }
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        super.finalize();
+        if (useMiniCluster) {
+            if (hbaseCluster != null) {
+                hbaseCluster.shutdown();
+            }
+        }
+    }
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,92 @@
+/****************************************************************
+ * 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.hbase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.james.mailbox.AbstractMailboxManagerTest;
+import org.apache.james.mailbox.BadCredentialsException;
+import org.apache.james.mailbox.MailboxException;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.hbase.mail.HBaseModSeqProvider;
+import org.apache.james.mailbox.hbase.mail.HBaseUidProvider;
+import org.junit.After;
+import org.junit.Before;
+import org.slf4j.LoggerFactory;
+
+/**
+ * HBaseMailboxManagerTest that extends the StoreMailboxManagerTest.
+ *  
+ */
+public class HBaseMailboxManagerTest extends AbstractMailboxManagerTest {
+
+    private Configuration conf;
+    /**
+     * Setup the mailboxManager.
+     
+     * @throws Exception
+     */
+    @Before
+    public void setup() throws Exception {
+        conf = HBaseClusterSingleton.build();
+        HBaseClusterSingleton.resetTables(conf);
+        createMailboxManager();
+    }
+
+    /**
+     * Close the system session and entityManagerFactory
+     * 
+     * @throws MailboxException 
+     * @throws BadCredentialsException 
+     */
+    @After
+    public void tearDown() throws Exception {
+        deleteAllMailboxes();
+        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
+        session.close();
+        HBaseClusterSingleton.resetTables(conf);
+    }
+
+    /* (non-Javadoc)i deve
+     * @see org.apache.james.mailbox.MailboxManagerTest#createMailboxManager()
+     */
+    @Override
+    protected void createMailboxManager() throws MailboxException{
+        HBaseUidProvider uidProvider = new HBaseUidProvider(conf);
+        HBaseModSeqProvider modSeqProvider = new HBaseModSeqProvider(conf);
+        HBaseMailboxSessionMapperFactory mf = new HBaseMailboxSessionMapperFactory(conf, uidProvider, modSeqProvider);
+        
+        HBaseMailboxManager mailboxManagerLocal = new HBaseMailboxManager(mf, null);
+        mailboxManagerLocal.init();
+
+        setMailboxManager(mailboxManagerLocal);
+
+        deleteAllMailboxes();
+    }
+
+    private void deleteAllMailboxes() throws BadCredentialsException, MailboxException {
+        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
+        try {
+            ((HBaseMailboxManager) mailboxManager).deleteEverything(session);
+        } catch (MailboxException e) {
+            e.printStackTrace();
+        }
+        session.close();
+    }
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,123 @@
+/****************************************************************
+ * 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.hbase;
+
+import java.util.UUID;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.hbase.mail.HBaseModSeqProvider;
+import org.apache.james.mailbox.hbase.mail.HBaseUidProvider;
+import org.apache.james.mailbox.store.mail.MailboxMapper;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.ModSeqProvider;
+import org.apache.james.mailbox.store.mail.UidProvider;
+import org.apache.james.mailbox.store.user.SubscriptionMapper;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * 
+ */
+public class HBaseMailboxSessionMapperFactoryTest {
+
+    private final static org.slf4j.Logger logger = LoggerFactory.getLogger(HBaseMailboxSessionMapperFactoryTest.class);
+    private static Configuration conf;
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+        conf = HBaseClusterSingleton.build();
+        HBaseClusterSingleton.resetTables(conf);
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+        
+    }
+
+     /**
+     * Test of createMessageMapper method, of class HBaseMailboxSessionMapperFactory.
+     */
+    @Test
+    public void testCreateMessageMapper() throws Exception {
+        System.out.println("createMessageMapper");
+        MailboxSession session = null;
+        HBaseMailboxSessionMapperFactory instance = new HBaseMailboxSessionMapperFactory(conf, null , null);
+        MessageMapper<UUID> messageMapper = instance.createMessageMapper(session); 
+        assertNotNull(messageMapper);
+        assertTrue(messageMapper instanceof MessageMapper);
+    }
+
+    /**
+     * Test of createMailboxMapper method, of class HBaseMailboxSessionMapperFactory.
+     */
+    @Test
+    public void testCreateMailboxMapper() throws Exception {
+        System.out.println("createMailboxMapper");
+        MailboxSession session = null;
+        HBaseMailboxSessionMapperFactory instance = new HBaseMailboxSessionMapperFactory(conf, null , null);
+        MailboxMapper<UUID> mailboxMapper = instance.createMailboxMapper(session); 
+        assertNotNull(mailboxMapper);
+        assertTrue(mailboxMapper instanceof MailboxMapper);
+    }
+
+    /**
+     * Test of createSubscriptionMapper method, of class HBaseMailboxSessionMapperFactory.
+     */
+    @Test
+    public void testCreateSubscriptionMapper() throws Exception {
+        System.out.println("createSubscriptionMapper");
+        MailboxSession session = null;
+        HBaseMailboxSessionMapperFactory instance = new HBaseMailboxSessionMapperFactory(conf, null , null);
+        SubscriptionMapper subscriptionMapper = instance.createSubscriptionMapper(session); 
+        assertNotNull(subscriptionMapper);
+        assertTrue(subscriptionMapper instanceof SubscriptionMapper);
+    }
+
+    /**
+     * Test of getModSeqProvider method, of class HBaseMailboxSessionMapperFactory.
+     */
+    @Test
+    public void testGetModSeqProvider() {
+        System.out.println("getModSeqProvider");
+        ModSeqProvider<UUID> expResult = new HBaseModSeqProvider(conf);
+        HBaseMailboxSessionMapperFactory instance = new HBaseMailboxSessionMapperFactory(conf, null , expResult);
+        ModSeqProvider<UUID> result = instance.getModSeqProvider();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of getUidProvider method, of class HBaseMailboxSessionMapperFactory.
+     */
+    @Test
+    public void testGetUidProvider() {
+        System.out.println("getUidProvider");
+        UidProvider<UUID> expResult = new HBaseUidProvider(conf);
+        HBaseMailboxSessionMapperFactory instance = new HBaseMailboxSessionMapperFactory(conf, expResult , null);        
+        UidProvider<UUID> result = instance.getUidProvider();
+        assertEquals(expResult, result);
+    }
+    
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseUtilsTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseUtilsTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseUtilsTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseUtilsTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,138 @@
+/****************************************************************
+ * 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.hbase;
+
+import java.util.Date;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.james.mailbox.MailboxPath;
+import java.util.UUID;
+import javax.mail.Flags;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.james.mailbox.hbase.mail.model.HBaseMailbox;
+import org.apache.james.mailbox.store.mail.model.Property;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMessage;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleProperty;
+import org.apache.james.mailbox.store.user.model.Subscription;
+import org.apache.james.mailbox.store.user.model.impl.SimpleSubscription;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.apache.james.mailbox.hbase.HBaseUtils.*;
+import static org.apache.james.mailbox.hbase.HBaseNames.*;
+import static org.apache.james.mailbox.hbase.FlagConvertor.*;
+import static org.apache.james.mailbox.hbase.PropertyConvertor.*;
+
+/**
+ * Tests for HBase Mailbox store utility methods .
+ * @author ieugen
+ */
+public class HBaseUtilsTest {
+
+    /**
+     * Test of mailboxRowKey method, of class HBaseMailbox.
+     */
+    @Test
+    public void testRowKey_All() {
+        System.out.println("getRowKey and UUIDFromRowKey");
+        final HBaseMailbox mailbox = new HBaseMailbox(new MailboxPath("gsoc", "ieugen", "INBOX"), 1234);
+        UUID uuid = mailbox.getMailboxId();
+        byte[] expResult = mailboxRowKey(uuid);
+        byte[] result = mailboxRowKey(mailbox.getMailboxId());
+        assertArrayEquals(expResult, result);
+
+        UUID newUUID = UUIDFromRowKey(result);
+        assertEquals(uuid, newUUID);
+
+        newUUID = UUIDFromRowKey(expResult);
+        assertEquals(uuid, newUUID);
+    }
+
+    /**
+     * Test of metadataToPut method, of class HBaseMailbox.
+     */
+    @Test
+    public void testMailboxToPut() {
+        System.out.println("mailboxToPut");
+        final HBaseMailbox instance = new HBaseMailbox(new MailboxPath("gsoc", "ieugen", "INBOX"), 1234);
+
+        Put result = toPut(instance);
+        assertArrayEquals(mailboxRowKey(instance.getMailboxId()), result.getRow());
+        assertTrue(result.has(MAILBOX_CF, MAILBOX_USER, Bytes.toBytes(instance.getUser())));
+        assertTrue(result.has(MAILBOX_CF, MAILBOX_NAME, Bytes.toBytes(instance.getName())));
+        assertTrue(result.has(MAILBOX_CF, MAILBOX_NAMESPACE, Bytes.toBytes(instance.getNamespace())));
+        assertTrue(result.has(MAILBOX_CF, MAILBOX_UIDVALIDITY, Bytes.toBytes(instance.getUidValidity())));
+        assertTrue(result.has(MAILBOX_CF, MAILBOX_LASTUID, Bytes.toBytes(instance.getLastUid())));
+        assertTrue(result.has(MAILBOX_CF, MAILBOX_HIGHEST_MODSEQ, Bytes.toBytes(instance.getHighestModSeq())));
+        assertTrue(result.has(MAILBOX_CF, MAILBOX_MESSAGE_COUNT, Bytes.toBytes(0L)));
+    }
+
+    /**
+     * Test of metadataToPut method for message.
+     */
+//    @Test
+    public void testMessageToPut() {
+        System.out.println("messageToPut");
+        // left to implement
+    }
+
+    @Test
+    public void testPropertyToBytes() {
+        final Property prop1 = new SimpleProperty("nspace", "localName", "test");
+        byte[] value = getValue(prop1);
+        final Property prop2 = getProperty(value);
+        assertEquals(prop1.getNamespace(), prop2.getNamespace());
+        assertEquals(prop1.getLocalName(), prop2.getLocalName());
+        assertEquals(prop1.getValue(), prop2.getValue());
+    }
+
+    @Test
+    public void testSubscriptionToPut() {
+        System.out.println("subscription toPut");
+        Subscription subscription = new SimpleSubscription("ieugen", "INBOX");
+        Put put = toPut(subscription);
+        assertArrayEquals(Bytes.toBytes(subscription.getUser()), put.getRow());
+        assertTrue(put.has(SUBSCRIPTION_CF, Bytes.toBytes(subscription.getMailbox()), MARKER_PRESENT));
+    }
+
+    @Test
+    public void testFlagsToPut() {
+        System.out.println("flagsToPut");
+
+        final Flags flags = new Flags();
+        flags.add(Flags.Flag.SEEN);
+        flags.add(Flags.Flag.DRAFT);
+        flags.add(Flags.Flag.RECENT);
+        flags.add(Flags.Flag.FLAGGED);
+        flags.add("userFlag1");
+        flags.add("userFlag2");
+        UUID uuid = UUID.randomUUID();
+        final SimpleMessage message = new SimpleMessage(new Date(), 100, 10, null, flags, new PropertyBuilder(), uuid);
+        Put put = flagsToPut(message, flags);
+        //test for the system flags
+        assertTrue(put.has(MESSAGES_META_CF, FLAGS_SEEN, MARKER_PRESENT));
+        assertTrue(put.has(MESSAGES_META_CF, FLAGS_DRAFT, MARKER_PRESENT));
+        assertTrue(put.has(MESSAGES_META_CF, FLAGS_RECENT, MARKER_PRESENT));
+        assertTrue(put.has(MESSAGES_META_CF, FLAGS_FLAGGED, MARKER_PRESENT));
+        assertTrue(put.has(MESSAGES_META_CF, FLAGS_ANSWERED, MARKER_MISSING));
+        assertTrue(put.has(MESSAGES_META_CF, FLAGS_DELETED, MARKER_MISSING));
+        assertTrue(put.has(MESSAGES_META_CF, userFlagToBytes("userFlag1"), MARKER_PRESENT));
+        assertTrue(put.has(MESSAGES_META_CF, userFlagToBytes("userFlag2"), MARKER_PRESENT));
+    }
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,310 @@
+/****************************************************************
+ * 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.hbase.mail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import org.apache.james.mailbox.hbase.io.ChunkInputStream;
+import org.apache.james.mailbox.hbase.io.ChunkOutputStream;
+import java.util.logging.Level;
+import org.apache.james.mailbox.MailboxException;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import java.util.UUID;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.james.mailbox.MailboxNotFoundException;
+import org.apache.james.mailbox.MailboxPath;
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
+import org.apache.james.mailbox.hbase.HBaseMailboxSessionMapperFactory;
+import org.apache.james.mailbox.hbase.mail.model.HBaseMailbox;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import static org.apache.james.mailbox.hbase.HBaseUtils.*;
+import static org.apache.james.mailbox.hbase.HBaseNames.*;
+
+/**
+ * HBaseMailboxMapper unit tests.
+ * @author ieugen
+ */
+public class HBaseMailboxMapperTest {
+
+    private static final Logger logger = Logger.getLogger("HBaseMailboxMapperTest");
+    /** testing mini-cluster */
+    private static Configuration conf;
+    private static HBaseUidProvider uidProvider;
+    private static HBaseModSeqProvider modSeqProvider;
+    private static HBaseMailboxSessionMapperFactory mapperFactory;
+    private static HBaseMailboxMapper mapper;
+    private static List<HBaseMailbox> mailboxList;
+    private static List<MailboxPath> pathsList;
+    private static final int NAMESPACES = 5;
+    private static final int USERS = 5;
+    private static final int MAILBOXES = 5;
+    private static final char SEPARATOR = '%';
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        // start the test cluster 
+        conf = HBaseClusterSingleton.build();
+        HBaseClusterSingleton.resetTables(conf);
+        uidProvider = new HBaseUidProvider(conf);
+        modSeqProvider = new HBaseModSeqProvider(conf);
+        mapperFactory = new HBaseMailboxSessionMapperFactory(conf, uidProvider, modSeqProvider);
+        fillMailboxList();
+        mapper = new HBaseMailboxMapper(conf);
+        for (HBaseMailbox mailbox : mailboxList) {
+            mapper.save(mailbox);
+        }
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+    }
+
+    private static void fillMailboxList() {
+        mailboxList = new ArrayList<HBaseMailbox>();
+        pathsList = new ArrayList<MailboxPath>();
+        MailboxPath path;
+        String name;
+        for (int i = 0; i < NAMESPACES; i++) {
+            for (int j = 0; j < USERS; j++) {
+                for (int k = 0; k < MAILBOXES; k++) {
+                    if (j == 3) {
+                        name = "test" + SEPARATOR + "subbox" + k;
+                    } else {
+                        name = "mailbox" + k;
+                    }
+                    path = new MailboxPath("namespace" + i, "user" + j, name);
+                    pathsList.add(path);
+                    mailboxList.add(new HBaseMailbox(path, 13));
+                }
+            }
+        }
+
+        logger.log(Level.INFO, "Created test case with {0} mailboxes and {1} paths", new Object[]{mailboxList.size(), pathsList.size()});
+    }
+
+    private void addMailbox(HBaseMailbox mailbox) throws MailboxException {
+        mailboxList.add(mailbox);
+        pathsList.add(new MailboxPath(mailbox.getNamespace(), mailbox.getUser(), mailbox.getName()));
+        mapper = new HBaseMailboxMapper(conf);
+        mapper.save(mailbox);
+        logger.log(Level.INFO, "Added new mailbox: {0} paths: {1}", new Object[]{mailboxList.size(), pathsList.size()});
+    }
+
+    /**
+     * Test of findMailboxByPath method, of class HBaseMailboxMapper.
+     */
+    @Test
+    public void testFindMailboxByPath() throws Exception {
+        System.out.println("findMailboxByPath");
+        HBaseMailbox mailbox;
+        for (MailboxPath path : pathsList) {
+            System.out.println("Searching for " + path);
+            mailbox = (HBaseMailbox) mapper.findMailboxByPath(path);
+            assertEquals(path, new MailboxPath(mailbox.getNamespace(), mailbox.getUser(), mailbox.getName()));
+        }
+    }
+
+    /**
+     * Test of findMailboxWithPathLike method, of class HBaseMailboxMapper.
+     */
+    @Test
+    public void testFindMailboxWithPathLike() throws Exception {
+        System.out.println("findMailboxWithPathLike");
+        MailboxPath path = pathsList.get(pathsList.size() / 2);
+
+        List<Mailbox<UUID>> result = mapper.findMailboxWithPathLike(path);
+        assertEquals(1, result.size());
+
+        int start = 3;
+        int end = 7;
+        MailboxPath newPath;
+
+        for (int i = start; i < end; i++) {
+            newPath = new MailboxPath(path);
+            newPath.setName(i + newPath.getName() + " " + i);
+            // test for paths with null user 
+            if (i % 2 == 0) {
+                newPath.setUser(null);
+            }
+            addMailbox(new HBaseMailbox(newPath, 1234));
+        }
+        result = mapper.findMailboxWithPathLike(path);
+        assertEquals(end - start + 1, result.size());
+    }
+
+    /**
+     * Test of list method, of class HBaseMailboxMapper.
+     */
+    @Test
+    public void testList() throws Exception {
+        System.out.println("list");
+        List<Mailbox<UUID>> result = mapper.list();
+        assertEquals(mailboxList.size(), result.size());
+
+    }
+
+    /**
+     * Test of save method, of class HBaseMailboxMapper.
+     */
+    @Test
+    public void testSave() throws Exception {
+        System.out.println("save and mailboxFromResult");
+        HTable mailboxes = new HTable(conf, MAILBOXES_TABLE);
+
+        HBaseMailbox mlbx = mailboxList.get(mailboxList.size() / 2);
+
+        Get get = new Get(mailboxRowKey(mlbx.getMailboxId()));
+        // get all columns for the DATA column family
+        get.addFamily(Bytes.toBytes("DATA"));
+
+        Result result = mailboxes.get(get);
+        HBaseMailbox newValue = (HBaseMailbox) mailboxFromResult(result);
+        assertEquals(mlbx, newValue);
+        assertEquals(mlbx.getUser(), newValue.getUser());
+        assertEquals(mlbx.getName(), newValue.getName());
+        assertEquals(mlbx.getNamespace(), newValue.getNamespace());
+        assertEquals(mlbx.getMailboxId(), newValue.getMailboxId());
+        assertEquals(mlbx.getLastUid(), newValue.getLastUid());
+        assertEquals(mlbx.getUidValidity(), newValue.getUidValidity());
+        assertEquals(mlbx.getHighestModSeq(), newValue.getHighestModSeq());
+        assertArrayEquals(mailboxRowKey(mlbx.getMailboxId()), mailboxRowKey(newValue.getMailboxId()));
+    }
+
+    /**
+     * Test of delete method, of class HBaseMailboxMapper.
+     */
+    @Test
+    public void testDelete() throws Exception {
+        System.out.println("delete");
+        // delete last 5 mailboxes from mailboxList
+        int offset = 5;
+        int notFoundCount = 0;
+
+        Iterator<HBaseMailbox> iterator = mailboxList.subList(mailboxList.size() - offset, mailboxList.size()).iterator();
+
+        while (iterator.hasNext()) {
+            HBaseMailbox mailbox = iterator.next();
+            mapper.delete(mailbox);
+            iterator.remove();
+            MailboxPath path = new MailboxPath(mailbox.getNamespace(), mailbox.getUser(), mailbox.getName());
+            pathsList.remove(path);
+            logger.log(Level.INFO, "Removing mailbox: {0}", path);
+            try {
+                mapper.findMailboxByPath(path);
+            } catch (MailboxNotFoundException e) {
+                logger.log(Level.INFO, "Succesfully removed {0}", mailbox);
+                notFoundCount++;
+            }
+        }
+        assertEquals(offset, notFoundCount);
+        assertEquals(mailboxList.size(), mapper.list().size());
+    }
+
+    /**
+     * Test of hasChildren method, of class HBaseMailboxMapper.
+     */
+    @Test
+    public void testHasChildren() throws Exception {
+        System.out.println("hasChildren");
+        String oldName;
+        for (MailboxPath path : pathsList) {
+            HBaseMailbox mailbox = new HBaseMailbox(path, 12455);
+            oldName = mailbox.getName();
+            if (path.getUser().equals("user3")) {
+                mailbox.setName("test");
+            }
+            boolean result = mapper.hasChildren(mailbox, SEPARATOR);
+            mailbox.setName(oldName);
+            if (path.getUser().equals("user3")) {
+                assertTrue(result);
+            } else {
+                assertFalse(result);
+            }
+
+        }
+    }
+
+    /**
+     * Test of deleteAllMemberships method, of class HBaseMailboxMapper.
+     */
+//    @Test
+    public void testDeleteAllMemberships() {
+        System.out.println("deleteAllMemberships");
+        fail("Not yet implemented");
+    }
+
+    /**
+     * Test of deleteAllMailboxes method, of class HBaseMailboxMapper.
+     */
+    @Test
+    public void testDeleteAllMailboxes() throws MailboxException {
+        System.out.println("deleteAllMailboxes");
+        mapper.deleteAllMailboxes();
+        assertEquals(0, mapper.list().size());
+        fillMailboxList();
+    }
+
+    @Test
+    public void chunkStream() throws IOException {
+        System.out.println("Checking ChunkOutpuStream and ChunkInputStream");
+        final String original = "This is a proper test for the HBase ChunkInputStream and"
+                + "ChunkOutputStream. This text must be larger than the chunk size so we write"
+                + "and read more then one chunk size. I think that a few more lore ipsum lines"
+                + "will be enough."
+                + "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor "
+                + "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis "
+                + "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
+                + "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu "
+                + "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa"
+                + " qui officia deserunt mollit anim id est laborum";
+        byte[] data = Bytes.toBytes(original);
+        // we make the column size = 10 bytes
+        ChunkOutputStream out = new ChunkOutputStream(conf,
+                MESSAGES_TABLE, MESSAGE_DATA_BODY, Bytes.toBytes("10"), 10);
+        ChunkInputStream in = new ChunkInputStream(conf,
+                MESSAGES_TABLE, MESSAGE_DATA_BODY, Bytes.toBytes("10"));
+        //create the stream
+        ByteArrayInputStream bin = new ByteArrayInputStream(data);
+        ByteArrayOutputStream bout = new ByteArrayOutputStream(data.length);
+        int b;
+        while ((b = bin.read()) != -1) {
+            out.write(b);
+        }
+        out.close();
+        while ((b = in.read()) != -1) {
+            bout.write(b);
+        }
+        String s = bout.toString();
+        assertTrue(original.equals(s));
+    }
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapperTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapperTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapperTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapperTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,193 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.apache.james.mailbox.hbase.mail;
+
+import org.junit.Test;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.logging.Logger;
+import org.apache.james.mailbox.MailboxPath;
+import org.apache.james.mailbox.hbase.mail.model.HBaseMailbox;
+import org.apache.james.mailbox.hbase.HBaseMailboxSessionMapperFactory;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import javax.mail.Flags;
+import javax.mail.internet.SharedInputStream;
+import javax.mail.util.SharedByteArrayInputStream;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.Message;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMessage;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import static org.junit.Assert.*;
+
+/**
+ * Unit tests for HBaseMessageMapper.
+ * @author ieugen
+ */
+public class HBaseMessageMapperTest {
+
+    private static final Logger logger = Logger.getLogger("HBaseMailboxMapperTest");
+    private static HBaseUidProvider uidProvider;
+    private static HBaseModSeqProvider modSeqProvider;
+    private static HBaseMailboxSessionMapperFactory mapperFactory;
+    private static HBaseMailboxMapper mailboxMapper;
+    private static HBaseMessageMapper messageMapper;
+    private static final List<MailboxPath> mboxPaths = new ArrayList<MailboxPath>();
+    private static final List<Mailbox<UUID>> mboxes = new ArrayList<Mailbox<UUID>>();
+    private static final List<Message<UUID>> messages = new ArrayList<Message<UUID>>();
+    private static final int pathAndMboxCount = 5;
+    private static Configuration conf;
+    /* we mock a simple message content*/
+    private static final byte[] messageTemplate = Bytes.toBytes(
+            "Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)\n"
+            + "From: Fred Foobar <foobar@Blurdybloop.COM>\n"
+            + "Subject: Test 02\n"
+            + "To: mooch@owatagu.siam.edu\n"
+            + "Message-Id: <B27397-0100000@Blurdybloop.COM>\n"
+            + "MIME-Version: 1.0\n"
+            + "Content-Type: TEXT/PLAIN; CHARSET=US-ASCII\n"
+            + "\n"
+            + "Test\n"
+            + "\n.");
+    private static SharedInputStream content = new SharedByteArrayInputStream(messageTemplate);
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+        conf = HBaseClusterSingleton.build();
+        HBaseClusterSingleton.resetTables(conf);
+        uidProvider = new HBaseUidProvider(conf);
+        modSeqProvider = new HBaseModSeqProvider(conf);
+        mapperFactory = new HBaseMailboxSessionMapperFactory(conf, uidProvider, modSeqProvider);
+        generateTestData();
+        mailboxMapper = new HBaseMailboxMapper(conf);
+        MailboxSession session = new MockMailboxSession("ieugen");
+        messageMapper = new HBaseMessageMapper(session, uidProvider, modSeqProvider, conf);
+        for (int i = 0; i < messages.size(); i++) {
+            messageMapper.add(mboxes.get(1), messages.get(i));
+        }
+
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+
+    public static void generateTestData() {
+        Random random = new Random();
+        MailboxPath mboxPath;
+        PropertyBuilder propBuilder = new PropertyBuilder();
+
+        for (int i = 0; i < pathAndMboxCount; i++) {
+            if (i % 2 == 0) {
+                mboxPath = new MailboxPath("gsoc", "ieugen" + i, "INBOX");
+            } else {
+                mboxPath = new MailboxPath("gsoc", "ieugen" + i, "INBOX.box" + i);
+            }
+            mboxPaths.add(mboxPath);
+            mboxes.add(new HBaseMailbox(mboxPaths.get(i), random.nextLong()));
+            propBuilder.setProperty("gsoc", "prop" + i, "value");
+        }
+        propBuilder.setMediaType("text");
+        propBuilder.setSubType("html");
+        propBuilder.setTextualLineCount(2L);
+
+        SimpleMessage<UUID> myMsg;
+        Flags flags = new Flags(Flags.Flag.RECENT);
+        Date today = new Date();
+
+        for (int i = 0; i < pathAndMboxCount * 2; i++) {
+            myMsg = new SimpleMessage<UUID>(today, messageTemplate.length,
+                    messageTemplate.length - 20, content, flags, propBuilder,
+                    mboxes.get(1).getMailboxId());
+            if (i == pathAndMboxCount * 2 - 1) {
+                flags.add(Flags.Flag.SEEN);
+                flags.remove(Flags.Flag.RECENT);
+                myMsg.setFlags(flags);
+            }
+            messages.add(myMsg);
+        }
+    }
+
+
+    /**
+     * Test of countMessagesInMailbox method, of class HBaseMessageMapper.
+     */
+    @Test
+    public void testCountMessagesInMailbox() throws Exception {
+        System.out.println("countMessagesInMailbox");
+        long messageCount = messageMapper.countMessagesInMailbox(mboxes.get(1));
+        assertEquals(messages.size(), messageCount);
+    }
+
+    /**
+     * Test of countUnseenMessagesInMailbox method, of class HBaseMessageMapper.
+     */
+    @Test
+    public void testCountUnseenMessagesInMailbox() throws Exception {
+        System.out.println("countUnseenMessagesInMailbox");
+        long unseen = messageMapper.countUnseenMessagesInMailbox(mboxes.get(1));
+        assertEquals(messages.size() - 1, unseen);
+    }
+
+    /**
+     * Test of findFirstUnseenMessageUid method, of class HBaseMessageMapper.
+     */
+    @Test
+    public void testFindFirstUnseenMessageUid() throws Exception {
+        System.out.println("findFirstUnseenMessageUid");
+        long uid = messageMapper.findFirstUnseenMessageUid(mboxes.get(1));
+        assertEquals(1, uid);
+    }
+
+    /**
+     * Test of findRecentMessageUidsInMailbox method, of class HBaseMessageMapper.
+     */
+    @Test
+    public void testFindRecentMessageUidsInMailbox() throws Exception {
+        System.out.println("findRecentMessageUidsInMailbox");
+        List<Long> recentMessages = messageMapper.findRecentMessageUidsInMailbox(mboxes.get(1));
+        assertEquals(messages.size() - 1, recentMessages.size());
+    }
+
+    /**
+     * Test of add method, of class HBaseMessageMapper.
+     */
+    @Test
+    public void testAdd() throws Exception {
+        System.out.println("add");
+        // The tables should be deleted every time the tests run.
+        long msgCount = messageMapper.countMessagesInMailbox(mboxes.get(1));
+        System.out.println(msgCount + " " + messages.size());
+        assertEquals(messages.size(), msgCount);
+    }
+
+    /**
+     * Test of getLastUid method, of class HBaseMessageMapper.
+     */
+    @Test
+    public void testGetLastUid() throws Exception {
+        System.out.println("getLastUid");
+        long lastUid = messageMapper.getLastUid(mboxes.get(1));
+        assertEquals(messages.size(), lastUid);
+    }
+
+    /**
+     * Test of getHighestModSeq method, of class HBaseMessageMapper.
+     */
+    @Test
+    public void testGetHighestModSeq() throws Exception {
+        System.out.println("getHighestModSeq");
+        long highestModSeq = messageMapper.getHighestModSeq(mboxes.get(1));
+        assertEquals(messages.size(), highestModSeq);
+    }
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseUidAndModSeqProviderTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseUidAndModSeqProviderTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseUidAndModSeqProviderTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseUidAndModSeqProviderTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,167 @@
+/****************************************************************
+ * 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.hbase.mail;
+
+import java.util.logging.Logger;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.james.mailbox.hbase.mail.model.HBaseMailbox;
+import org.apache.james.mailbox.hbase.HBaseMailboxSessionMapperFactory;
+import org.apache.james.mailbox.MailboxPath;
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Unit tests for UidProvider. 
+ * @author ieugen
+ */
+public class HBaseUidAndModSeqProviderTest {
+
+    private static final Logger logger = Logger.getLogger("HBaseUidProviderTest");
+    /** testing mini-cluster */
+    private static Configuration conf;
+    private static HBaseUidProvider uidProvider;
+    private static HBaseModSeqProvider modSeqProvider;
+    private static HBaseMailboxMapper mapper;
+    private static HBaseMailboxSessionMapperFactory mapperFactory;
+    private static List<HBaseMailbox> mailboxList;
+    private static List<MailboxPath> pathsList;
+    private static final int NAMESPACES = 5;
+    private static final int USERS = 5;
+    private static final int MAILBOXES = 5;
+    private static final char SEPARATOR = '%';
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+        // start the test cluster 
+        conf = HBaseClusterSingleton.build();
+        HBaseClusterSingleton.resetTables(conf);
+        uidProvider = new HBaseUidProvider(conf);
+        modSeqProvider = new HBaseModSeqProvider(conf);
+        mapperFactory = new HBaseMailboxSessionMapperFactory(conf, uidProvider, modSeqProvider);
+        mapper = new HBaseMailboxMapper(conf);
+        fillMailboxList();
+        for (HBaseMailbox mailbox : mailboxList) {
+            mapper.save(mailbox);
+        }
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+
+    private static void fillMailboxList() {
+        mailboxList = new ArrayList<HBaseMailbox>();
+        pathsList = new ArrayList<MailboxPath>();
+        MailboxPath path;
+        String name;
+        for (int i = 0; i < NAMESPACES; i++) {
+            for (int j = 0; j < USERS; j++) {
+                for (int k = 0; k < MAILBOXES; k++) {
+                    if (j == 3) {
+                        name = "test" + SEPARATOR + "subbox" + k;
+                    } else {
+                        name = "mailbox" + k;
+                    }
+                    path = new MailboxPath("namespace" + i, "user" + j, name);
+                    pathsList.add(path);
+                    mailboxList.add(new HBaseMailbox(path, 13));
+                }
+            }
+        }
+
+        logger.log(Level.INFO, "Created test case with {0} mailboxes and {1} paths", new Object[]{mailboxList.size(), pathsList.size()});
+    }
+
+    /**
+     * Test of lastUid method, of class HBaseUidProvider.
+     */
+    @Test
+    public void testLastUid() throws Exception {
+        System.out.println("lastUid");
+        HBaseMailbox mailbox = mailboxList.get(mailboxList.size() / 2);
+        MailboxPath path = new MailboxPath("gsoc", "ieugen", "Trash");
+        HBaseMailbox newBox = new HBaseMailbox(path, 1234);
+        mapper.save(newBox);
+        mailboxList.add(newBox);
+        pathsList.add(path);
+
+        long result = uidProvider.lastUid(null, newBox);
+        assertEquals(0, result);
+        for (int i = 1; i < 10; i++) {
+            long uid = uidProvider.nextUid(null, newBox);
+            assertEquals(uid, uidProvider.lastUid(null, newBox));
+        }
+    }
+
+    /**
+     * Test of nextUid method, of class HBaseUidProvider.
+     */
+    @Test
+    public void testNextUid() throws Exception {
+        System.out.println("nextUid");
+        HBaseMailbox mailbox = mailboxList.get(mailboxList.size() / 2);
+        long lastUid = uidProvider.lastUid(null, mailbox);
+        for (int i = (int) lastUid + 1; i < (lastUid + 10); i++) {
+            long result = uidProvider.nextUid(null, mailbox);
+            assertEquals(i, result);
+        }
+    }
+
+    /**
+     * Test of highestModSeq method, of class HBaseModSeqProvider.
+     */
+    @Test
+    public void testHighestModSeq() throws Exception {
+        System.out.println("highestModSeq");
+        System.out.println("lastUid");
+        HBaseMailbox mailbox = mailboxList.get(mailboxList.size() / 2);
+        MailboxPath path = new MailboxPath("gsoc", "ieugen", "Trash");
+        HBaseMailbox newBox = new HBaseMailbox(path, 1234);
+        mapper.save(newBox);
+        mailboxList.add(newBox);
+        pathsList.add(path);
+
+        long result = modSeqProvider.highestModSeq(null, newBox);
+        assertEquals(0, result);
+        for (int i = 1; i < 10; i++) {
+            long uid = modSeqProvider.nextModSeq(null, newBox);
+            assertEquals(uid, modSeqProvider.highestModSeq(null, newBox));
+        }
+    }
+
+    /**
+     * Test of nextModSeq method, of class HBaseModSeqProvider.
+     */
+    @Test
+    public void testNextModSeq() throws Exception {
+        System.out.println("nextModSeq");
+        HBaseMailbox mailbox = mailboxList.get(mailboxList.size() / 2);
+        long lastUid = modSeqProvider.highestModSeq(null, mailbox);
+        for (int i = (int) lastUid + 1; i < (lastUid + 10); i++) {
+            long result = modSeqProvider.nextModSeq(null, mailbox);
+            assertEquals(i, result);
+        }
+    }
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/model/HBaseMailboxTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/model/HBaseMailboxTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/model/HBaseMailboxTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/model/HBaseMailboxTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,162 @@
+/****************************************************************
+ * 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.hbase.mail.model;
+
+import java.util.UUID;
+import org.apache.james.mailbox.MailboxPath;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Unit tests for HBaseMailbox class.
+ * @author ieugen
+ */
+public class HBaseMailboxTest {
+
+    /**
+     * Test of getter and setter for MailboxId
+     */
+    @Test
+    public void testGetSetMailboxId() {
+        System.out.println("getSetMailboxId");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 10);
+
+        UUID expResult = UUID.randomUUID();
+        instance.setMailboxId(expResult);
+        assertEquals(expResult, instance.getMailboxId());
+
+    }
+
+    /**
+     * Test of getter and setter for Namespace, of class HBaseMailbox.
+     */
+    @Test
+    public void testGetSetNamespace() {
+        System.out.println("getSetNamespace");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 124566);
+        String result = instance.getNamespace();
+        assertEquals(mailboxPath.getNamespace(), result);
+
+        instance.setNamespace("newName");
+        assertEquals("newName", instance.getNamespace());
+
+    }
+
+    /**
+     * Test of getter and setter for User, of class HBaseMailbox.
+     */
+    @Test
+    public void testGetSetUser() {
+        System.out.println("getUser");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 12);
+        String result = instance.getUser();
+        assertEquals(mailboxPath.getUser(), result);
+
+        instance.setUser("eric");
+        assertEquals("eric", instance.getUser());
+    }
+
+    /**
+     * Test of getter and setter for Name, of class HBaseMailbox.
+     */
+    @Test
+    public void testGetSetName() {
+        System.out.println("getSetName");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 1677);
+        String result = instance.getName();
+        assertEquals(mailboxPath.getName(), result);
+
+        instance.setName("newINBOX");
+        assertEquals("newINBOX", instance.getName());
+    }
+
+    /**
+     * Test of getUidValidity method, of class HBaseMailbox.
+     */
+    @Test
+    public void testGetUidValidity() {
+        System.out.println("getUidValidity");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 123345);
+        long expResult = 123345L;
+        long result = instance.getUidValidity();
+        assertEquals(expResult, result);
+
+    }
+
+    /**
+     * Test of hashCode method, of class HBaseMailbox.
+     */
+    @Test
+    public void testHashCode() {
+        System.out.println("hashCode");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 1234);
+        // from the hashCode()
+        final int PRIME = 31;
+        int result = 1;
+        UUID mailboxId = instance.getMailboxId();
+        int expResult = PRIME * result + (int) (mailboxId.getMostSignificantBits() ^ (mailboxId.getMostSignificantBits() >>> 32));
+
+        assertEquals(expResult, instance.hashCode());
+    }
+
+    /**
+     * Test of equals method, of class HBaseMailbox.
+     */
+    @Test
+    public void testEquals() {
+        System.out.println("equals");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 12345);
+        final HBaseMailbox instance2 = new HBaseMailbox(mailboxPath, 12345);
+        instance2.setMailboxId(instance.getMailboxId());
+        assertEquals(instance, instance2);
+    }
+
+    /**
+     * Test of consumeUid method, of class HBaseMailbox.
+     */
+    @Test
+    public void testConsumeUid() {
+        System.out.println("consumeUid");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 10);
+        long expResult = instance.getLastUid() + 1;
+        long result = instance.consumeUid();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of consumeModSeq method, of class HBaseMailbox.
+     */
+    @Test
+    public void testConsumeModSeq() {
+        System.out.println("consumeModSeq");
+        final MailboxPath mailboxPath = new MailboxPath("gsoc", "ieugen", "INBOX");
+        final HBaseMailbox instance = new HBaseMailbox(mailboxPath, 10);
+        long expResult = instance.getHighestModSeq() + 1;
+        long result = instance.consumeModSeq();
+        assertEquals(expResult, result);
+    }
+}

Added: james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/user/HBaseSubscriptionMapperTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/user/HBaseSubscriptionMapperTest.java?rev=1164981&view=auto
==============================================================================
--- james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/user/HBaseSubscriptionMapperTest.java (added)
+++ james/mailbox/trunk/hbase/src/test/java/org/apache/james/mailbox/hbase/user/HBaseSubscriptionMapperTest.java Sun Sep  4 09:49:14 2011
@@ -0,0 +1,187 @@
+/****************************************************************
+ * 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.hbase.user;
+
+import java.util.List;
+import java.util.logging.Logger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.james.mailbox.store.user.model.impl.SimpleSubscription;
+import org.apache.james.mailbox.store.user.model.Subscription;
+import org.apache.james.mailbox.SubscriptionException;
+import org.apache.james.mailbox.hbase.HBaseMailboxSessionMapperFactory;
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.apache.james.mailbox.hbase.HBaseNames.*;
+
+/**
+ *
+ * @author ieugen
+ */
+public class HBaseSubscriptionMapperTest {
+    //TODO: move tests to a TestSuite so we reduce time by avoiding miniCluster restarts
+
+    private static final Logger logger = Logger.getLogger("HBaseSubscriptionMapperTest");
+    /** testing mini-cluster */
+    private static Configuration conf;
+    private static HBaseMailboxSessionMapperFactory mapperFactory;
+    private static HBaseSubscriptionMapper mapper;
+    private static Map<String, List<SimpleSubscription>> subscriptionList;
+    private static final int USERS = 5;
+    private static final int MAILBOXES = 5;
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+        // start the test cluster 
+        conf = HBaseClusterSingleton.build();
+        HBaseClusterSingleton.resetTables(conf);
+        mapperFactory = new HBaseMailboxSessionMapperFactory(conf, null, null);
+        mapper = new HBaseSubscriptionMapper(conf);
+        fillSubscriptionList();
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+
+    private static void fillSubscriptionList() throws SubscriptionException {
+        System.out.println("Creating subscription list");
+        SimpleSubscription subscription;
+        String user, mailbox;
+        subscriptionList = new HashMap<String, List<SimpleSubscription>>();
+        for (int i = 0; i < USERS; i++) {
+            user = "user" + i;
+            List<SimpleSubscription> mailboxes = new ArrayList<SimpleSubscription>();
+            subscriptionList.put(user, mailboxes);
+
+            for (int j = 0; j < MAILBOXES; j++) {
+                if (j == 0) {
+                    mailbox = "INBOX";
+                } else {
+                    mailbox = "BOX" + j;
+                }
+                if ((i % 2 == 0) && (j > 0)) {
+                    continue;
+                }
+                subscription = new SimpleSubscription(user, mailbox);
+                mailboxes.add(subscription);
+                mapper.save(subscription);
+                System.out.println("Adding subscription " + subscription);
+            }
+        }
+    }
+
+    /**
+     * Test of findMailboxSubscriptionForUser method, of class HBseSubscriptionMapper.
+     */
+    @Test
+    public void testFindMailboxSubscriptionForUser() throws Exception {
+        System.out.println("findMailboxSubscriptionForUser");
+
+        SimpleSubscription fake1 = new SimpleSubscription("user1", "FAKEBOX");
+        SimpleSubscription fake2 = new SimpleSubscription("fakeUser", "INBOX");
+
+        for (String user : subscriptionList.keySet()) {
+            System.out.println("Searching for all subscriptions for user: " + user);
+            for (SimpleSubscription subscription : subscriptionList.get(user)) {
+                Subscription result = mapper.findMailboxSubscriptionForUser(user, subscription.getMailbox());
+                assertEquals(subscription.getMailbox(), result.getMailbox());
+                assertEquals(subscription.getUser(), result.getUser());
+            }
+        }
+        assertNull(mapper.findMailboxSubscriptionForUser(fake1.getUser(), fake1.getMailbox()));
+        assertNull(mapper.findMailboxSubscriptionForUser(fake2.getUser(), fake2.getMailbox()));
+    }
+
+    /**
+     * Test of save method, of class HBaseSubscriptionMapper.
+     */
+    @Test
+    public void testSave() throws Exception {
+        System.out.println("save");
+        HTable subscriptions = new HTable(mapperFactory.getClusterConfiguration(), SUBSCRIPTIONS_TABLE);
+
+        for (String user : subscriptionList.keySet()) {
+            Get get = new Get(Bytes.toBytes(user));
+            get.addFamily(SUBSCRIPTION_CF);
+            Result result = subscriptions.get(get);
+            for (Subscription subscription : subscriptionList.get(user)) {
+                assertTrue(result.containsColumn(SUBSCRIPTION_CF, Bytes.toBytes(subscription.getMailbox())));
+            }
+        }
+        subscriptions.close();
+    }
+
+    /**
+     * Test of findSubscriptionsForUser method, of class HBaseSubscriptionMapper.
+     */
+    @Test
+    public void testFindSubscriptionsForUser() throws Exception {
+        System.out.println("findSubscriptionsForUser");
+        SimpleSubscription fake1 = new SimpleSubscription("user1", "FAKEBOX");
+        SimpleSubscription fake2 = new SimpleSubscription("fakeUser", "INBOX");
+        for (String user : subscriptionList.keySet()) {
+            System.out.println("Searching for all subscriptions for user: " + user);
+            List<Subscription> foundSubscriptions = mapper.findSubscriptionsForUser(user);
+            assertEquals(subscriptionList.get(user).size(), foundSubscriptions.size());
+            // TODO: patch Subscription to implement equals
+            //assertTrue(subscriptionList.get(user).containsAll(foundSubscriptions));
+            //assertTrue(foundSubscriptions.containsAll(subscriptionList.get(user)));
+            //assertFalse(foundSubscriptions.contains(fake1));
+            //assertFalse(foundSubscriptions.contains(fake2));
+        }
+        //TODO: check what value we should return in case of no subscriptions: null or empty list
+        assertEquals(mapper.findSubscriptionsForUser(fake2.getMailbox()).size(), 0);
+
+    }
+
+    /**
+     * Test of delete method, of class HBaseSubscriptionMapper.
+     */
+    @Test
+    public void testDelete() throws Exception {
+        System.out.println("delete");
+        HTable subscriptions = new HTable(mapperFactory.getClusterConfiguration(), SUBSCRIPTIONS_TABLE);
+
+        for (String user : subscriptionList.keySet()) {
+            System.out.println("Deleting subscriptions for user: " + user);
+            for (SimpleSubscription subscription : subscriptionList.get(user)) {
+                System.out.println("Deleting subscription : " + subscription);
+                mapper.delete(subscription);
+                Get get = new Get(Bytes.toBytes(subscription.getUser()));
+                Result result = subscriptions.get(get);
+                assertFalse(result.containsColumn(SUBSCRIPTION_CF, Bytes.toBytes(subscription.getMailbox())));
+            }
+        }
+        subscriptions.close();
+        fillSubscriptionList();
+    }
+}

Modified: james/mailbox/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/pom.xml?rev=1164981&r1=1164980&r2=1164981&view=diff
==============================================================================
--- james/mailbox/trunk/pom.xml (original)
+++ james/mailbox/trunk/pom.xml Sun Sep  4 09:49:14 2011
@@ -46,6 +46,7 @@
     <module>jpa</module>
     <module>jcr</module>
     <module>maildir</module>
+    <module>hbase</module>
     <module>spring</module>
     <module>tool</module>
   </modules>



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


Mime
View raw message