/** Test of getBlob method, of class FilesystemAsyncBlobStore. */
  public void testGetBlob() throws IOException {
    String blobKey = TestUtils.createRandomBlobKey();
    GetOptions options = null;
    Blob resultBlob;

    blobStore.createContainerInLocation(null, CONTAINER_NAME);

    resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
    assertNull(resultBlob, "Blob exists");

    // create blob
    TestUtils.createBlobsInContainer(CONTAINER_NAME, blobKey);

    resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);

    assertNotNull(resultBlob, "Blob exists");
    // checks file content
    InputSupplier<FileInputStream> expectedFile =
        Files.newInputStreamSupplier(new File(TARGET_CONTAINER_NAME, blobKey));
    assertTrue(
        ByteStreams.equal(expectedFile, resultBlob.getPayload()),
        "Blob payload differs from file content");
    // metadata are verified in the test for blobMetadata, so no need to
    // perform a complete test here
    assertNotNull(resultBlob.getMetadata(), "Metadata null");
    MutableBlobMetadata metadata = resultBlob.getMetadata();
    assertEquals(blobKey, metadata.getName(), "Wrong blob metadata");
  }
 public void testGetBlob_NotExistingContainer() {
   try {
     blobStore.getBlob(CONTAINER_NAME, TestUtils.createRandomBlobKey(), null);
     fail("Retrieve must fail, container does not exist.");
   } catch (ContainerNotFoundException e) {
     // correct if arrive here
   }
 }
  public void testRanges() throws IOException {
    blobStore.createContainerInLocation(null, CONTAINER_NAME);
    String input = "abcdefgh";
    Payload payload;
    Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(input)).build();
    blobStore.putBlob(CONTAINER_NAME, blob);

    GetOptions getOptionsRangeStartAt = new GetOptions();
    getOptionsRangeStartAt.startAt(1);
    Blob blobRangeStartAt =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
    payload = blobRangeStartAt.getPayload();
    try {
      assertEquals(input.substring(1), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }

    GetOptions getOptionsRangeTail = new GetOptions();
    getOptionsRangeTail.tail(3);
    Blob blobRangeTail =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
    payload = blobRangeTail.getPayload();
    try {
      assertEquals(input.substring(5), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }

    GetOptions getOptionsFragment = new GetOptions();
    getOptionsFragment.range(4, 6);
    Blob blobFragment =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
    payload = blobFragment.getPayload();
    try {
      assertEquals(input.substring(4, 7), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }
  }
Ejemplo n.º 4
0
  /** http://code.google.com/p/jclouds/issues/detail?id=992 */
  public void testUseBucketWithUpperCaseName() throws Exception {
    String bucketName = CONTAINER_PREFIX + "-TestBucket";
    String blobName = "TestBlob.txt";
    StorageMetadata container = null;
    BlobStore store = view.getBlobStore();

    // Create and use a valid bucket name with uppercase characters in the bucket name (US regions
    // only)
    try {
      store.createContainerInLocation(null, bucketName);

      for (StorageMetadata metadata : store.list()) {
        if (metadata.getName().equals(bucketName)) {
          container = metadata;
          break;
        }
      }

      assertNotNull(container);

      store.putBlob(
          bucketName,
          store.blobBuilder(blobName).payload("This is a test!").contentType("text/plain").build());

      assertNotNull(store.getBlob(bucketName, blobName));
    } finally {
      if (container != null) {
        store.deleteContainer(bucketName);
      }
    }

    // Try to create the same bucket successfully created above in one of the non-US regions to
    // ensure an error is
    // encountered as expected.
    Location location = null;

    for (Location pLocation : store.listAssignableLocations()) {
      if (!ImmutableSet.of(Region.US_STANDARD, Region.US_EAST_1, Region.US_WEST_1, Region.US_WEST_2)
          .contains(pLocation.getId())) {
        location = pLocation;
        break;
      }
    }

    try {
      store.createContainerInLocation(location, bucketName);
      fail("Should had failed because in non-US regions, mixed-case bucket names are invalid.");
    } catch (AWSResponseException e) {
      assertEquals("InvalidBucketName", e.getError().getCode());
    }
  }
  @Test
  void testToBlob() {
    assertNull(ToBlob.INSTANCE.apply(null));
    BlobStore blobStore = getBlobStore();
    blobStore.createContainerInLocation(null, "container");
    blobStore.createDirectory("container", "one");

    blobStore.putBlob(
        "container",
        blobStore.blobBuilder("myblob").payload(ByteSource.wrap("testcontent".getBytes())).build());
    Blob representation = ToBlob.INSTANCE.apply(blobStore.getBlob("container", "myblob"));
    assertNotNull(representation);
    assertNotNull(representation.getBlobMetadata());
  }