Package org.akubraproject

Examples of org.akubraproject.Blob


    final URI id1 = createId("blobInputStream1");

    // openInputStream on non-existent blob
    shouldFail(new ConAction() {
      public void run(BlobStoreConnection con) throws Exception {
        Blob b = getBlob(con, id1, false);
        b.openInputStream().close();
      }
    }, MissingBlobException.class, id1);

    // openInputStream on existing blob
    runTests(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          String body = "For the love of God, Montresor";
          Blob b = getBlob(con, id1, null);
          createBlob(con, b, body);

          // read partial body
          byte[] buf = new byte[100];

          InputStream is = b.openInputStream();
          int got = is.read(buf, 0, 10);
          assertTrue(got > 0 && got <= 10, "Invalid number of bytes read: " + got);
          int len = got;
          is.close();
          assertEquals(new String(buf, 0, len, "UTF-8"), body.substring(0, len));

          is = b.openInputStream();
          got = 0;
          while (got < len) {
            int skipped = (int) is.skip(len - got);
            assertTrue(skipped > 0 && skipped <= (len - got),
                       "Invalid number of bytes skipped: " + skipped);
View Full Code Here


  public void testOutputStream() throws Exception {
    // check if create is supported
    if (!isOutputSupp) {
      shouldFail(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          Blob b = getBlob(con, createId("blobOutputStream1"), false);
          b.openOutputStream(-1, true).close();
        }
      }, UnsupportedOperationException.class, null);

      return;
    }
View Full Code Here

  protected void testOutputStream(final URI id, final String body, final String body2,
                                  final long estSize) throws Exception {
    runTests(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          final Blob b = getBlob(con, id, null);

          testOutputStream(b, body, estSize, true);     // test create
          testOutputStream(b, body2, estSize, true);    // test overwrite

          deleteBlob(con, b);
View Full Code Here

  public void testBlobUpdate() throws Exception {
    final URI id = createId("blobBlobUpdate1");

    runTests(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          Blob b = getBlob(con, id, null);
          createBlob(con, b, null);
          setBlob(con, b, "value1");
          setBlob(con, b, "value2");
          setBlob(con, b, "value3");
        }
    }, true);

    runTests(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          Blob b = getBlob(con, id, "value3");
          setBlob(con, b, "value4");
          setBlob(con, b, "value5");
        }
    }, true);
View Full Code Here

  public void testMoveTo() throws Exception {
    // check if move is supported
    if (!isMoveToSupp) {
      shouldFail(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          Blob b = getBlob(con, createId("blobMoveTo1"), false);
          b.moveTo(b.getId(), null);
        }
      }, UnsupportedOperationException.class, null);

      return;
    }

    // set up
    final URI id1 = createId("blobMoveTo1");
    final URI id2 = createId("blobMoveTo2");
    final URI id3 = createId("blobMoveTo3");
    final URI id4 = createId("blobMoveTo4");

    createBlob(id1, "foo", true);
    createBlob(id4, "bar", true);

    // move blob from id1 to id2
    renameBlob(id1, id2, "foo", true);

    // move from non-existent blob should fail
    shouldFail(new ConAction() {
      public void run(BlobStoreConnection con) throws Exception {
        Blob ob = getBlob(con, id1, false);
        ob.moveTo(id3, null);
      }
    }, MissingBlobException.class, id1);

    getBlob(id1, null, true);
    getBlob(id3, null, true);

    // move to existing blob should fail
    shouldFail(new ConAction() {
      public void run(BlobStoreConnection con) throws Exception {
        Blob ob = getBlob(con, id2, "foo");
        ob.moveTo(id4, null);
      }
    }, DuplicateBlobException.class, id4);

    getBlob(id2, "foo", true);
    getBlob(id4, "bar", true);

    // move a non-existent blob onto itself should fail
    shouldFail(new ConAction() {
      public void run(BlobStoreConnection con) throws Exception {
        Blob b = getBlob(con, id1, false);
        b.moveTo(id1, null);
      }
    }, MissingBlobException.class, id1);

    getBlob(id1, null, true);

    // move an existing blob onto itself should fail
    shouldFail(new ConAction() {
      public void run(BlobStoreConnection con) throws Exception {
        Blob b = getBlob(con, id2, "foo");
        b.moveTo(id2, null);
      }
    }, DuplicateBlobException.class, id2);

    getBlob(id2, "foo", true);

    // move to null
    if (!isIdGenSupp) {
      // move to null should fail
      shouldFail(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          Blob b = getBlob(con, id2, "foo");
          b.moveTo(null, null);
        }
      }, UnsupportedOperationException.class, null);

      getBlob(id2, "foo", true);
    } else {
      // null id should work
      runTests(new ConAction() {
          public void run(BlobStoreConnection con) throws Exception {
            Blob b = getBlob(con, id2, "foo");
            Blob b2 = b.moveTo(null, null);
            // undo for other tests
            b2.moveTo(id2, null);
          }
      }, false);
    }

    // move to incompatible blob should fail
    final URI inv = getInvalidId();
    if (inv != null) {
      shouldFail(new ConAction() {
        public void run(BlobStoreConnection con) throws Exception {
          Blob ob = getBlob(con, id2, "foo");
          ob.moveTo(inv, null);
        }
      }, UnsupportedIdException.class, inv);
    }

    getBlob(id2, "foo", true);
View Full Code Here

  @Override
  public Blob moveTo(URI blobId, Map<String, String> hints) throws IOException {
    ensureOpen();

    Blob nb = delegate.moveTo(blobId, hints);
    return getConnection().getBlob(nb.getId(), hints);
  }
View Full Code Here

    shouldFail(new Action() {
      public void run(Transaction txn) throws Exception {
        BlobStoreConnection con = store.openConnection(txn, hints);

        Blob b = getBlob(con, createId("blobConSync3"), null);
        createBlob(con, b, "foos");
        b = moveBlob(con, b, createId("blobConSync4"), "foos");
        deleteBlob(con, b);

        con.sync();
View Full Code Here

  }

  @Override
  public Blob getBlob(InputStream content, long estimatedSize, Map<String, String> hints)
            throws IOException, UnsupportedOperationException {
    Blob blob = getBlob(null, hints);

    boolean success = false;
    try {
      OutputStream out = blob.openOutputStream(estimatedSize, true);
      try {
        IOUtils.copyLarge(content, out);
        out.close();
        out = null;
      } finally {
        if (out != null)
          IOUtils.closeQuietly(out);
      }

      success = true;
    } finally {
      if (!success) {
        try {
          blob.delete();
        } catch (Throwable t) {
          log.error("Error deleting blob after blob-creation failure", t);
        }
      }
    }
View Full Code Here

    return store.openConnection(null, null);
  }

  private static void addTestBlob(BlobStoreConnection connection,
                                  URI blobId) throws Exception {
    Blob blob = connection.getBlob(blobId, null);
    OutputStream out = blob.openOutputStream(-1, false);
    IOUtils.copy(new StringReader(blobId.toString()), out);
    out.close();
  }
View Full Code Here

      throws Exception {
    IdMapper mapper = new MockIdMapper();
    BlobStore store = new IdMappingBlobStore(URI.create("urn:test-store"),
        new MemBlobStore(), mapper);
    BlobStoreConnection connection = store.openConnection(null, null);
    Blob delegate = connection.getBlob(blobId, null);
    OutputStream out = delegate.openOutputStream(-1, false);
    IOUtils.copy(new StringReader(blobId.toString()), out);
    out.close();
    if (!delegateCanCanonicalize)
      delegate = new BlobWrapper(delegate) {
        @Override
View Full Code Here

TOP

Related Classes of org.akubraproject.Blob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.