Skip to content

Commit e2898f7

Browse files
committed
Providing an idle publisher to resolve race condition
1 parent df2b80b commit e2898f7

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.junit.jupiter.api.Test;
4848
import org.junit.jupiter.params.ParameterizedTest;
4949
import org.junit.jupiter.params.provider.MethodSource;
50+
import org.reactivestreams.Subscriber;
5051
import org.reactivestreams.Subscription;
5152
import software.amazon.awssdk.core.FileTransformerConfiguration;
5253
import software.amazon.awssdk.core.FileTransformerConfiguration.FileWriteOption;
@@ -331,12 +332,25 @@ private static void stubException(String newContent, FileAsyncResponseTransforme
331332

332333
RuntimeException runtimeException = new RuntimeException("oops");
333334
ByteBuffer content = ByteBuffer.wrap(newContent.getBytes(StandardCharsets.UTF_8));
334-
transformer.onStream(SdkPublisher.adapt(Flowable.just(content, content)));
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);
335351
transformer.exceptionOccurred(runtimeException);
336352

337-
assertThat(future).failsWithin(1, TimeUnit.SECONDS)
338-
.withThrowableOfType(ExecutionException.class)
339-
.withCause(runtimeException);
353+
assertThatThrownBy(future::join).isInstanceOf(Exception.class);
340354
}
341355

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

0 commit comments

Comments
 (0)