use of com.zimbra.cs.store.StagedBlob in project zm-mailbox by Zimbra.
the class StoreManagerNegativeTest method nullLocator.
@Test
public void nullLocator() throws Exception {
Random rand = new Random();
byte[] bytes = new byte[10000];
rand.nextBytes(bytes);
StoreManager sm = StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
IncomingBlob incoming = sm.newIncomingBlob("foo", null);
OutputStream out = incoming.getAppendingOutputStream();
out.write(bytes);
Blob blob = incoming.getBlob();
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
try {
mblob.getLocalBlob().getInputStream();
Assert.fail("Expected IOException since locator is not handled correctly");
} catch (IOException io) {
//expected
} finally {
sm.delete(mblob);
}
}
use of com.zimbra.cs.store.StagedBlob in project zm-mailbox by Zimbra.
the class AbstractExternalStoreManagerTest method testUncachedSubstream.
@Test
public void testUncachedSubstream() throws Exception {
ParsedMessage pm = ThreaderTest.getRootMessage();
byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
StoreManager sm = StoreManager.getInstance();
Blob blob = sm.storeIncoming(pm.getRawInputStream());
StagedBlob staged = sm.stage(blob, mbox);
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
Blob localBlob = mblob.getLocalBlob();
InputStream stream = sm.getContent(localBlob);
Assert.assertTrue("input stream external", stream instanceof BlobInputStream);
if (sm instanceof ExternalStoreManager) {
((ExternalStoreManager) sm).clearCache();
}
blob.getFile().delete();
Assert.assertFalse(blob.getFile().exists());
//create new stream spanning the whole blob
InputStream newStream = ((BlobInputStream) stream).newStream(0, -1);
Assert.assertNotNull(newStream);
Assert.assertTrue("stream content = mime content", TestUtil.bytesEqual(mimeBytes, newStream));
}
use of com.zimbra.cs.store.StagedBlob in project zm-mailbox by Zimbra.
the class TritonBlobStoreManagerTest method sisEmpty.
@Test
public void sisEmpty() throws Exception {
TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
byte[] bytes = new byte[0];
Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
//blob has not yet been finalized, so it shouldn't exist in remote system yet
byte[] hash = sm.getHash(blob);
Assert.assertNotNull("empty blob always exists", sm.getSisBlob(hash));
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
//blob uploaded, now sis should return true and increment ref count
Blob sisBlob = sm.getSisBlob(hash);
Assert.assertNotNull("object created", sisBlob);
Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
}
use of com.zimbra.cs.store.StagedBlob in project zm-mailbox by Zimbra.
the class TritonBlobStoreManagerTest method sis.
@Test
public void sis() throws Exception {
TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
Random rand = new Random();
byte[] bytes = new byte[10000];
rand.nextBytes(bytes);
Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
//blob has not yet been finalized, so it shouldn't exist in remote system yet
byte[] hash = sm.getHash(blob);
Assert.assertNull("object not yet created", sm.getSisBlob(hash));
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
//blob uploaded, now sis should return true and increment ref count
Blob sisBlob = sm.getSisBlob(hash);
Assert.assertNotNull("object created", sisBlob);
Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
//delete once, should still exist;
sm.delete(mblob);
Assert.assertNotNull("object still ref'd", sm.getSisBlob(hash));
//delete twice (once for original, once since we just did a sisCheck above)
sm.delete(mblob);
sm.delete(mblob);
Assert.assertNull("object deleted", sm.getSisBlob(hash));
}
use of com.zimbra.cs.store.StagedBlob in project zm-mailbox by Zimbra.
the class Mailbox method createDocument.
public Document createDocument(OperationContext octxt, int folderId, ParsedDocument pd, MailItem.Type type, int flags, MailItem parent, CustomMetadata custom, boolean indexing) throws IOException, ServiceException {
StoreManager sm = StoreManager.getInstance();
StagedBlob staged = sm.stage(pd.getBlob(), this);
SaveDocument redoRecorder = new SaveDocument(mId, pd.getDigest(), pd.getSize(), folderId, flags);
boolean success = false;
try {
long start = System.currentTimeMillis();
beginTransaction("createDoc", octxt, redoRecorder);
SaveDocument redoPlayer = (octxt == null ? null : (SaveDocument) octxt.getPlayer());
int itemId = getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getMessageId());
String uuid = redoPlayer == null ? UUIDUtil.generateUUID() : redoPlayer.getUuid();
Document doc;
switch(type) {
case DOCUMENT:
doc = Document.create(itemId, uuid, getFolderById(folderId), pd.getFilename(), pd.getContentType(), pd, custom, flags, parent);
break;
case WIKI:
doc = WikiItem.create(itemId, uuid, getFolderById(folderId), pd.getFilename(), pd, null);
break;
default:
throw MailServiceException.INVALID_TYPE(type.toString());
}
redoRecorder.setMessageId(itemId);
redoRecorder.setUuid(doc.getUuid());
redoRecorder.setDocument(pd);
redoRecorder.setItemType(type);
redoRecorder.setDescription(pd.getDescription());
redoRecorder.setFlags(doc.getFlagBitmask());
// Get the redolog data from the mailbox blob. This is less than ideal in the
// HTTP store case because it will result in network access, and possibly an
// extra write to local disk. If this becomes a problem, we should update the
// ParsedDocument constructor to take a DataSource instead of an InputStream.
MailboxBlob mailboxBlob = doc.setContent(staged, pd);
redoRecorder.setMessageBodyInfo(new MailboxBlobDataSource(mailboxBlob), mailboxBlob.getSize());
if (indexing) {
index.add(doc);
}
success = true;
long elapsed = System.currentTimeMillis() - start;
ZimbraLog.mailbox.debug("createDocument elapsed=" + elapsed);
return doc;
} catch (IOException ioe) {
throw ServiceException.FAILURE("error writing document blob", ioe);
} finally {
endTransaction(success);
sm.quietDelete(staged);
}
}
Aggregations