mirror of https://github.com/apache/jclouds.git
JCLOUDS-801: Add portable multipart upload tests
Exercise both repeatable and non-repeatable payloads. Tested against AWS-S3, Azure, and legacy Swift. Skipped on all other providers.
This commit is contained in:
parent
38ebf0d06c
commit
91c47bfd92
|
@ -65,6 +65,11 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
|||
provider = System.getProperty("test.swift.provider", "swift");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getMinimumMultipartBlobSize() {
|
||||
return PART_SIZE + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test(enabled = false)
|
||||
public void testGetTwoRanges() {
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.jclouds.blobstore.integration.internal;
|
|||
|
||||
import static com.google.common.base.Charsets.UTF_8;
|
||||
import static com.google.common.hash.Hashing.md5;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.jclouds.blobstore.options.GetOptions.Builder.ifETagDoesntMatch;
|
||||
import static org.jclouds.blobstore.options.GetOptions.Builder.ifETagMatches;
|
||||
import static org.jclouds.blobstore.options.GetOptions.Builder.ifModifiedSince;
|
||||
|
@ -32,6 +33,7 @@ import static org.testng.Assert.fail;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.Date;
|
||||
|
@ -53,15 +55,19 @@ import org.jclouds.blobstore.domain.BlobMetadata;
|
|||
import org.jclouds.blobstore.domain.PageSet;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageType;
|
||||
import org.jclouds.blobstore.options.PutOptions;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.encryption.internal.JCECrypto;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.io.payloads.ByteSourcePayload;
|
||||
import org.jclouds.io.payloads.InputStreamPayload;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Closeables2;
|
||||
import org.jclouds.utils.TestUtils;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.SkipException;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -517,6 +523,77 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testPutByteSource() throws Exception {
|
||||
long length = 42;
|
||||
ByteSource byteSource = TestUtils.randomByteSource().slice(0, length);
|
||||
Payload payload = new ByteSourcePayload(byteSource);
|
||||
testPut(payload, payload, length, new PutOptions());
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testPutInputStream() throws Exception {
|
||||
long length = 42;
|
||||
ByteSource byteSource = TestUtils.randomByteSource().slice(0, length);
|
||||
Payload payload = new InputStreamPayload(byteSource.openStream());
|
||||
testPut(payload, new ByteSourcePayload(byteSource), length, new PutOptions());
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testPutMultipartByteSource() throws Exception {
|
||||
long length = getMinimumMultipartBlobSize();
|
||||
ByteSource byteSource = TestUtils.randomByteSource().slice(0, length);
|
||||
Payload payload = new ByteSourcePayload(byteSource);
|
||||
testPut(payload, payload, length, new PutOptions().multipart(true));
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testPutMultipartInputStream() throws Exception {
|
||||
long length = getMinimumMultipartBlobSize();
|
||||
ByteSource byteSource = TestUtils.randomByteSource().slice(0, length);
|
||||
Payload payload = new InputStreamPayload(byteSource.openStream());
|
||||
testPut(payload, new ByteSourcePayload(byteSource), length, new PutOptions().multipart(true));
|
||||
}
|
||||
|
||||
private void testPut(Payload payload, Payload expectedPayload, long length, PutOptions options)
|
||||
throws IOException, InterruptedException {
|
||||
BlobStore blobStore = view.getBlobStore();
|
||||
String blobName = "multipart-upload";
|
||||
Map<String, String> userMetadata = ImmutableMap.of("key1", "value1", "key2", "value2");
|
||||
PayloadBlobBuilder blobBuilder = blobStore.blobBuilder(blobName)
|
||||
.userMetadata(userMetadata)
|
||||
.payload(payload)
|
||||
.contentLength(length);
|
||||
addContentMetadata(blobBuilder);
|
||||
|
||||
String container = getContainerName();
|
||||
try {
|
||||
String etag = blobStore.putBlob(container, blobBuilder.build(), options);
|
||||
assertThat(etag).isNotNull();
|
||||
|
||||
Blob blob = blobStore.getBlob(container, blobName);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = blob.getPayload().openStream();
|
||||
assertThat(is).hasContentEqualTo(expectedPayload.openStream());
|
||||
} finally {
|
||||
Closeables2.closeQuietly(is);
|
||||
}
|
||||
validateMetadata(blob.getMetadata(), container, blob.getMetadata().getName());
|
||||
checkContentMetadata(blob);
|
||||
assertThat(blob.getMetadata().getUserMetadata()).isEqualTo(userMetadata);
|
||||
|
||||
PageSet<? extends StorageMetadata> set = blobStore.list(container);
|
||||
assertThat(set).hasSize(1);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
}
|
||||
}
|
||||
|
||||
protected long getMinimumMultipartBlobSize() {
|
||||
throw new SkipException("multipart upload not supported");
|
||||
}
|
||||
|
||||
protected void checkContentMetadata(Blob blob) {
|
||||
checkContentType(blob, "text/csv");
|
||||
checkContentDisposition(blob, "attachment; filename=photo.jpg");
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.blobstore.integration;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.aws.s3.blobstore.strategy.MultipartUpload;
|
||||
import org.jclouds.s3.blobstore.integration.S3BlobIntegrationLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -24,4 +27,16 @@ public class AWSS3BlobIntegrationLiveTest extends S3BlobIntegrationLiveTest {
|
|||
public AWSS3BlobIntegrationLiveTest() {
|
||||
provider = "aws-s3";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties props = super.setupProperties();
|
||||
props.setProperty("jclouds.mpu.parts.size", String.valueOf(MultipartUpload.MIN_PART_SIZE));
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getMinimumMultipartBlobSize() {
|
||||
return MultipartUpload.MIN_PART_SIZE + 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,11 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
|||
private ByteSource oneHundredOneConstitutions;
|
||||
private byte[] oneHundredOneConstitutionsMD5;
|
||||
|
||||
@Override
|
||||
protected long getMinimumMultipartBlobSize() {
|
||||
return MultipartUploadStrategy.MAX_BLOCK_SIZE + 1;
|
||||
}
|
||||
|
||||
public AzureBlobIntegrationLiveTest() {
|
||||
provider = "azureblob";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue