use of io.helidon.common.reactive.RetrySchema in project helidon by oracle.
the class ReadableByteChannelPublisherTest method negativeDelay.
@Test
void negativeDelay() throws Exception {
PeriodicalChannel pc = createChannelWithNoAvailableData(10, 1);
RetrySchema schema = (i, delay) -> i >= 3 ? -10 : 0;
ReadableByteChannelPublisher publisher = new ReadableByteChannelPublisher(pc, schema);
// assert
try {
ContentReaders.readBytes(publisher).get(5, TimeUnit.SECONDS);
fail("Did not throw expected ExecutionException!");
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(TimeoutException.class));
}
}
use of io.helidon.common.reactive.RetrySchema in project helidon by oracle.
the class ReadableByteChannelPublisherTest method onClosedInProgress.
@Test
@Disabled("This test uses a sleep, so could cause issues on slow environments")
void onClosedInProgress() throws Exception {
PeriodicalChannel pc = createChannelWithNoAvailableData(5, 2);
RetrySchema schema = RetrySchema.constant(TimeUnit.SECONDS.toMillis(2));
ReadableByteChannelPublisher publisher = new ReadableByteChannelPublisher(pc, schema);
// start reading (this will cause 2 second delay)
Single<byte[]> data = ContentReaders.readBytes(publisher);
// run the stream
data.thenRun(() -> {
});
Thread.sleep(1000);
// immediately close the channel, so we fail reading
pc.close();
CompletionException c = assertThrows(CompletionException.class, () -> data.await(5, TimeUnit.SECONDS));
assertThat(c.getCause(), instanceOf(ClosedChannelException.class));
LazyValue<ScheduledExecutorService> executor = publisher.executor();
assertThat("Executor should have been used", executor.isLoaded(), is(true));
assertThat("Executor should have been shut down", executor.get().isShutdown(), is(true));
}
Aggregations