Search in sources :

Example 36 with DeliveryOptions

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

the class AbstractBlobConsistencyCheckTest method singleBlob.

@Test
public void singleBlob() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
    BlobConsistencyChecker checker = getChecker();
    Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
    Assert.assertEquals(0, results.unexpectedBlobs.size());
    Assert.assertEquals(0, results.missingBlobs.size());
    Assert.assertEquals(0, results.usedBlobs.size());
    Assert.assertEquals(0, results.incorrectSize.size());
    Assert.assertEquals(0, results.incorrectModContent.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Results(com.zimbra.cs.store.file.BlobConsistencyChecker.Results) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobConsistencyChecker(com.zimbra.cs.store.file.BlobConsistencyChecker) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 37 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions 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 38 with DeliveryOptions

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

the class DbVolumeBlobsTest method testDuplicateRow.

@Test
public void testDuplicateRow() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    MailboxBlobInfo blobInfo = new MailboxBlobInfo(null, mbox.getId(), msg.getId(), msg.getSavedSequence(), String.valueOf(vol.getId()), null);
    DbVolumeBlobs.addBlobReference(conn, blobInfo);
    try {
        DbVolumeBlobs.addBlobReference(conn, blobInfo);
        Assert.fail("expected exception");
    } catch (ServiceException e) {
    // expected
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ServiceException(com.zimbra.common.service.ServiceException) 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 39 with DeliveryOptions

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

the class TestBlobDeduper method testBlobDeduper.

@Test
public void testBlobDeduper() throws Exception {
    Assume.assumeTrue(StoreManager.getInstance() 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) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) FileBlobStore(com.zimbra.cs.store.file.FileBlobStore) ArrayList(java.util.ArrayList) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 40 with DeliveryOptions

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

the class DbVolumeBlobsTest method deleteBlobRef.

@Test
public void deleteBlobRef() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    DbVolumeBlobs.addBlobReference(conn, mbox, vol, msg);
    String digest = msg.getBlob().getDigest();
    String path = msg.getBlob().getLocalBlob().getFile().getPath();
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(1, blobs.size());
    Assert.assertEquals(path, getPath(blobs.get(0)));
    DbVolumeBlobs.deleteBlobRef(conn, blobs.get(0).getId());
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(0, blobs.size());
}
Also used : BlobReference(com.zimbra.cs.store.file.BlobReference) 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) Test(org.junit.Test)

Aggregations

DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)59 Mailbox (com.zimbra.cs.mailbox.Mailbox)50 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)46 Message (com.zimbra.cs.mailbox.Message)45 Test (org.junit.Test)44 Account (com.zimbra.cs.account.Account)18 OperationContext (com.zimbra.cs.mailbox.OperationContext)14 MimeMessage (javax.mail.internet.MimeMessage)12 ItemId (com.zimbra.cs.service.util.ItemId)11 Volume (com.zimbra.cs.volume.Volume)11 ServiceException (com.zimbra.common.service.ServiceException)10 Element (com.zimbra.common.soap.Element)9 IOException (java.io.IOException)9 Folder (com.zimbra.cs.mailbox.Folder)7 BlobReference (com.zimbra.cs.store.file.BlobReference)7 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)6 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5 MailItem (com.zimbra.cs.mailbox.MailItem)5 MailboxBlobInfo (com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo)5 BlobConsistencyChecker (com.zimbra.cs.store.file.BlobConsistencyChecker)5