Search in sources :

Example 6 with Mailbox

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

the class FileBlobStoreConsistencyCheckTest method createUnexpectedBlob.

@Override
protected String createUnexpectedBlob(int index) throws ServiceException, IOException {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    String dir = vol.getBlobDir(mbox.getId(), 0);
    File file = new File(dir + "/foo" + index + ".txt");
    file.mkdirs();
    file.createNewFile();
    return file.getCanonicalPath();
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) File(java.io.File)

Example 7 with Mailbox

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

the class AbstractBlobConsistencyCheckTest method allBlobs.

@Test
public void allBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    int msgs = 10;
    for (int i = 0; i < msgs; i++) {
        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, true);
    Assert.assertEquals(0, results.missingBlobs.size());
    Assert.assertEquals(0, results.unexpectedBlobs.size());
    Assert.assertEquals(msgs, 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 8 with Mailbox

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

the class AbstractBlobConsistencyCheckTest method wrongSize.

@Test
public void wrongSize() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
    MailboxBlob blob = msg.getBlob();
    String text = "some garbage";
    appendText(blob, text);
    BlobConsistencyChecker checker = getChecker();
    Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
    Assert.assertEquals(0, results.missingBlobs.size());
    Assert.assertEquals(0, results.unexpectedBlobs.size());
    Assert.assertEquals(0, results.usedBlobs.size());
    Assert.assertEquals(1, results.incorrectSize.size());
    BlobInfo info = results.incorrectSize.values().iterator().next();
    Assert.assertEquals(blob.size + text.length(), (long) info.fileDataSize);
    Assert.assertEquals(0, results.incorrectModContent.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Results(com.zimbra.cs.store.file.BlobConsistencyChecker.Results) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobConsistencyChecker(com.zimbra.cs.store.file.BlobConsistencyChecker) BlobInfo(com.zimbra.cs.store.file.BlobConsistencyChecker.BlobInfo) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 9 with Mailbox

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

the class AbstractBlobConsistencyCheckTest method unexpectedBlobs.

@Test
public void unexpectedBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    String path = createUnexpectedBlob(0);
    BlobConsistencyChecker checker = getChecker();
    Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
    Assert.assertEquals(0, results.missingBlobs.size());
    Assert.assertEquals(1, results.unexpectedBlobs.size());
    BlobInfo info = results.unexpectedBlobs.values().iterator().next();
    Assert.assertEquals(path, info.path);
    Assert.assertEquals(0, results.usedBlobs.size());
    Assert.assertEquals(0, results.incorrectSize.size());
    Assert.assertEquals(0, results.incorrectModContent.size());
    deleteAllBlobs();
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
    int msgs = 10;
    for (int i = 0; i < msgs; i++) {
        createUnexpectedBlob(i);
    }
    results = checker.check(getVolumeIds(), mbox.getId(), true, false);
    Assert.assertEquals(0, results.missingBlobs.size());
    Assert.assertEquals(msgs, results.unexpectedBlobs.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) BlobInfo(com.zimbra.cs.store.file.BlobConsistencyChecker.BlobInfo) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 10 with Mailbox

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

the class AbstractStoreManagerTest method emptyBlob.

@Test
public void emptyBlob() throws Exception {
    StoreManager sm = StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    IncomingBlob incoming = sm.newIncomingBlob("foo", null);
    Blob blob = incoming.getBlob();
    Assert.assertEquals("blob size = incoming written", 0, blob.getRawSize());
    if (sm instanceof ExternalStoreManager) {
        ((ExternalStoreManager) sm).clearCache();
    }
    StagedBlob staged = sm.stage(blob, mbox);
    Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
    if (sm instanceof ExternalStoreManager) {
        ((ExternalStoreManager) sm).clearCache();
    }
    MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
    Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
    if (sm instanceof ExternalStoreManager) {
        ((ExternalStoreManager) sm).clearCache();
    }
    mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
    Assert.assertEquals("mblob size = staged size", staged.getSize(), mblob.getSize());
    if (sm instanceof ExternalStoreManager) {
        ((ExternalStoreManager) sm).clearCache();
    }
    Assert.assertEquals(0, mblob.getLocalBlob().getRawSize());
    sm.delete(mblob);
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ExternalStoreManager(com.zimbra.cs.store.external.ExternalStoreManager) ExternalStoreManager(com.zimbra.cs.store.external.ExternalStoreManager) Test(org.junit.Test) ThreaderTest(com.zimbra.cs.mailbox.ThreaderTest)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)817 Account (com.zimbra.cs.account.Account)389 Test (org.junit.Test)376 OperationContext (com.zimbra.cs.mailbox.OperationContext)365 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)306 Message (com.zimbra.cs.mailbox.Message)303 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)243 ItemId (com.zimbra.cs.service.util.ItemId)243 Element (com.zimbra.common.soap.Element)138 ServiceException (com.zimbra.common.service.ServiceException)127 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)127 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)106 MimeMessage (javax.mail.internet.MimeMessage)104 Folder (com.zimbra.cs.mailbox.Folder)82 ArrayList (java.util.ArrayList)81 ZMailbox (com.zimbra.client.ZMailbox)73 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)71 PreparedStatement (java.sql.PreparedStatement)67 SQLException (java.sql.SQLException)67 Header (javax.mail.Header)66