Add live test for JCLOUDS-233

Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/435103eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/435103eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/435103eb

Branch: refs/heads/master
Commit: 435103eb35ca1f1fa16d96938da2a52b58d8345e
Parents: 19f7914
Author: Andrew Gaul <[email protected]>
Authored: Tue Aug 6 11:46:03 2013 -0700
Committer: Andrew Gaul <[email protected]>
Committed: Tue Aug 6 11:53:48 2013 -0700

----------------------------------------------------------------------
 .../AzureBlobIntegrationLiveTest.java           | 52 ++++++++++++++++++++
 1 file changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/435103eb/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java
----------------------------------------------------------------------
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 82b07b3..a7b104d 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<InputStream> input = new InputSupplier<InputStream>() {
+         @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;
+      }
+   };
 }

Reply via email to