Ejemplo n.º 1
0
 @Test
 public void testCreateEmptyBlob() {
   String blobName = "test-create-empty-blob";
   BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
   BlobInfo remoteBlob = storage.create(blob);
   assertNotNull(remoteBlob);
   assertEquals(blob.blobId(), remoteBlob.blobId());
   byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
   assertArrayEquals(new byte[0], readBytes);
   assertTrue(storage.delete(BUCKET, blobName));
 }
Ejemplo n.º 2
0
 @Test
 public void testWriteChannelExistingBlob() throws IOException {
   String blobName = "test-write-channel-existing-blob";
   BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
   BlobInfo remoteBlob = storage.create(blob);
   byte[] stringBytes;
   try (BlobWriteChannel writer = storage.writer(remoteBlob)) {
     stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8);
     writer.write(ByteBuffer.wrap(stringBytes));
   }
   assertArrayEquals(stringBytes, storage.readAllBytes(blob.blobId()));
   assertTrue(storage.delete(BUCKET, blobName));
 }
Ejemplo n.º 3
0
 @Test
 public void testCreateBlobStream() throws UnsupportedEncodingException {
   String blobName = "test-create-blob-stream";
   BlobInfo blob = BlobInfo.builder(BUCKET, blobName).contentType(CONTENT_TYPE).build();
   ByteArrayInputStream stream = new ByteArrayInputStream(BLOB_STRING_CONTENT.getBytes(UTF_8));
   BlobInfo remoteBlob = storage.create(blob, stream);
   assertNotNull(remoteBlob);
   assertEquals(blob.blobId(), remoteBlob.blobId());
   assertEquals(blob.contentType(), remoteBlob.contentType());
   byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
   assertEquals(BLOB_STRING_CONTENT, new String(readBytes, UTF_8));
   assertTrue(storage.delete(BUCKET, blobName));
 }
Ejemplo n.º 4
0
 @Test
 public void testComposeBlob() {
   String sourceBlobName1 = "test-compose-blob-source-1";
   String sourceBlobName2 = "test-compose-blob-source-2";
   BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
   BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
   assertNotNull(storage.create(sourceBlob1, BLOB_BYTE_CONTENT));
   assertNotNull(storage.create(sourceBlob2, BLOB_BYTE_CONTENT));
   String targetBlobName = "test-compose-blob-target";
   BlobInfo targetBlob = BlobInfo.builder(BUCKET, targetBlobName).build();
   Storage.ComposeRequest req =
       Storage.ComposeRequest.of(ImmutableList.of(sourceBlobName1, sourceBlobName2), targetBlob);
   BlobInfo remoteBlob = storage.compose(req);
   assertNotNull(remoteBlob);
   assertEquals(targetBlob.blobId(), remoteBlob.blobId());
   byte[] readBytes = storage.readAllBytes(BUCKET, targetBlobName);
   byte[] composedBytes = Arrays.copyOf(BLOB_BYTE_CONTENT, BLOB_BYTE_CONTENT.length * 2);
   System.arraycopy(
       BLOB_BYTE_CONTENT, 0, composedBytes, BLOB_BYTE_CONTENT.length, BLOB_BYTE_CONTENT.length);
   assertArrayEquals(composedBytes, readBytes);
   assertTrue(storage.delete(BUCKET, sourceBlobName1));
   assertTrue(storage.delete(BUCKET, sourceBlobName2));
   assertTrue(storage.delete(BUCKET, targetBlobName));
 }