Search in sources :

Example 1 with ContentAddressableStoreManager

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

the class TritonBlobStoreManagerTest method sisEmpty.

@Test
public void sisEmpty() throws Exception {
    TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
    Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
    byte[] bytes = new byte[0];
    Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
    // blob has not yet been finalized, so it shouldn't exist in remote system yet
    byte[] hash = sm.getHash(blob);
    Assert.assertNotNull("empty blob always exists", sm.getSisBlob(hash));
    Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, 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(bytes, mblob.getLocalBlob().getInputStream()));
    // blob uploaded, now sis should return true and increment ref count
    Blob sisBlob = sm.getSisBlob(hash);
    Assert.assertNotNull("object created", sisBlob);
    Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.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) ContentAddressableStoreManager(com.zimbra.cs.store.external.ContentAddressableStoreManager) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test) AbstractStoreManagerTest(com.zimbra.cs.store.AbstractStoreManagerTest)

Example 2 with ContentAddressableStoreManager

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

the class TritonBlobStoreManagerTest method sis.

@Test
public void sis() throws Exception {
    TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
    Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
    Random rand = new Random();
    byte[] bytes = new byte[10000];
    rand.nextBytes(bytes);
    Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
    // blob has not yet been finalized, so it shouldn't exist in remote system yet
    byte[] hash = sm.getHash(blob);
    Assert.assertNull("object not yet created", sm.getSisBlob(hash));
    Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, 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(bytes, mblob.getLocalBlob().getInputStream()));
    // blob uploaded, now sis should return true and increment ref count
    Blob sisBlob = sm.getSisBlob(hash);
    Assert.assertNotNull("object created", sisBlob);
    Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
    // delete once, should still exist;
    sm.delete(mblob);
    Assert.assertNotNull("object still ref'd", sm.getSisBlob(hash));
    // delete twice (once for original, once since we just did a sisCheck above)
    sm.delete(mblob);
    sm.delete(mblob);
    Assert.assertNull("object deleted", sm.getSisBlob(hash));
}
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) ContentAddressableStoreManager(com.zimbra.cs.store.external.ContentAddressableStoreManager) Random(java.util.Random) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test) AbstractStoreManagerTest(com.zimbra.cs.store.AbstractStoreManagerTest)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)2 AbstractStoreManagerTest (com.zimbra.cs.store.AbstractStoreManagerTest)2 Blob (com.zimbra.cs.store.Blob)2 MailboxBlob (com.zimbra.cs.store.MailboxBlob)2 StagedBlob (com.zimbra.cs.store.StagedBlob)2 ContentAddressableStoreManager (com.zimbra.cs.store.external.ContentAddressableStoreManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Test (org.junit.Test)2 Random (java.util.Random)1