You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2014/05/22 19:46:04 UTC
git commit: Use ByteSource methods to create test input
Repository: jclouds
Updated Branches:
refs/heads/master 4c265d316 -> 26b53e52b
Use ByteSource methods to create test input
Also avoids excessive system calls due to unbuffered writes. Finally
migrate repeatingArrayByteSource to ByteSources.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/26b53e52
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/26b53e52
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/26b53e52
Branch: refs/heads/master
Commit: 26b53e52b7e758cd1052c3430e79871284b9b30e
Parents: 4c265d3
Author: Andrew Gaul <ga...@apache.org>
Authored: Thu May 22 10:43:57 2014 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Thu May 22 10:43:57 2014 -0700
----------------------------------------------------------------------
.../main/java/org/jclouds/io/ByteSources.java | 5 +++++
...ttpCommandExecutorServiceIntegrationTest.java | 19 +++++--------------
.../AzureBlobIntegrationLiveTest.java | 8 ++------
3 files changed, 12 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/26b53e52/core/src/main/java/org/jclouds/io/ByteSources.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/jclouds/io/ByteSources.java b/core/src/main/java/org/jclouds/io/ByteSources.java
index 06fe135..7055664 100644
--- a/core/src/main/java/org/jclouds/io/ByteSources.java
+++ b/core/src/main/java/org/jclouds/io/ByteSources.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import com.google.common.annotations.Beta;
+import com.google.common.collect.Iterables;
import com.google.common.io.ByteSource;
/**
@@ -48,4 +49,8 @@ public class ByteSources {
};
}
+ /** Create an infinite-length ByteSource which repeats its input. */
+ public static ByteSource repeatingArrayByteSource(final byte[] input) {
+ return ByteSource.concat(Iterables.cycle(ByteSource.wrap(input)));
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/26b53e52/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java
index f3c2729..c10a354 100644
--- a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java
+++ b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java
@@ -32,11 +32,12 @@ import static org.testng.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Writer;
import java.net.URLDecoder;
+import java.util.Arrays;
import java.util.Random;
import java.util.zip.GZIPInputStream;
+import org.jclouds.io.ByteSources;
import org.jclouds.io.Payload;
import org.jclouds.util.Strings2;
import org.testng.annotations.BeforeClass;
@@ -48,7 +49,6 @@ import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import com.google.common.io.ByteSource;
-import com.google.common.io.CharSink;
import com.google.common.io.Files;
import com.squareup.okhttp.mockwebserver.Dispatcher;
import com.squareup.okhttp.mockwebserver.MockResponse;
@@ -277,18 +277,9 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
f = File.createTempFile("jclouds", "tmp");
f.deleteOnExit();
long length = (new Random().nextInt(32) + 1) * 1024 * 1024;
-
- CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
- Writer out = null;
- try {
- out = fileSink.openStream();
- for (long i = 0; i < length; i++) {
- out.append('a');
- }
- out.flush();
- } finally {
- close(out, true);
- }
+ byte[] buf = new byte[1024];
+ Arrays.fill(buf, (byte) 'a');
+ ByteSources.repeatingArrayByteSource(buf).slice(0, length).copyTo(Files.asByteSink(f));
ByteSource byteSource = asByteSource(f);
payload = newByteSourcePayload(byteSource);
http://git-wip-us.apache.org/repos/asf/jclouds/blob/26b53e52/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 2c4060f..6238002 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
@@ -20,7 +20,6 @@ import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
-import com.google.common.collect.Iterables;
import com.google.common.io.ByteSource;
import com.google.common.io.Files;
import org.jclouds.azureblob.blobstore.strategy.MultipartUploadStrategy;
@@ -28,6 +27,7 @@ import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
import org.jclouds.blobstore.options.PutOptions;
+import org.jclouds.io.ByteSources;
import org.testng.SkipException;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
@@ -98,7 +98,7 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
public void testMultipartChunkedFileStreamPowerOfTwoSize() throws IOException, InterruptedException {
final long limit = MultipartUploadStrategy.MAX_BLOCK_SIZE;
- ByteSource input = repeatingArrayByteSource(new byte[1024]).slice(0, limit);
+ ByteSource input = ByteSources.repeatingArrayByteSource(new byte[1024]).slice(0, limit);
File file = new File("target/const.txt");
input.copyTo(Files.asByteSink(file));
String containerName = getContainerName();
@@ -114,8 +114,4 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
returnContainer(containerName);
}
}
-
- private static ByteSource repeatingArrayByteSource(final byte[] input) {
- return ByteSource.concat(Iterables.cycle(ByteSource.wrap(input)));
- }
}