Skip to content

Commit 6cb022a

Browse files
authored
Merge pull request #3580 from aws/zoewang/fixMPU
Fixed contentLength mismatch issue thrown from putObject when multipa…
2 parents 507c093 + 7de2e18 commit 6cb022a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: services/s3/src/it/java/software/amazon/awssdk/services/s3/multipart/S3MultipartClientPutObjectIntegrationTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.Optional;
3737
import java.util.UUID;
3838
import java.util.zip.CRC32;
39+
import java.util.concurrent.ExecutorService;
40+
import java.util.concurrent.Executors;
3941
import java.util.zip.CheckedInputStream;
4042
import javax.crypto.KeyGenerator;
4143
import org.apache.commons.lang3.RandomStringUtils;
@@ -75,6 +77,7 @@ public class S3MultipartClientPutObjectIntegrationTest extends S3IntegrationTest
7577
private static final byte[] CONTENT = RandomStringUtils.randomAscii(OBJ_SIZE).getBytes(Charset.defaultCharset());
7678
private static File testFile;
7779
private static S3AsyncClient mpuS3Client;
80+
private static ExecutorService executorService = Executors.newFixedThreadPool(2);
7881

7982
@BeforeAll
8083
public static void setup() throws Exception {
@@ -97,6 +100,7 @@ public static void teardown() throws Exception {
97100
mpuS3Client.close();
98101
testFile.delete();
99102
deleteBucketAndAllContents(TEST_BUCKET);
103+
executorService.shutdown();
100104
}
101105

102106
@BeforeEach
@@ -120,6 +124,27 @@ void putObject_fileRequestBody_objectSentCorrectly() throws Exception {
120124
assertThat(ChecksumUtils.computeCheckSum(objContent)).isEqualTo(expectedSum);
121125
}
122126

127+
@Test
128+
void putObject_inputStreamAsyncRequestBody_objectSentCorrectly() throws Exception {
129+
AsyncRequestBody body = AsyncRequestBody.fromInputStream(
130+
new ByteArrayInputStream(CONTENT),
131+
Long.valueOf(OBJ_SIZE),
132+
executorService);
133+
mpuS3Client.putObject(r -> r.bucket(TEST_BUCKET)
134+
.key(TEST_KEY)
135+
.contentLength(Long.valueOf(OBJ_SIZE)), body).join();
136+
137+
assertThat(CAPTURING_INTERCEPTOR.createMpuChecksumAlgorithm).isEqualTo("CRC32");
138+
assertThat(CAPTURING_INTERCEPTOR.uploadPartChecksumAlgorithm).isEqualTo("CRC32");
139+
140+
ResponseInputStream<GetObjectResponse> objContent = s3.getObject(r -> r.bucket(TEST_BUCKET).key(TEST_KEY),
141+
ResponseTransformer.toInputStream());
142+
143+
assertThat(objContent.response().contentLength()).isEqualTo(testFile.length());
144+
byte[] expectedSum = ChecksumUtils.computeCheckSum(Files.newInputStream(testFile.toPath()));
145+
assertThat(ChecksumUtils.computeCheckSum(objContent)).isEqualTo(expectedSum);
146+
}
147+
123148
@Test
124149
void putObject_byteAsyncRequestBody_objectSentCorrectly() throws Exception {
125150
byte[] bytes = RandomStringUtils.randomAscii(OBJ_SIZE).getBytes(Charset.defaultCharset());

Diff for: services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/multipart/SdkPojoConversionUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final class SdkPojoConversionUtils {
5151

5252
protected static final Set<String> PUT_OBJECT_REQUEST_TO_UPLOAD_PART_FIELDS_TO_IGNORE =
5353
new HashSet<>(Arrays.asList("ChecksumSHA1", "ChecksumSHA256", "ContentMD5", "ChecksumCRC32C", "ChecksumCRC32",
54-
"ChecksumCRC64NVME"));
54+
"ChecksumCRC64NVME", "ContentLength"));
5555

5656
private SdkPojoConversionUtils() {
5757
}

0 commit comments

Comments
 (0)