Search in sources :

Example 1 with MailboxBlobInfo

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

the class DbVolumeBlobsTest method testIncrementalBlobs.

@Test
public void testIncrementalBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    int ts1 = (int) (System.currentTimeMillis() / 1000);
    Message msg1 = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Thread.sleep(1000);
    int ts2 = (int) (System.currentTimeMillis() / 1000);
    Message msg2 = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Thread.sleep(1000);
    int ts3 = (int) (System.currentTimeMillis() / 1000);
    Iterable<MailboxBlobInfo> allBlobs = null;
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), ts1, ts2);
    Assert.assertEquals(msg1.getId(), allBlobs.iterator().next().itemId);
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), ts2, ts3);
    Assert.assertEquals(msg2.getId(), allBlobs.iterator().next().itemId);
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Test(org.junit.Test)

Example 2 with MailboxBlobInfo

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

the class DbVolumeBlobsTest method writeAllBlobRefs.

@Test
public void writeAllBlobRefs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Map<String, String> digestToPath = new HashMap<String, String>();
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    for (int i = 0; i < 10; i++) {
        Message msg = mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
        digestToPath.put(msg.getDigest(), msg.getBlob().getLocalBlob().getFile().getPath());
    }
    Iterable<MailboxBlobInfo> allBlobs = null;
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), -1, -1);
    for (MailboxBlobInfo info : allBlobs) {
        DbVolumeBlobs.addBlobReference(conn, info);
    }
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(digestToPath.size(), blobs.size());
    for (BlobReference blob : blobs) {
        String path = digestToPath.remove(blob.getDigest());
        Assert.assertNotNull(path);
        Assert.assertEquals(path, getPath(blob));
    }
    Assert.assertTrue(digestToPath.isEmpty());
}
Also used : BlobReference(com.zimbra.cs.store.file.BlobReference) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) HashMap(java.util.HashMap) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 3 with MailboxBlobInfo

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

the class MailboxBlobTest method serialization.

@Test
public void serialization() throws Exception {
    MailboxBlobInfo mbinfo = new MailboxBlobInfo(MockProvisioning.DEFAULT_ACCOUNT_ID, 1, Mailbox.FIRST_USER_ID, 1, "locator", "digest123");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(mbinfo);
    oos.close();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    MailboxBlobInfo mbi2 = (MailboxBlobInfo) ois.readObject();
    Assert.assertEquals(mbinfo.accountId, mbi2.accountId);
    Assert.assertEquals(mbinfo.mailboxId, mbi2.mailboxId);
    Assert.assertEquals(mbinfo.itemId, mbi2.itemId);
    Assert.assertEquals(mbinfo.revision, mbi2.revision);
    Assert.assertEquals(mbinfo.locator, mbi2.locator);
    Assert.assertEquals(mbinfo.digest, mbi2.digest);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 4 with MailboxBlobInfo

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

the class DbVolumeBlobsTest method testUniqueBlobDigests.

@Test
public void testUniqueBlobDigests() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    for (int i = 0; i < 5; i++) {
        mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
        mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
    }
    Iterable<MailboxBlobInfo> allBlobs = null;
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), -1, -1);
    for (MailboxBlobInfo info : allBlobs) {
        DbVolumeBlobs.addBlobReference(conn, info);
    }
    SpoolingCache<String> digests = DbVolumeBlobs.getUniqueDigests(conn, vol);
    Assert.assertEquals(5, digests.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Test(org.junit.Test)

Example 5 with MailboxBlobInfo

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

the class DbVolumeBlobsTest method dumpsterBlobs.

@Test
public void dumpsterBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Map<String, String> digestToPath = new HashMap<String, String>();
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    for (int i = 0; i < 10; i++) {
        Message msg = mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
        digestToPath.put(msg.getDigest(), msg.getBlob().getLocalBlob().getFile().getPath());
        mbox.delete(null, msg.getId(), msg.getType());
    }
    mbox.emptyFolder(null, Mailbox.ID_FOLDER_TRASH, false);
    Iterable<MailboxBlobInfo> allBlobs = null;
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), -1, -1);
    for (MailboxBlobInfo info : allBlobs) {
        DbVolumeBlobs.addBlobReference(conn, info);
    }
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(digestToPath.size(), blobs.size());
    for (BlobReference blob : blobs) {
        String path = digestToPath.remove(blob.getDigest());
        Assert.assertNotNull(path);
        Assert.assertEquals(path, getPath(blob));
    }
    Assert.assertTrue(digestToPath.isEmpty());
}
Also used : BlobReference(com.zimbra.cs.store.file.BlobReference) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) HashMap(java.util.HashMap) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Aggregations

MailboxBlobInfo (com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo)8 Test (org.junit.Test)8 Mailbox (com.zimbra.cs.mailbox.Mailbox)7 Volume (com.zimbra.cs.volume.Volume)7 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)5 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)5 Message (com.zimbra.cs.mailbox.Message)4 BlobReference (com.zimbra.cs.store.file.BlobReference)4 HashMap (java.util.HashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Document (com.zimbra.cs.mailbox.Document)2 ParsedDocument (com.zimbra.cs.mime.ParsedDocument)2 InputStream (java.io.InputStream)2 ServiceException (com.zimbra.common.service.ServiceException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1