37
37
import org .junit .jupiter .api .extension .ExtendWith ;
38
38
import org .mockito .ArgumentCaptor ;
39
39
import org .mockito .Mock ;
40
+ import org .mockito .exceptions .verification .WantedButNotInvoked ;
40
41
import org .mockito .junit .jupiter .MockitoExtension ;
42
+ import software .amazon .awssdk .core .async .AsyncRequestBody ;
41
43
import software .amazon .awssdk .http .SdkHttpExecutionAttributes ;
42
44
import software .amazon .awssdk .services .s3 .S3AsyncClient ;
43
45
import software .amazon .awssdk .services .s3 .model .PutObjectRequest ;
44
46
import software .amazon .awssdk .services .s3 .model .PutObjectResponse ;
45
47
import software .amazon .awssdk .transfer .s3 .model .UploadDirectoryRequest ;
46
48
import software .amazon .awssdk .transfer .s3 .model .UploadFileRequest ;
49
+ import software .amazon .awssdk .transfer .s3 .model .UploadRequest ;
47
50
48
51
@ ExtendWith (MockitoExtension .class )
49
52
public class CrtS3TransferManagerTest {
@@ -81,7 +84,7 @@ void uploadDirectory_shouldUseCrtUploadFile() {
81
84
.completionFuture ()
82
85
.join ();
83
86
84
- verifyCrtInRequestAttributes ();
87
+ verifyCrtInRequestAttributes (true );
85
88
}
86
89
87
90
@ Test
@@ -94,18 +97,38 @@ void uploadFile_shouldUseCrtUploadFile() {
94
97
.completionFuture ()
95
98
.join ();
96
99
97
- verifyCrtInRequestAttributes ();
100
+ verifyCrtInRequestAttributes (true );
98
101
}
99
102
100
- private void verifyCrtInRequestAttributes () {
101
- ArgumentCaptor <PutObjectRequest > requestArgumentCaptor = ArgumentCaptor .forClass (PutObjectRequest .class );
102
103
103
- verify (s3AsyncClient ).putObject (requestArgumentCaptor .capture (), ArgumentCaptor .forClass (Path .class ).capture ());
104
+ @ Test
105
+ void upload_shouldUseCrtUpload () {
106
+ when (s3AsyncClient .putObject (any (PutObjectRequest .class ), any (AsyncRequestBody .class ))).thenReturn (CompletableFuture .completedFuture (PutObjectResponse .builder ().build ()));
107
+ transferManager .upload (UploadRequest .builder ()
108
+ .putObjectRequest (PutObjectRequest .builder ().bucket ("test" ).key ("test" ).build ())
109
+ .requestBody (AsyncRequestBody .fromString ("test" ))
110
+ .build ())
111
+ .completionFuture ()
112
+ .join ();
113
+
114
+ verifyCrtInRequestAttributes (false );
115
+ }
116
+
117
+ private void verifyCrtInRequestAttributes (boolean verifyObservable ) {
118
+ ArgumentCaptor <PutObjectRequest > requestArgumentCaptor = ArgumentCaptor .forClass (PutObjectRequest .class );
104
119
120
+ try {
121
+ verify (s3AsyncClient ).putObject (requestArgumentCaptor .capture (), ArgumentCaptor .forClass (Path .class ).capture ());
122
+ } catch (WantedButNotInvoked e ) {
123
+ verify (s3AsyncClient ).putObject (requestArgumentCaptor .capture (), ArgumentCaptor .forClass (AsyncRequestBody .class ).capture ());
124
+ }
105
125
PutObjectRequest actual = requestArgumentCaptor .getValue ();
106
126
assertThat (actual .overrideConfiguration ()).isPresent ();
107
127
SdkHttpExecutionAttributes attribute = actual .overrideConfiguration ().get ().executionAttributes ().getAttribute (SDK_HTTP_EXECUTION_ATTRIBUTES );
108
128
assertThat (attribute ).isNotNull ();
109
129
assertThat (attribute .getAttribute (CRT_PROGRESS_LISTENER )).isNotNull ();
130
+ if (verifyObservable ) {
131
+ assertThat (attribute .getAttribute (METAREQUEST_PAUSE_OBSERVABLE )).isNotNull ();
132
+ }
110
133
}
111
134
}
0 commit comments