Handle when total length is less than part length

This commit is contained in:
Andrew Gaul 2016-06-01 22:01:38 -07:00
parent a67ae3f27b
commit bc1f12b7bd
2 changed files with 7 additions and 1 deletions

View File

@ -43,6 +43,7 @@ public final class MultipartUploadSlicingAlgorithm {
@VisibleForTesting
static final int DEFAULT_MAGNITUDE_BASE = 100;
// TODO: these are not injected
@Inject(optional = true)
@Named("jclouds.mpu.parts.size")
@VisibleForTesting
@ -108,6 +109,11 @@ public final class MultipartUploadSlicingAlgorithm {
unitPartSize = minimumPartSize; // take the minimum part size
parts = (int)(length / unitPartSize);
}
if (parts == 0) {
partSize = length;
unitPartSize = length;
parts = 1;
}
if (parts > maximumNumberOfParts) { // if still splits in too many parts
parts = maximumNumberOfParts - 1; // limit them. do not care about not
// covering

View File

@ -639,7 +639,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
blobStore.getMinimumMultipartPartSize(), blobStore.getMaximumMultipartPartSize(),
blobStore.getMaximumNumberOfParts());
// make sure that we are creating multiple parts
assertThat(algorithm.calculateChunkSize(length)).isLessThan(length);
assertThat(algorithm.calculateChunkSize(length)).isLessThanOrEqualTo(length);
ByteSource byteSource = TestUtils.randomByteSource().slice(0, length);
Payload payload = new ByteSourcePayload(byteSource);
HashCode hashCode = byteSource.hash(Hashing.md5());