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();
}
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());
}
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());
}
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());
}
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);
}
Aggregations