mirror of https://github.com/apache/jclouds.git
Use ByteSource methods to create test input
Also avoids excessive system calls due to unbuffered writes. Finally migrate repeatingArrayByteSource to ByteSources.
This commit is contained in:
parent
4c265d3168
commit
26b53e52b7
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.io.ByteSource;
|
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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,12 @@ import static org.testng.Assert.fail;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Writer;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import org.jclouds.io.ByteSources;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
import org.testng.annotations.BeforeClass;
|
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.ImmutableList;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.CharSink;
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.squareup.okhttp.mockwebserver.Dispatcher;
|
import com.squareup.okhttp.mockwebserver.Dispatcher;
|
||||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||||
|
@ -277,18 +277,9 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
f = File.createTempFile("jclouds", "tmp");
|
f = File.createTempFile("jclouds", "tmp");
|
||||||
f.deleteOnExit();
|
f.deleteOnExit();
|
||||||
long length = (new Random().nextInt(32) + 1) * 1024 * 1024;
|
long length = (new Random().nextInt(32) + 1) * 1024 * 1024;
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
|
Arrays.fill(buf, (byte) 'a');
|
||||||
Writer out = null;
|
ByteSources.repeatingArrayByteSource(buf).slice(0, length).copyTo(Files.asByteSink(f));
|
||||||
try {
|
|
||||||
out = fileSink.openStream();
|
|
||||||
for (long i = 0; i < length; i++) {
|
|
||||||
out.append('a');
|
|
||||||
}
|
|
||||||
out.flush();
|
|
||||||
} finally {
|
|
||||||
close(out, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteSource byteSource = asByteSource(f);
|
ByteSource byteSource = asByteSource(f);
|
||||||
payload = newByteSourcePayload(byteSource);
|
payload = newByteSourcePayload(byteSource);
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import org.jclouds.azureblob.blobstore.strategy.MultipartUploadStrategy;
|
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.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
|
||||||
import org.jclouds.blobstore.options.PutOptions;
|
import org.jclouds.blobstore.options.PutOptions;
|
||||||
|
import org.jclouds.io.ByteSources;
|
||||||
import org.testng.SkipException;
|
import org.testng.SkipException;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
@ -98,7 +98,7 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
||||||
|
|
||||||
public void testMultipartChunkedFileStreamPowerOfTwoSize() throws IOException, InterruptedException {
|
public void testMultipartChunkedFileStreamPowerOfTwoSize() throws IOException, InterruptedException {
|
||||||
final long limit = MultipartUploadStrategy.MAX_BLOCK_SIZE;
|
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");
|
File file = new File("target/const.txt");
|
||||||
input.copyTo(Files.asByteSink(file));
|
input.copyTo(Files.asByteSink(file));
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
|
@ -114,8 +114,4 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
||||||
returnContainer(containerName);
|
returnContainer(containerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ByteSource repeatingArrayByteSource(final byte[] input) {
|
|
||||||
return ByteSource.concat(Iterables.cycle(ByteSource.wrap(input)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue