44
44
import org .apache .commons .lang3 .RandomStringUtils ;
45
45
import org .junit .jupiter .api .AfterEach ;
46
46
import org .junit .jupiter .api .BeforeEach ;
47
+ import org .junit .jupiter .api .RepeatedTest ;
47
48
import org .junit .jupiter .api .Test ;
48
49
import org .junit .jupiter .params .ParameterizedTest ;
49
50
import org .junit .jupiter .params .provider .MethodSource ;
53
54
import software .amazon .awssdk .core .FileTransformerConfiguration .FileWriteOption ;
54
55
import software .amazon .awssdk .core .FileTransformerConfiguration .FailureBehavior ;
55
56
import software .amazon .awssdk .core .async .SdkPublisher ;
57
+ import software .amazon .awssdk .core .internal .util .NoopSubscription ;
56
58
57
59
/**
58
60
* Tests for {@link FileAsyncResponseTransformer}.
@@ -184,6 +186,11 @@ void createOrAppendExisting_fileExists_shouldAppend() throws Exception {
184
186
assertThat (testPath ).hasContent (existingString + content );
185
187
}
186
188
189
+ @ RepeatedTest (10000 )
190
+ void foo () throws Exception {
191
+ exceptionOccurred_deleteFileBehavior (FileTransformerConfiguration .defaultCreateNew ());
192
+ }
193
+
187
194
@ ParameterizedTest
188
195
@ MethodSource ("configurations" )
189
196
void exceptionOccurred_deleteFileBehavior (FileTransformerConfiguration configuration ) throws Exception {
@@ -193,7 +200,7 @@ void exceptionOccurred_deleteFileBehavior(FileTransformerConfiguration configura
193
200
Files .write (testPath , "foobar" .getBytes (StandardCharsets .UTF_8 ));
194
201
}
195
202
FileAsyncResponseTransformer <String > transformer = new FileAsyncResponseTransformer <>(testPath , configuration );
196
- stubException (RandomStringUtils . random ( 200 ), transformer );
203
+ stubException (transformer );
197
204
if (configuration .failureBehavior () == LEAVE ) {
198
205
assertThat (testPath ).exists ();
199
206
} else {
@@ -326,31 +333,17 @@ private static void stubSuccessfulStreaming(String newContent, FileAsyncResponse
326
333
assertThat (future .isCompletedExceptionally ()).isFalse ();
327
334
}
328
335
329
- private static void stubException (String newContent , FileAsyncResponseTransformer <String > transformer ) throws Exception {
336
+ private static void stubException (FileAsyncResponseTransformer <String > transformer ) throws Exception {
330
337
CompletableFuture <String > future = transformer .prepare ();
331
338
transformer .onResponse ("foobar" );
332
339
333
340
RuntimeException runtimeException = new RuntimeException ("oops" );
334
- ByteBuffer content = ByteBuffer .wrap (newContent .getBytes (StandardCharsets .UTF_8 ));
335
- SdkPublisher <ByteBuffer > idlePublisher = new SdkPublisher <ByteBuffer >() {
336
- @ Override
337
- public void subscribe (Subscriber <? super ByteBuffer > subscriber ) {
338
- subscriber .onSubscribe (new Subscription () {
339
- @ Override
340
- public void request (long l ) {
341
- subscriber .onNext (content );
342
- }
343
-
344
- @ Override
345
- public void cancel () {
346
- }
347
- });
348
- }
349
- };
350
- transformer .onStream (idlePublisher );
341
+ transformer .onStream (s -> s .onSubscribe (new NoopSubscription (s )));
351
342
transformer .exceptionOccurred (runtimeException );
352
343
353
- assertThatThrownBy (future ::join ).isInstanceOf (Exception .class );
344
+ assertThat (future ).failsWithin (1 , TimeUnit .SECONDS )
345
+ .withThrowableOfType (ExecutionException .class )
346
+ .withCause (runtimeException );
354
347
}
355
348
356
349
private static SdkPublisher <ByteBuffer > testPublisher (String content ) {
0 commit comments