Search in sources :

Example 1 with MockStoreManager

use of com.zimbra.cs.store.MockStoreManager in project zm-mailbox by Zimbra.

the class MailboxTestUtil method clearData.

/**
     * Clears the database and index.
     * @param zimbraServerDir the directory that contains the ZimbraServer project
     */
public static void clearData(String zimbraServerDir) throws Exception {
    HSQLDB.clearDatabase(zimbraServerDir);
    MailboxManager.getInstance().clearCache();
    MailboxIndex.shutdown();
    File index = new File("build/test/index");
    if (index.isDirectory()) {
        deleteDirContents(index);
    }
    StoreManager sm = StoreManager.getInstance();
    if (sm instanceof MockStoreManager) {
        ((MockStoreManager) sm).purge();
    } else if (sm instanceof MockHttpStoreManager) {
        MockHttpStore.purge();
    }
    DocumentHandler.resetLocalHost();
    EphemeralStore.getFactory().shutdown();
}
Also used : MockStoreManager(com.zimbra.cs.store.MockStoreManager) File(java.io.File) MockHttpStoreManager(com.zimbra.cs.store.http.HttpStoreManagerTest.MockHttpStoreManager) StoreManager(com.zimbra.cs.store.StoreManager) MockStoreManager(com.zimbra.cs.store.MockStoreManager) MockHttpStoreManager(com.zimbra.cs.store.http.HttpStoreManagerTest.MockHttpStoreManager)

Example 2 with MockStoreManager

use of com.zimbra.cs.store.MockStoreManager in project zm-mailbox by Zimbra.

the class MailboxTest method deleteMailbox.

@Test
public void deleteMailbox() throws Exception {
    MockStoreManager sm = (MockStoreManager) StoreManager.getInstance();
    // first test normal mailbox delete
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Assert.assertEquals("start with no blobs in the store", 0, sm.size());
    MailItem item = mbox.addMessage(null, MailboxTestUtil.generateMessage("test"), STANDARD_DELIVERY_OPTIONS, null);
    Assert.assertEquals("1 blob in the store", 1, sm.size());
    // Index the mailbox so that mime message gets cached
    mbox.index.indexDeferredItems();
    // make sure digest is in message cache.
    Assert.assertTrue(MessageCache.contains(item.getDigest()));
    mbox.deleteMailbox();
    Assert.assertEquals("end with no blobs in the store", 0, sm.size());
    // make sure digest is removed from message cache.
    Assert.assertFalse(MessageCache.contains(item.getDigest()));
    // then test mailbox delete without store delete
    mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Assert.assertEquals("start with no blobs in the store", 0, sm.size());
    item = mbox.addMessage(null, MailboxTestUtil.generateMessage("test"), STANDARD_DELIVERY_OPTIONS, null);
    Assert.assertEquals("1 blob in the store", 1, sm.size());
    // Index the mailbox so that mime message gets cached
    mbox.index.indexDeferredItems();
    // make sure digest is in message cache.
    Assert.assertTrue(MessageCache.contains(item.getDigest()));
    mbox.deleteMailbox(Mailbox.DeleteBlobs.NEVER);
    Assert.assertEquals("end with 1 blob in the store", 1, sm.size());
    // make sure digest is still present in message cache.
    Assert.assertTrue(MessageCache.contains(item.getDigest()));
    sm.purge();
    // then do it contingent on whether the store is centralized or local
    mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Assert.assertEquals("start with no blobs in the store", 0, sm.size());
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test"), STANDARD_DELIVERY_OPTIONS, null).getId();
    Assert.assertEquals("1 blob in the store", 1, sm.size());
    mbox.deleteMailbox(Mailbox.DeleteBlobs.UNLESS_CENTRALIZED);
    int expected = StoreManager.getInstance().supports(StoreManager.StoreFeature.CENTRALIZED) ? 1 : 0;
    Assert.assertEquals("end with " + expected + " blob(s) in the store", expected, sm.size());
    sm.purge();
}
Also used : MockStoreManager(com.zimbra.cs.store.MockStoreManager) Test(org.junit.Test)

Aggregations

MockStoreManager (com.zimbra.cs.store.MockStoreManager)2 StoreManager (com.zimbra.cs.store.StoreManager)1 MockHttpStoreManager (com.zimbra.cs.store.http.HttpStoreManagerTest.MockHttpStoreManager)1 File (java.io.File)1 Test (org.junit.Test)1