2525
2626import com .adobe .testing .s3mock .junit5 .S3MockExtension ;
2727import com .amazonaws .services .s3 .AmazonS3 ;
28+ import com .amazonaws .services .s3 .model .ListMultipartUploadsRequest ;
29+ import com .amazonaws .services .s3 .model .MultipartUpload ;
2830import com .amazonaws .services .s3 .model .ObjectMetadata ;
2931import com .amazonaws .services .s3 .model .S3Object ;
3032import com .artipie .asto .blocking .BlockingStorage ;
3133import com .artipie .asto .s3 .S3Storage ;
3234import com .google .common .io .ByteStreams ;
35+ import io .reactivex .Flowable ;
3336import java .io .ByteArrayInputStream ;
3437import java .net .URI ;
3538import java .util .Arrays ;
3639import java .util .Collection ;
40+ import java .util .List ;
3741import java .util .UUID ;
3842import java .util .stream .Collectors ;
3943import org .hamcrest .MatcherAssert ;
4044import org .hamcrest .Matchers ;
45+ import org .hamcrest .collection .IsEmptyIterable ;
4146import org .hamcrest .core .IsEqual ;
47+ import org .junit .jupiter .api .Assertions ;
4248import org .junit .jupiter .api .Test ;
4349import org .junit .jupiter .api .extension .RegisterExtension ;
4450import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
5056 * Tests for {@link S3Storage}.
5157 *
5258 * @since 0.15
59+ * @checkstyle ClassDataAbstractionCouplingCheck (2 lines)
5360 */
5461class S3StorageTest {
5562
@@ -75,6 +82,35 @@ void shouldUploadObjectWhenSave(final AmazonS3 client) throws Exception {
7582 MatcherAssert .assertThat (downloaded , Matchers .equalTo (data ));
7683 }
7784
85+ @ Test
86+ void shouldFailToSaveMultipartUploadWhenFailedToReadContent (final AmazonS3 client ) {
87+ final String bucket = UUID .randomUUID ().toString ();
88+ client .createBucket (bucket );
89+ final String key = "fail" ;
90+ Assertions .assertThrows (
91+ Exception .class ,
92+ () -> this .storage (bucket ).save (
93+ new Key .From (key ),
94+ new Content .From (Flowable .error (new IllegalStateException ()))
95+ ).join ()
96+ );
97+ }
98+
99+ @ Test
100+ void shouldAbortMultipartUploadWhenFailedToReadContent (final AmazonS3 client ) {
101+ final String bucket = UUID .randomUUID ().toString ();
102+ client .createBucket (bucket );
103+ final String key = "abort" ;
104+ this .storage (bucket ).save (
105+ new Key .From (key ),
106+ new Content .From (Flowable .error (new IllegalStateException ()))
107+ ).exceptionally (ignore -> null ).join ();
108+ final List <MultipartUpload > uploads = client .listMultipartUploads (
109+ new ListMultipartUploadsRequest (bucket )
110+ ).getMultipartUploads ();
111+ MatcherAssert .assertThat (uploads , new IsEmptyIterable <>());
112+ }
113+
78114 @ Test
79115 void shouldExistForSavedObject (final AmazonS3 client ) {
80116 final String bucket = UUID .randomUUID ().toString ();
0 commit comments