Skip to content

Commit 3f55b2e

Browse files
committed
Using a no-op subscriber
1 parent e2898f7 commit 3f55b2e

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
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;
@@ -53,6 +54,7 @@
5354
import software.amazon.awssdk.core.FileTransformerConfiguration.FileWriteOption;
5455
import software.amazon.awssdk.core.FileTransformerConfiguration.FailureBehavior;
5556
import software.amazon.awssdk.core.async.SdkPublisher;
57+
import software.amazon.awssdk.core.internal.util.NoopSubscription;
5658

5759
/**
5860
* Tests for {@link FileAsyncResponseTransformer}.
@@ -184,6 +186,11 @@ void createOrAppendExisting_fileExists_shouldAppend() throws Exception {
184186
assertThat(testPath).hasContent(existingString + content);
185187
}
186188

189+
@RepeatedTest(10000)
190+
void foo() throws Exception {
191+
exceptionOccurred_deleteFileBehavior(FileTransformerConfiguration.defaultCreateNew());
192+
}
193+
187194
@ParameterizedTest
188195
@MethodSource("configurations")
189196
void exceptionOccurred_deleteFileBehavior(FileTransformerConfiguration configuration) throws Exception {
@@ -193,7 +200,7 @@ void exceptionOccurred_deleteFileBehavior(FileTransformerConfiguration configura
193200
Files.write(testPath, "foobar".getBytes(StandardCharsets.UTF_8));
194201
}
195202
FileAsyncResponseTransformer<String> transformer = new FileAsyncResponseTransformer<>(testPath, configuration);
196-
stubException(RandomStringUtils.random(200), transformer);
203+
stubException(transformer);
197204
if (configuration.failureBehavior() == LEAVE) {
198205
assertThat(testPath).exists();
199206
} else {
@@ -326,31 +333,17 @@ private static void stubSuccessfulStreaming(String newContent, FileAsyncResponse
326333
assertThat(future.isCompletedExceptionally()).isFalse();
327334
}
328335

329-
private static void stubException(String newContent, FileAsyncResponseTransformer<String> transformer) throws Exception {
336+
private static void stubException(FileAsyncResponseTransformer<String> transformer) throws Exception {
330337
CompletableFuture<String> future = transformer.prepare();
331338
transformer.onResponse("foobar");
332339

333340
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)));
351342
transformer.exceptionOccurred(runtimeException);
352343

353-
assertThatThrownBy(future::join).isInstanceOf(Exception.class);
344+
assertThat(future).failsWithin(1, TimeUnit.SECONDS)
345+
.withThrowableOfType(ExecutionException.class)
346+
.withCause(runtimeException);
354347
}
355348

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

0 commit comments

Comments
 (0)