@@ -249,7 +249,7 @@ public void testSingleUpload() throws Exception {
249249 // was interpreted as an inconsistent write.
250250 MultipartUploader completer = uploader0 ;
251251 // and upload with uploader 1 to validate cross-uploader uploads
252- PartHandle partHandle = putPart (file , uploadHandle , 1 , payload );
252+ PartHandle partHandle = putPart (file , uploadHandle , 1 , true , payload );
253253 partHandles .put (1 , partHandle );
254254 PathHandle fd = complete (completer , uploadHandle , file ,
255255 partHandles );
@@ -317,12 +317,13 @@ protected PartHandle buildAndPutPart(
317317 final Path file ,
318318 final UploadHandle uploadHandle ,
319319 final int index ,
320+ final boolean isLastPart ,
320321 final MessageDigest origDigest ) throws IOException {
321322 byte [] payload = generatePayload (index );
322323 if (origDigest != null ) {
323324 origDigest .update (payload );
324325 }
325- return putPart (file , uploadHandle , index , payload );
326+ return putPart (file , uploadHandle , index , isLastPart , payload );
326327 }
327328
328329 /**
@@ -331,13 +332,15 @@ protected PartHandle buildAndPutPart(
331332 * @param file destination
332333 * @param uploadHandle handle
333334 * @param index index of part
335+ * @param isLastPart is last part of the upload ?
334336 * @param payload byte array of payload
335337 * @return the part handle
336338 * @throws IOException IO failure.
337339 */
338340 protected PartHandle putPart (final Path file ,
339341 final UploadHandle uploadHandle ,
340342 final int index ,
343+ final boolean isLastPart ,
341344 final byte [] payload ) throws IOException {
342345 ContractTestUtils .NanoTimer timer = new ContractTestUtils .NanoTimer ();
343346 PartHandle partHandle ;
@@ -347,7 +350,7 @@ protected PartHandle putPart(final Path file,
347350 payload .length ,
348351 file )) {
349352 partHandle = awaitFuture (getUploader (index )
350- .putPart (uploadHandle , index , file ,
353+ .putPart (uploadHandle , index , isLastPart , file ,
351354 new ByteArrayInputStream (payload ),
352355 payload .length ));
353356 }
@@ -488,7 +491,7 @@ public void testMultipartUpload() throws Exception {
488491 MessageDigest origDigest = DigestUtils .getMd5Digest ();
489492 int payloadCount = getTestPayloadCount ();
490493 for (int i = 1 ; i <= payloadCount ; ++i ) {
491- PartHandle partHandle = buildAndPutPart (file , uploadHandle , i ,
494+ PartHandle partHandle = buildAndPutPart (file , uploadHandle , i , i == payloadCount ,
492495 origDigest );
493496 partHandles .put (i , partHandle );
494497 }
@@ -515,7 +518,7 @@ public void testMultipartUploadEmptyPart() throws Exception {
515518 origDigest .update (payload );
516519 InputStream is = new ByteArrayInputStream (payload );
517520 PartHandle partHandle = awaitFuture (
518- uploader .putPart (uploadHandle , 1 , file , is , payload .length ));
521+ uploader .putPart (uploadHandle , 1 , true , file , is , payload .length ));
519522 partHandles .put (1 , partHandle );
520523 completeUpload (file , uploadHandle , partHandles , origDigest , 0 );
521524 }
@@ -530,7 +533,7 @@ public void testUploadEmptyBlock() throws Exception {
530533 Path file = methodPath ();
531534 UploadHandle uploadHandle = startUpload (file );
532535 Map <Integer , PartHandle > partHandles = new HashMap <>();
533- partHandles .put (1 , putPart (file , uploadHandle , 1 , new byte [0 ]));
536+ partHandles .put (1 , putPart (file , uploadHandle , 1 , true , new byte [0 ]));
534537 completeUpload (file , uploadHandle , partHandles , null , 0 );
535538 }
536539
@@ -550,7 +553,8 @@ public void testMultipartUploadReverseOrder() throws Exception {
550553 origDigest .update (payload );
551554 }
552555 for (int i = payloadCount ; i > 0 ; --i ) {
553- partHandles .put (i , buildAndPutPart (file , uploadHandle , i , null ));
556+ partHandles .put (i , buildAndPutPart (file , uploadHandle , i , i == payloadCount ,
557+ null ));
554558 }
555559 completeUpload (file , uploadHandle , partHandles , origDigest ,
556560 payloadCount * partSizeInBytes ());
@@ -574,7 +578,8 @@ public void testMultipartUploadReverseOrderNonContiguousPartNumbers()
574578 }
575579 Map <Integer , PartHandle > partHandles = new HashMap <>();
576580 for (int i = payloadCount ; i > 0 ; i -= 2 ) {
577- partHandles .put (i , buildAndPutPart (file , uploadHandle , i , null ));
581+ partHandles .put (i , buildAndPutPart (file , uploadHandle , i , i == payloadCount ,
582+ null ));
578583 }
579584 completeUpload (file , uploadHandle , partHandles , origDigest ,
580585 getTestPayloadCount () * partSizeInBytes ());
@@ -591,7 +596,7 @@ public void testMultipartUploadAbort() throws Exception {
591596 UploadHandle uploadHandle = startUpload (file );
592597 Map <Integer , PartHandle > partHandles = new HashMap <>();
593598 for (int i = 12 ; i > 10 ; i --) {
594- partHandles .put (i , buildAndPutPart (file , uploadHandle , i , null ));
599+ partHandles .put (i , buildAndPutPart (file , uploadHandle , i , i == 12 , null ));
595600 }
596601 abortUpload (uploadHandle , file );
597602
@@ -601,7 +606,7 @@ public void testMultipartUploadAbort() throws Exception {
601606
602607 intercept (IOException .class ,
603608 () -> awaitFuture (
604- uploader0 .putPart (uploadHandle , 49 , file , is , len )));
609+ uploader0 .putPart (uploadHandle , 49 , true , file , is , len )));
605610 intercept (IOException .class ,
606611 () -> complete (uploader0 , uploadHandle , file , partHandles ));
607612
@@ -701,7 +706,8 @@ public void testPutPartEmptyUploadID() throws Exception {
701706 byte [] payload = generatePayload (1 );
702707 InputStream is = new ByteArrayInputStream (payload );
703708 intercept (IllegalArgumentException .class ,
704- () -> uploader0 .putPart (emptyHandle , 1 , dest , is , payload .length ));
709+ () -> uploader0 .putPart (emptyHandle , 1 , true , dest , is ,
710+ payload .length ));
705711 }
706712
707713 /**
@@ -715,7 +721,7 @@ public void testCompleteEmptyUploadID() throws Exception {
715721 UploadHandle emptyHandle =
716722 BBUploadHandle .from (ByteBuffer .wrap (new byte [0 ]));
717723 Map <Integer , PartHandle > partHandles = new HashMap <>();
718- PartHandle partHandle = putPart (dest , realHandle , 1 ,
724+ PartHandle partHandle = putPart (dest , realHandle , 1 , true ,
719725 generatePayload (1 , SMALL_FILE ));
720726 partHandles .put (1 , partHandle );
721727
@@ -743,7 +749,7 @@ public void testDirectoryInTheWay() throws Exception {
743749 UploadHandle uploadHandle = startUpload (file );
744750 Map <Integer , PartHandle > partHandles = new HashMap <>();
745751 int size = SMALL_FILE ;
746- PartHandle partHandle = putPart (file , uploadHandle , 1 ,
752+ PartHandle partHandle = putPart (file , uploadHandle , 1 , true ,
747753 generatePayload (1 , size ));
748754 partHandles .put (1 , partHandle );
749755
@@ -802,10 +808,10 @@ public void testConcurrentUploads() throws Throwable {
802808 assertNotEquals ("Upload handles match" , upload1 , upload2 );
803809
804810 // put part 1
805- partHandles1 .put (partId1 , putPart (file , upload1 , partId1 , payload1 ));
811+ partHandles1 .put (partId1 , putPart (file , upload1 , partId1 , false , payload1 ));
806812
807813 // put part2
808- partHandles2 .put (partId2 , putPart (file , upload2 , partId2 , payload2 ));
814+ partHandles2 .put (partId2 , putPart (file , upload2 , partId2 , true , payload2 ));
809815
810816 // complete part u1. expect its size and digest to
811817 // be as expected.
0 commit comments