|
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; |
| 51 | +import org.reactivestreams.Subscriber; |
50 | 52 | import org.reactivestreams.Subscription; |
51 | 53 | import software.amazon.awssdk.core.FileTransformerConfiguration; |
52 | 54 | import software.amazon.awssdk.core.FileTransformerConfiguration.FileWriteOption; |
53 | 55 | import software.amazon.awssdk.core.FileTransformerConfiguration.FailureBehavior; |
54 | 56 | import software.amazon.awssdk.core.async.SdkPublisher; |
| 57 | +import software.amazon.awssdk.core.internal.util.NoopSubscription; |
55 | 58 |
|
56 | 59 | /** |
57 | 60 | * Tests for {@link FileAsyncResponseTransformer}. |
@@ -192,7 +195,7 @@ void exceptionOccurred_deleteFileBehavior(FileTransformerConfiguration configura |
192 | 195 | Files.write(testPath, "foobar".getBytes(StandardCharsets.UTF_8)); |
193 | 196 | } |
194 | 197 | FileAsyncResponseTransformer<String> transformer = new FileAsyncResponseTransformer<>(testPath, configuration); |
195 | | - stubException(RandomStringUtils.random(200), transformer); |
| 198 | + stubException(transformer); |
196 | 199 | if (configuration.failureBehavior() == LEAVE) { |
197 | 200 | assertThat(testPath).exists(); |
198 | 201 | } else { |
@@ -325,18 +328,17 @@ private static void stubSuccessfulStreaming(String newContent, FileAsyncResponse |
325 | 328 | assertThat(future.isCompletedExceptionally()).isFalse(); |
326 | 329 | } |
327 | 330 |
|
328 | | - private static void stubException(String newContent, FileAsyncResponseTransformer<String> transformer) throws Exception { |
| 331 | + private static void stubException(FileAsyncResponseTransformer<String> transformer) throws Exception { |
329 | 332 | CompletableFuture<String> future = transformer.prepare(); |
330 | 333 | transformer.onResponse("foobar"); |
331 | 334 |
|
332 | 335 | RuntimeException runtimeException = new RuntimeException("oops"); |
333 | | - ByteBuffer content = ByteBuffer.wrap(newContent.getBytes(StandardCharsets.UTF_8)); |
334 | | - transformer.onStream(SdkPublisher.adapt(Flowable.just(content, content))); |
| 336 | + transformer.onStream(s -> s.onSubscribe(new NoopSubscription(s))); |
335 | 337 | transformer.exceptionOccurred(runtimeException); |
336 | 338 |
|
337 | 339 | assertThat(future).failsWithin(1, TimeUnit.SECONDS) |
338 | | - .withThrowableOfType(ExecutionException.class) |
339 | | - .withCause(runtimeException); |
| 340 | + .withThrowableOfType(ExecutionException.class) |
| 341 | + .withCause(runtimeException); |
340 | 342 | } |
341 | 343 |
|
342 | 344 | private static SdkPublisher<ByteBuffer> testPublisher(String content) { |
|
0 commit comments