Package org.jclouds.blobstore

Examples of org.jclouds.blobstore.BlobStore


      File file = new File("target/const.txt");
      Files.copy(oneHundredOneConstitutions, file);
      String containerName = getContainerName();
     
      try {
         BlobStore blobStore = view.getBlobStore();
         blobStore.createContainerInLocation(null, containerName);
         Blob blob = blobStore.blobBuilder("const.txt").payload(file).build();
         blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());

      } finally {
         returnContainer(containerName);
      }
   }
View Full Code Here


   public void testPutWithReducedRedundancyStorage() throws InterruptedException {
      String containerName = getContainerName();
      try {
         String blobName = "test-rrs";
         BlobStore blobStore = view.getBlobStore();
         blobStore.createContainerInLocation(null, containerName);

         Blob blob = blobStore.blobBuilder(blobName).payload("something").build();
         blobStore.putBlob(containerName, blob,
            storageClass(StorageClass.REDUCED_REDUNDANCY));

         S3Client s3Client = S3Client.class.cast(view.unwrap(AWSS3ApiMetadata.CONTEXT_TOKEN).getApi());
         ListBucketResponse response = s3Client.listBucket(containerName, withPrefix(blobName));
View Full Code Here

    */
   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());
      }
   }
View Full Code Here

   }

   public void testDirectoryEndingWithSlash() throws InterruptedException {
     String containerName = getContainerName();
     try {
       BlobStore blobStore = view.getBlobStore();
       blobStore.createDirectory(containerName, "someDir");

       // According to the S3 documentation, a directory is nothing but a blob
       // whose name ends with a '/'. So let's try to remove the blob we just
       // created.
       blobStore.removeBlob(containerName, "someDir/");

       // The directory "someDir" shouldn't exist since we removed it. If this
       // test succeeds, it confirms that a directory (or folder) is nothing
       // but a blob with a name ending in '/'.
       assertEquals(blobStore.directoryExists(containerName, "someDir"), false);
     } finally {
       returnContainer(containerName);
     }
   }
View Full Code Here

    public void testListObjectsWhenResponseIs2xx() throws Exception {
        Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder().put(
                 keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess).build();

        BlobStore clientWhenLocationsExist = requestsSendResponses(requestResponseMap);

        Set<? extends Location> locations = clientWhenLocationsExist.listAssignableLocations();
        assertNotNull(locations);
        assertEquals(locations.size(), 1);
        assertEquals(locations.iterator().next().getId(), "region-a.geo-1");
    }
View Full Code Here

   
   @Test(groups = { "integration", "live" })
   public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
      String containerName = getContainerName();
      try {
         BlobStore blobStore = view.getBlobStore();
         long countBefore = blobStore.countBlobs(containerName);

         addMultipartBlobToContainer(containerName, "const.txt");

         long countAfter = blobStore.countBlobs(containerName);
         assertNotEquals(countBefore, countAfter,
                         "No blob was created");
         assertTrue(countAfter - countBefore > 1,
                    "A multipart blob wasn't actually created - " +
                    "there was only 1 extra blob but there should be one manifest blob and multiple chunk blobs");
View Full Code Here

   // InputStreamPayloads are handled differently than File; Test InputStreams too
   @Test(groups = { "integration", "live" })
   public void testMultipartChunkedInputStream() throws InterruptedException, IOException {
      String container = getContainerName();
      try {
         BlobStore blobStore = view.getBlobStore();

         blobStore.createContainerInLocation(null, container);

         File inFile = createFileBiggerThan(PART_SIZE);
         File outFile = new File("target/lots-of-const-readback.txt");

         InputStream contentToUpload = new FileInputStream(inFile);
         Blob write = blobStore.blobBuilder("const.txt").payload(contentToUpload).contentLength(inFile.length()).build();
         blobStore.putBlob(container, write, PutOptions.Builder.multipart());

         Blob read = blobStore.getBlob(container, "const.txt");
         read.getPayload().writeTo(new FileOutputStream(outFile));

         assertEquals(Files.hash(outFile, Hashing.md5()), Files.hash(inFile, Hashing.md5()));

      } finally {
View Full Code Here

   }

   protected void addMultipartBlobToContainer(String containerName, String key) throws IOException {
      File fileToUpload = createFileBiggerThan(PART_SIZE);

      BlobStore blobStore = view.getBlobStore();
      blobStore.createContainerInLocation(null, containerName);
      Blob blob = blobStore.blobBuilder(key)
         .payload(fileToUpload)
         .build();
      blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());
   }
View Full Code Here

            .addHeader("Authorization", "AWS identity:0uvBv1wEskuhFHYJF/L6kEV9A7o=").build();
   }

   @Test
   public void testSignGetBlobWithTime() {
      BlobStore getBlobWithTime = requestsSendResponses(init());
      HttpRequest compare = getBlobWithTime();
      assertEquals(getBlobWithTime.getContext().getSigner().signGetBlob(container, name, 3l /* seconds */),
         compare);
   }
View Full Code Here

            .addHeader("Authorization", "AWS identity:4FnyjdX/ULdDMRbVlLNjZfEo9RQ=").build();
   }

   @Test
   public void testSignPutBlobWithTime() throws Exception {
      BlobStore signPutBloblWithTime = requestsSendResponses(init());
      Blob blob = signPutBloblWithTime.blobBuilder(name).payload(text).contentType("text/plain").build();
      HttpRequest compare = putBlobWithTime();
      compare.setPayload(blob.getPayload());
      assertEquals(signPutBloblWithTime.getContext().getSigner().signPutBlob(container, blob, 3l /* seconds */),
         compare);
   }
View Full Code Here

TOP

Related Classes of org.jclouds.blobstore.BlobStore

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.