@Test(groups = { "integration", "live" }) public void testPutMultipartByteSource() throws Exception { long length = Math.max(getMinimumMultipartBlobSize(), MultipartUploadSlicingAlgorithm.DEFAULT_PART_SIZE + 1); BlobStore blobStore = view.getBlobStore(); MultipartUploadSlicingAlgorithm algorithm = new MultipartUploadSlicingAlgorithm( blobStore.getMinimumMultipartPartSize(), blobStore.getMaximumMultipartPartSize(), blobStore.getMaximumNumberOfParts()); // make sure that we are creating multiple parts assertThat(algorithm.calculateChunkSize(length)).isLessThan(length); ByteSource byteSource = TestUtils.randomByteSource().slice(0, length); Payload payload = new ByteSourcePayload(byteSource); HashCode hashCode = byteSource.hash(Hashing.md5()); testPut(payload, hashCode, payload, length, new PutOptions().multipart(true)); }
@Test(groups = { "integration", "live" }) public void testPutMultipartInputStream() throws Exception { long length = Math.max(getMinimumMultipartBlobSize(), MultipartUploadSlicingAlgorithm.DEFAULT_PART_SIZE + 1); BlobStore blobStore = view.getBlobStore(); MultipartUploadSlicingAlgorithm algorithm = new MultipartUploadSlicingAlgorithm( blobStore.getMinimumMultipartPartSize(), blobStore.getMaximumMultipartPartSize(), blobStore.getMaximumNumberOfParts()); // make sure that we are creating multiple parts assertThat(algorithm.calculateChunkSize(length)).isLessThan(length); ByteSource byteSource = TestUtils.randomByteSource().slice(0, length); Payload payload = new InputStreamPayload(byteSource.openStream()); testPut(payload, null, new ByteSourcePayload(byteSource), length, new PutOptions().multipart(true)); }
@Test(groups = { "integration", "live" }) public void testPutBlobAccessMultipart() throws Exception { BlobStore blobStore = view.getBlobStore(); String containerName = getContainerName(); ByteSource byteSource = TestUtils.randomByteSource().slice(0, getMinimumMultipartBlobSize()); Payload payload = Payloads.newByteSourcePayload(byteSource); payload.getContentMetadata().setContentLength(byteSource.size()); try { String blobNamePrivate = "put-access-blob-name-private"; Blob blobPrivate = blobStore.blobBuilder(blobNamePrivate).payload(payload).build(); blobStore.putBlob(containerName, blobPrivate, new PutOptions().setBlobAccess(BlobAccess.PRIVATE).multipart(true)); assertThat(blobStore.getBlobAccess(containerName, blobNamePrivate)).isEqualTo(BlobAccess.PRIVATE); String blobNamePublic = "put-access-blob-name-public"; Blob blobPublic = blobStore.blobBuilder(blobNamePublic).payload(payload).build(); blobStore.putBlob(containerName, blobPublic, new PutOptions().setBlobAccess(BlobAccess.PUBLIC_READ).multipart(true)); assertThat(blobStore.getBlobAccess(containerName, blobNamePublic)).isEqualTo(BlobAccess.PUBLIC_READ); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testGetRangeMultipart() throws InterruptedException, IOException { String container = getContainerName(); InputStream expect = null; InputStream actual = null; try { String name = "apples"; long length = getMinimumMultipartBlobSize(); ByteSource byteSource = TestUtils.randomByteSource().slice(0, length); Blob blob = view.getBlobStore().blobBuilder(name) .payload(byteSource) .contentLength(length) .build(); view.getBlobStore().putBlob(container, blob, new PutOptions().multipart(true)); blob = view.getBlobStore().getBlob(container, name, range(0, 5)); validateMetadata(blob.getMetadata(), container, name); expect = byteSource.slice(0, 6).openStream(); actual = blob.getPayload().openStream(); assertThat(actual).hasContentEqualTo(expect); } finally { Closeables2.closeQuietly(expect); Closeables2.closeQuietly(actual); returnContainer(container); } }