Search in sources :

Example 31 with StoreManager

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

the class TestBlobDeduper method testBlobDeduper.

@Test
public void testBlobDeduper() throws Exception {
    StoreManager storeMgr = StoreManager.getInstance();
    TestUtil.assumeTrue(String.format("StoreManager class=%s is not FileBlobStore", storeMgr.getClass().getName()), storeMgr instanceof FileBlobStore);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    String[] paths = new String[5];
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    for (int i = 0; i < 5; i++) {
        Message msg = mbox.addMessage(null, new ParsedMessage(("From: test@zimbra.com\r\nTo: to1@zimbra.com\r\nSubject: " + TEST_NAME).getBytes(), false), opt, null);
        paths[i] = msg.getBlob().getLocalBlob().getFile().getPath();
    }
    // Make sure inodes are different for paths
    for (int i = 0; i < 4; i++) {
        Assert.assertFalse(IO.fileInfo(paths[i]).getInodeNum() == IO.fileInfo(paths[i + 1]).getInodeNum());
    }
    // wait for a seconds, so that timestamp gets changed.
    Thread.sleep(1000);
    BlobDeduper deduper = BlobDeduper.getInstance();
    List<Short> volumeIds = new ArrayList<Short>();
    volumeIds.add(vol.getId());
    deduper.process(volumeIds);
    while (deduper.isRunning()) {
        // wait until deduper finishes.
        Thread.sleep(1000);
    }
    // Make sure inodes are same for paths
    for (int i = 0; i < 4; i++) {
        Assert.assertTrue(IO.fileInfo(paths[i]).getInodeNum() == IO.fileInfo(paths[i + 1]).getInodeNum());
    }
}
Also used : Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobDeduper(com.zimbra.cs.store.file.BlobDeduper) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ArrayList(java.util.ArrayList) StoreManager(com.zimbra.cs.store.StoreManager) Volume(com.zimbra.cs.volume.Volume) FileBlobStore(com.zimbra.cs.store.file.FileBlobStore) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 32 with StoreManager

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

the class TestStoreManager method testStore.

@Test
public void testStore() throws Exception {
    ParsedMessage pm = getMessage();
    byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    StoreManager sm = StoreManager.getInstance();
    Blob blob = sm.storeIncoming(pm.getRawInputStream());
    Assert.assertEquals("blob size = message size", pm.getRawData().length, blob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(mimeBytes, blob.getInputStream()));
    StagedBlob staged = sm.stage(blob, mbox);
    Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
    MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
    Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
    Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(mimeBytes, mblob.getLocalBlob().getInputStream()));
    mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
    Assert.assertEquals("mblob size = staged size", staged.getSize(), mblob.getSize());
    Assert.assertTrue("mailboxblob content = mime content", TestUtil.bytesEqual(mimeBytes, mblob.getLocalBlob().getInputStream()));
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) StoreManager(com.zimbra.cs.store.StoreManager) Test(org.junit.Test)

Aggregations

StoreManager (com.zimbra.cs.store.StoreManager)32 MailboxBlob (com.zimbra.cs.store.MailboxBlob)17 StagedBlob (com.zimbra.cs.store.StagedBlob)16 IOException (java.io.IOException)14 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)11 InputStream (java.io.InputStream)11 Blob (com.zimbra.cs.store.Blob)10 Mailbox (com.zimbra.cs.mailbox.Mailbox)9 Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)6 ServiceException (com.zimbra.common.service.ServiceException)6 CopyInputStream (com.zimbra.common.util.CopyInputStream)6 Test (org.junit.Test)6 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)5 ArrayList (java.util.ArrayList)5 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)4 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)4 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)4 Volume (com.zimbra.cs.volume.Volume)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)3