From 435103eb35ca1f1fa16d96938da2a52b58d8345e Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 6 Aug 2013 11:46:03 -0700 Subject: [PATCH] Add live test for JCLOUDS-233 --- .../AzureBlobIntegrationLiveTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java index 82b07b334e..a7b104d12c 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java @@ -19,10 +19,13 @@ package org.jclouds.azureblob.blobstore.integration; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.concurrent.ExecutionException; +import com.google.common.io.ByteStreams; import com.google.common.io.Files; import com.google.common.io.InputSupplier; +import org.jclouds.azureblob.blobstore.strategy.MultipartUploadStrategy; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest; @@ -95,4 +98,53 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest { returnContainer(containerName); } } + + public void testMultipartChunkedFileStreamPowerOfTwoSize() throws IOException, InterruptedException { + final long limit = MultipartUploadStrategy.MAX_BLOCK_SIZE; + InputSupplier input = new InputSupplier() { + @Override + public InputStream getInput() throws IOException { + return ByteStreams.limit(ZERO_INPUT_STREAM, limit); + } + }; + File file = new File("target/const.txt"); + Files.copy(input, file); + String containerName = getContainerName(); + + try { + BlobStore blobStore = view.getBlobStore(); + blobStore.createContainerInLocation(null, containerName); + Blob blob = blobStore.blobBuilder("const.txt").payload(file).build(); + String expected = blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart()); + String etag = blobStore.blobMetadata(containerName, "const.txt").getETag(); + assertEquals(etag, expected); + } finally { + returnContainer(containerName); + } + } + + /** An infinite-length zero byte InputStream. */ + // Guava feature request: + // https://code.google.com/p/guava-libraries/issues/detail?id=1370 + private static final InputStream ZERO_INPUT_STREAM = new InputStream() { + @Override + public int read() { + return 0; + } + + @Override + public int read(final byte[] b) { + return read(b, 0, b.length); + } + + @Override + public int read(final byte[] b, final int off, final int len) { + if (off < 0 || len < 0 || len > b.length - off) { + throw new IndexOutOfBoundsException(); + } + int length = Math.min(len, b.length - off); + Arrays.fill(b, off, length, (byte) 0); + return length; + } + }; }