Updated Branches:
  refs/heads/1.6.x 8cbd2bb7f -> f6cf6a19b

Reduce testFileGetParallel input size to ~160 KB

Previously this test downloaded 45 MB in 30 seconds which failed on
slower connections, causing spurious test failures.  The larger input
size provides no benefit.


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

Branch: refs/heads/1.6.x
Commit: f6cf6a19b85d4657dd489fad46edac21d4497c9d
Parents: 8cbd2bb
Author: Andrew Gaul <[email protected]>
Authored: Mon Sep 2 19:58:40 2013 -0700
Committer: Andrew Gaul <[email protected]>
Committed: Wed Sep 4 19:51:19 2013 -0700

----------------------------------------------------------------------
 .../internal/BaseBlobIntegrationTest.java       | 34 ++++++++++++--------
 1 file changed, 21 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/f6cf6a19/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
 
b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
index f0376e8..a6bcb6d 100644
--- 
a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
+++ 
b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
@@ -64,6 +64,7 @@ import org.jclouds.http.HttpResponseException;
 import org.jclouds.io.Payload;
 import org.jclouds.io.Payloads;
 import org.jclouds.io.WriteTo;
+import org.jclouds.io.payloads.InputStreamSupplierPayload;
 import org.jclouds.io.payloads.StreamingPayload;
 import org.jclouds.logging.Logger;
 import org.testng.ITestContext;
@@ -100,7 +101,7 @@ public class BaseBlobIntegrationTest extends 
BaseBlobStoreIntegrationTest {
       oneHundredOneConstitutionsMD5 = md5Supplier(oneHundredOneConstitutions);
    }
 
-   protected static byte[] md5Supplier(InputSupplier<InputStream> supplier) 
throws IOException {
+   protected static byte[] md5Supplier(InputSupplier<? extends InputStream> 
supplier) throws IOException {
       return asByteSource(supplier.getInput()).hash(md5()).asBytes();
    }
 
@@ -127,7 +128,7 @@ public class BaseBlobIntegrationTest extends 
BaseBlobStoreIntegrationTest {
    public void testPutFileParallel() throws InterruptedException, IOException, 
TimeoutException {
 
       File payloadFile = File.createTempFile("testPutFileParallel", "png");
-      Files.write(createTestInput(32 * 1024), payloadFile);
+      Files.copy(createTestInput(32 * 1024), payloadFile);
       
       final Payload testPayload = Payloads.newFilePayload(payloadFile);
       final byte[] md5 = md5Supplier(testPayload);
@@ -170,13 +171,14 @@ public class BaseBlobIntegrationTest extends 
BaseBlobStoreIntegrationTest {
    }
 
    @Test(groups = { "integration", "live" })
-   public void testBigFileGets() throws Exception {
+   public void testFileGetParallel() throws Exception {
+      final InputSupplier<? extends InputStream> supplier = createTestInput(32 
* 1024);
       final String expectedContentDisposition = "attachment; 
filename=constit.txt";
       final String container = getContainerName();
       try {
          final String name = "constitution.txt";
 
-         uploadConstitution(container, name, expectedContentDisposition);
+         uploadInputSupplier(container, name, expectedContentDisposition, 
supplier);
          Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap();
          for (int i = 0; i < 10; i++) {
 
@@ -187,7 +189,7 @@ public class BaseBlobIntegrationTest extends 
BaseBlobStoreIntegrationTest {
                         public Void apply(Blob from) {
                            try {
                               validateMetadata(from.getMetadata(), container, 
name);
-                              assertEquals(md5Supplier(from.getPayload()), 
oneHundredOneConstitutionsMD5);
+                              assertEquals(md5Supplier(from.getPayload()), 
md5Supplier(supplier));
                               checkContentDisposition(from, 
expectedContentDisposition);
                            } catch (IOException e) {
                               Throwables.propagate(e);
@@ -209,12 +211,16 @@ public class BaseBlobIntegrationTest extends 
BaseBlobStoreIntegrationTest {
 
    }
 
-   private void uploadConstitution(String container, String name, String 
contentDisposition) throws IOException {
-      view.getBlobStore().putBlob(
-               container,
-               
view.getBlobStore().blobBuilder(name).payload(oneHundredOneConstitutions.getInput()).contentType(
-                        
"text/plain").contentMD5(oneHundredOneConstitutionsMD5).contentLength(
-                        
oneHundredOneConstitutionsLength).contentDisposition(contentDisposition).build());
+   private void uploadInputSupplier(String container, String name, String 
contentDisposition,
+         InputSupplier<? extends InputStream> supplier) throws IOException {
+      BlobStore blobStore = view.getBlobStore();
+      blobStore.putBlob(container, blobStore.blobBuilder(name)
+            .payload(new InputStreamSupplierPayload(supplier))
+            .contentType("text/plain")
+            .contentMD5(md5Supplier(supplier))
+            .contentLength(ByteStreams.length(supplier))
+            .contentDisposition(contentDisposition)
+            .build());
    }
 
    @Test(groups = { "integration", "live" })
@@ -606,10 +612,12 @@ public class BaseBlobIntegrationTest extends 
BaseBlobStoreIntegrationTest {
       assertEquals(metadata.getContentMetadata().getContentMD5(), 
md5().hashString(TEST_STRING, UTF_8).asBytes());
    }
 
-   private static byte[] createTestInput(int length) throws IOException {
+   /** @return InputSupplier containing a random length 0..length of random 
bytes. */
+   @SuppressWarnings("unchecked")
+   private static InputSupplier<? extends InputStream> createTestInput(int 
length) {
       Random random = new Random();
       byte[] buffer = new byte[random.nextInt(length)];
       random.nextBytes(buffer);
-      return buffer;
+      return ByteStreams.newInputStreamSupplier(buffer);
    }
 }

Reply via email to