21
21
import software .amazon .awssdk .services .s3 .model .GetObjectResponse ;
22
22
import software .amazon .awssdk .services .s3 .model .NoSuchBucketException ;
23
23
import software .amazon .awssdk .services .s3 .model .NoSuchKeyException ;
24
+ import software .amazon .awssdk .services .s3 .model .NoSuchUploadException ;
24
25
import software .amazon .awssdk .services .s3 .model .ObjectIdentifier ;
25
26
import software .amazon .awssdk .services .s3 .model .PutObjectRequest ;
26
27
import software .amazon .awssdk .services .s3 .model .S3Exception ;
44
45
45
46
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
46
47
import static org .junit .jupiter .api .Assertions .assertEquals ;
48
+ import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
47
49
import static org .junit .jupiter .api .Assertions .assertThrows ;
48
50
import static org .junit .jupiter .api .Assertions .assertTrue ;
49
51
import static org .mockito .ArgumentMatchers .any ;
@@ -618,7 +620,7 @@ public void createMultipartUploadFailure() {
618
620
v3Client .createMultipartUpload (builder -> builder .bucket ("NotMyBukkit" ).key ("InvalidKey" ).build ());
619
621
} catch (S3EncryptionClientException exception ) {
620
622
// Verify inner exception
621
- assertTrue ( exception .getCause () instanceof NoSuchBucketException );
623
+ assertInstanceOf ( NoSuchBucketException . class , exception .getCause ());
622
624
}
623
625
624
626
v3Client .close ();
@@ -642,15 +644,15 @@ public void uploadPartFailure() {
642
644
RequestBody .fromInputStream (new BoundedInputStream (16 ), 16 ));
643
645
} catch (S3EncryptionClientException exception ) {
644
646
// Verify inner exception
645
- assertTrue ( exception .getCause () instanceof NoSuchBucketException );
647
+ assertInstanceOf ( NoSuchBucketException . class , exception .getCause ());
646
648
}
647
649
648
- // MPU was not completed, but delete to be safe
650
+ // MPU was not completed, but abort and delete to be safe
651
+ v3Client .abortMultipartUpload (builder -> builder .bucket (BUCKET ).key (objectKey ).uploadId (initiateResult .uploadId ()).build ());
649
652
deleteObject (BUCKET , objectKey , v3Client );
650
653
v3Client .close ();
651
654
}
652
655
653
-
654
656
@ Test
655
657
public void completeMultipartUploadFailure () {
656
658
// V3 Client
@@ -661,7 +663,26 @@ public void completeMultipartUploadFailure() {
661
663
v3Client .completeMultipartUpload (builder -> builder .bucket ("NotMyBukkit" ).key ("InvalidKey" ).uploadId ("Invalid" ).build ());
662
664
} catch (S3EncryptionClientException exception ) {
663
665
// Verify inner exception
664
- assertTrue (exception .getCause () instanceof NoSuchBucketException );
666
+ assertInstanceOf (NoSuchBucketException .class , exception .getCause ());
667
+ }
668
+
669
+ v3Client .close ();
670
+ }
671
+
672
+ @ Test
673
+ public void abortMultipartUploadFailure () {
674
+ final String objectKey = appendTestSuffix ("abort-multipart-failure" );
675
+
676
+ // V3 Client
677
+ S3Client v3Client = S3EncryptionClient .builder ()
678
+ .aesKey (AES_KEY )
679
+ .build ();
680
+
681
+ try {
682
+ v3Client .abortMultipartUpload (builder -> builder .bucket (BUCKET ).key (objectKey ).uploadId ("invalid upload id" ).build ());
683
+ } catch (S3EncryptionClientException exception ) {
684
+ // Verify inner exception
685
+ assertInstanceOf (NoSuchUploadException .class , exception .getCause ());
665
686
}
666
687
667
688
v3Client .close ();
0 commit comments