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