Search in sources :

Example 1 with IncomingBlob

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

the class StoreManagerNegativeTest method incorrectRemoteSize.

@Test
public void incorrectRemoteSize() throws Exception {
    Random rand = new Random();
    byte[] bytes = new byte[10000];
    rand.nextBytes(bytes);
    StoreManager sm = StoreManager.getInstance();
    IncomingBlob incoming = sm.newIncomingBlob("foo", null);
    OutputStream out = incoming.getAppendingOutputStream();
    out.write(bytes);
    try {
        incoming.getCurrentSize();
        Assert.fail("Expected exception since remote size is incorrect");
    } catch (IOException ioe) {
    //expected
    }
}
Also used : Random(java.util.Random) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) IncomingBlob(com.zimbra.cs.store.IncomingBlob) StoreManager(com.zimbra.cs.store.StoreManager) Test(org.junit.Test)

Example 2 with IncomingBlob

use of com.zimbra.cs.store.IncomingBlob 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);
    }
}
Also used : Blob(com.zimbra.cs.store.Blob) IncomingBlob(com.zimbra.cs.store.IncomingBlob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Random(java.util.Random) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailboxBlob(com.zimbra.cs.store.MailboxBlob) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) IncomingBlob(com.zimbra.cs.store.IncomingBlob) StoreManager(com.zimbra.cs.store.StoreManager) Test(org.junit.Test)

Example 3 with IncomingBlob

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

the class PatchStore method acceptPatch.

/**
     * Accepts patch. Turns an IncomingPatch into a StoredPatch.
     *
     * @param ip The IncomingPatch instance to accept.
     * @param fileId The id of the file the patch creates.
     * @param version the version The version number of the file the patch creates.
     * @param manifest The patch manifest.
     *
     * @return StoredPatch instance.
     *
     * @throws IOException Signals that an I/O exception has occurred.
     * @throws ServiceException the service exception
     */
public StoredPatch acceptPatch(IncomingPatch ip, int fileId, int version) throws IOException, ServiceException {
    if (version > 1) {
        deletePatch(ip.getAccountId(), fileId);
    }
    IncomingBlob manifestBlob = blobStore.createIncoming(null);
    try {
        ip.getManifest().writeTo(manifestBlob.getAppendingOutputStream());
    } catch (IOException e) {
        blobStore.deleteIncoming(manifestBlob);
        throw e;
    }
    // ok, we got manifest written to a separate incoming blob here, now let's store both
    StoredBlob psb = blobStore.store(ip.patchBlob, getStoredPatchId(ip.getAccountId(), fileId, false), version);
    StoredBlob msb = null;
    try {
        msb = blobStore.store(manifestBlob, getStoredPatchId(ip.getAccountId(), fileId, true), version);
    } catch (IOException e) {
        blobStore.delete(psb, version);
        throw e;
    }
    StoredPatch sp = new StoredPatch(psb, msb, ip.getAccountId());
    psb.setContext(sp);
    return sp;
}
Also used : StoredBlob(com.zimbra.cs.octosync.store.BlobStore.StoredBlob) IOException(java.io.IOException) IncomingBlob(com.zimbra.cs.store.IncomingBlob)

Example 4 with IncomingBlob

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

the class StoreManagerBasedTempBlobStore method createIncoming.

// BlobStore API
@Override
public IncomingBlob createIncoming(Object ctx) throws IOException, ServiceException {
    synchronized (incomingBlobs) {
        String id;
        do {
            id = UUID.randomUUID().toString();
        } while (incomingBlobs.containsKey(id));
        IncomingBlob ib = storeManager.newIncomingBlob(id, ctx);
        incomingBlobs.put(id, ib);
        return ib;
    }
}
Also used : IncomingBlob(com.zimbra.cs.store.IncomingBlob)

Example 5 with IncomingBlob

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

the class StoreManagerBasedTempBlobStore method store.

// BlobStore API
@Override
public StoredBlob store(IncomingBlob ib, String id, int version) throws IOException, ServiceException {
    IncomingBlob myIb = ib;
    synchronized (incomingBlobs) {
        IncomingBlob existingBlob = incomingBlobs.remove(myIb.getId());
        if (existingBlob == null) {
            // because the underlying file is gone
            throw ServiceException.INVALID_REQUEST("Cannot accept incoming blob " + myIb.getId(), null);
        }
        assert existingBlob == myIb : "Wrong blob removed: " + myIb.getId();
    }
    Blob blob = myIb.getBlob();
    StoredBlob sb = new StoredBlob(id, blob, myIb.getContext(), blob.getRawSize());
    if (storedCached) {
        synchronized (storedBlobs) {
            TreeMap<Integer, StoredBlob> versionMap = storedBlobs.get(id);
            if (versionMap == null) {
                versionMap = new TreeMap<Integer, StoredBlob>();
                storedBlobs.put(id, versionMap);
            }
            Integer versionInt = Integer.valueOf(version);
            assert !versionMap.containsKey(versionInt) : "Version " + version + " already exists";
            versionMap.put(versionInt, sb);
        }
    }
    return sb;
}
Also used : Blob(com.zimbra.cs.store.Blob) IncomingBlob(com.zimbra.cs.store.IncomingBlob) IncomingBlob(com.zimbra.cs.store.IncomingBlob)

Aggregations

IncomingBlob (com.zimbra.cs.store.IncomingBlob)7 IOException (java.io.IOException)3 Blob (com.zimbra.cs.store.Blob)2 StoreManager (com.zimbra.cs.store.StoreManager)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 Random (java.util.Random)2 Test (org.junit.Test)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 StoredBlob (com.zimbra.cs.octosync.store.BlobStore.StoredBlob)1 MailboxBlob (com.zimbra.cs.store.MailboxBlob)1 StagedBlob (com.zimbra.cs.store.StagedBlob)1