Search in sources :

Example 6 with MailboxBlobInfo

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

the class DbVolumeBlobsTest method revisionBlobs.

@Test
public void revisionBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, String> digestToPath = new HashMap<String, String>();
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    InputStream in = new ByteArrayInputStream("testcontent".getBytes());
    ParsedDocument pd = new ParsedDocument(in, "docname", "text/plain", System.currentTimeMillis(), null, null);
    Document doc = mbox.createDocument(null, Mailbox.ID_FOLDER_BRIEFCASE, pd, MailItem.Type.DOCUMENT, 0);
    digestToPath.put(doc.getDigest(), doc.getBlob().getLocalBlob().getFile().getPath());
    int baseId = doc.getId();
    for (int i = 0; i < 10; i++) {
        in = new ByteArrayInputStream(("testcontent-new-" + i).getBytes());
        pd = new ParsedDocument(in, "docname", "text/plain", System.currentTimeMillis(), null, null);
        doc = mbox.addDocumentRevision(null, baseId, pd);
        digestToPath.put(doc.getDigest(), doc.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) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Document(com.zimbra.cs.mailbox.Document) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) Volume(com.zimbra.cs.volume.Volume) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 7 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)

Example 8 with MailboxBlobInfo

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

the class DbVolumeBlobsTest method revisionDumpsterBlobs.

@Test
public void revisionDumpsterBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, String> digestToPath = new HashMap<String, String>();
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    InputStream in = new ByteArrayInputStream("testcontent".getBytes());
    ParsedDocument pd = new ParsedDocument(in, "docname", "text/plain", System.currentTimeMillis(), null, null);
    Document doc = mbox.createDocument(null, Mailbox.ID_FOLDER_BRIEFCASE, pd, MailItem.Type.DOCUMENT, 0);
    digestToPath.put(doc.getDigest(), doc.getBlob().getLocalBlob().getFile().getPath());
    int baseId = doc.getId();
    for (int i = 0; i < 10; i++) {
        in = new ByteArrayInputStream(("testcontent-new-" + i).getBytes());
        pd = new ParsedDocument(in, "docname", "text/plain", System.currentTimeMillis(), null, null);
        doc = mbox.addDocumentRevision(null, baseId, pd);
        digestToPath.put(doc.getDigest(), doc.getBlob().getLocalBlob().getFile().getPath());
    }
    mbox.delete(null, baseId, MailItem.Type.DOCUMENT);
    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) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Document(com.zimbra.cs.mailbox.Document) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) Volume(com.zimbra.cs.volume.Volume) ByteArrayInputStream(java.io.ByteArrayInputStream) 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