Skip to content

Commit 1ec1c12

Browse files
authored
Providing an idle publisher to resolve race condition (#5993)
* Providing an idle publisher to resolve race condition * Using a no-op subscriber * Remove repeated test --------- Co-authored-by: Ran Vaknin <[email protected]>
1 parent f1079a8 commit 1ec1c12

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/async/FileAsyncResponseTransformerTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@
4444
import org.apache.commons.lang3.RandomStringUtils;
4545
import org.junit.jupiter.api.AfterEach;
4646
import org.junit.jupiter.api.BeforeEach;
47+
import org.junit.jupiter.api.RepeatedTest;
4748
import org.junit.jupiter.api.Test;
4849
import org.junit.jupiter.params.ParameterizedTest;
4950
import org.junit.jupiter.params.provider.MethodSource;
51+
import org.reactivestreams.Subscriber;
5052
import org.reactivestreams.Subscription;
5153
import software.amazon.awssdk.core.FileTransformerConfiguration;
5254
import software.amazon.awssdk.core.FileTransformerConfiguration.FileWriteOption;
5355
import software.amazon.awssdk.core.FileTransformerConfiguration.FailureBehavior;
5456
import software.amazon.awssdk.core.async.SdkPublisher;
57+
import software.amazon.awssdk.core.internal.util.NoopSubscription;
5558

5659
/**
5760
* Tests for {@link FileAsyncResponseTransformer}.
@@ -192,7 +195,7 @@ void exceptionOccurred_deleteFileBehavior(FileTransformerConfiguration configura
192195
Files.write(testPath, "foobar".getBytes(StandardCharsets.UTF_8));
193196
}
194197
FileAsyncResponseTransformer<String> transformer = new FileAsyncResponseTransformer<>(testPath, configuration);
195-
stubException(RandomStringUtils.random(200), transformer);
198+
stubException(transformer);
196199
if (configuration.failureBehavior() == LEAVE) {
197200
assertThat(testPath).exists();
198201
} else {
@@ -325,18 +328,17 @@ private static void stubSuccessfulStreaming(String newContent, FileAsyncResponse
325328
assertThat(future.isCompletedExceptionally()).isFalse();
326329
}
327330

328-
private static void stubException(String newContent, FileAsyncResponseTransformer<String> transformer) throws Exception {
331+
private static void stubException(FileAsyncResponseTransformer<String> transformer) throws Exception {
329332
CompletableFuture<String> future = transformer.prepare();
330333
transformer.onResponse("foobar");
331334

332335
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)));
335337
transformer.exceptionOccurred(runtimeException);
336338

337339
assertThat(future).failsWithin(1, TimeUnit.SECONDS)
338-
.withThrowableOfType(ExecutionException.class)
339-
.withCause(runtimeException);
340+
.withThrowableOfType(ExecutionException.class)
341+
.withCause(runtimeException);
340342
}
341343

342344
private static SdkPublisher<ByteBuffer> testPublisher(String content) {

0 commit comments

Comments
 (0)