use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class AfterFinallyTest method testCallbackThrowsErrorOnError.
@Test
@Override
void testCallbackThrowsErrorOnError() {
TerminalSignalConsumer mock = throwableMock(new DeliberateException());
toSource(doFinally(Completable.failed(DELIBERATE_EXCEPTION), mock)).subscribe(listener);
assertThat(listener.awaitOnError(), is(DELIBERATE_EXCEPTION));
verify(mock).onError(DELIBERATE_EXCEPTION);
verifyNoMoreInteractions(mock);
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class BeforeFinallyTest method testCallbackThrowsErrorOnError.
@Test
@Override
void testCallbackThrowsErrorOnError() {
DeliberateException exception = new DeliberateException();
TerminalSignalConsumer mock = throwableMock(exception);
toSource(doFinally(Completable.failed(DELIBERATE_EXCEPTION), mock)).subscribe(listener);
assertThat(listener.awaitOnError(), is(exception));
assertThat(listener.awaitOnError().getSuppressed()[0], is(DELIBERATE_EXCEPTION));
verify(mock).onError(DELIBERATE_EXCEPTION);
verifyNoMoreInteractions(mock);
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class AbstractWhenCancelTest method testCallbackThrowsError.
@Test
void testCallbackThrowsError() {
LegacyTestCompletable completable = new LegacyTestCompletable();
DeliberateException e = assertThrows(DeliberateException.class, () -> {
try {
toSource(doCancel(completable, () -> {
throw DELIBERATE_EXCEPTION;
})).subscribe(listener);
listener.awaitSubscription().cancel();
} finally {
completable.verifyCancelled();
}
});
assertThat(e, is(sameInstance(DELIBERATE_EXCEPTION)));
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class RoundRobinLoadBalancerTest method hostUnhealthyDoesntRaceToRunHealthCheck.
// Concurrency test, run multiple times (at least 1000).
@Test
void hostUnhealthyDoesntRaceToRunHealthCheck() throws Exception {
serviceDiscoveryPublisher.onComplete();
final Single<TestLoadBalancedConnection> properConnection = newRealizedConnectionSingle("address-1");
final int timeAdvancementsTillHealthy = 3;
final UnhealthyHostConnectionFactory unhealthyHostConnectionFactory = new UnhealthyHostConnectionFactory("address-1", timeAdvancementsTillHealthy, properConnection);
final DelegatingConnectionFactory connectionFactory = unhealthyHostConnectionFactory.createFactory();
lb = defaultLb(connectionFactory);
sendServiceDiscoveryEvents(upEvent("address-1"));
// Imitate concurrency by running multiple threads attempting to establish connections.
ExecutorService executor = Executors.newFixedThreadPool(3);
try {
final Runnable runnable = () -> assertThrows(ExecutionException.class, () -> lb.selectConnection(any(), null).toFuture().get());
for (int i = 0; i < 1000; i++) {
executor.submit(runnable);
}
// From test main thread, wait until the host becomes UNHEALTHY, which is apparent from
// NoHostAvailableException being thrown from selection AFTER a health check was scheduled by any thread.
final Executor executorForRetries = io.servicetalk.concurrent.api.Executors.newFixedSizeExecutor(1);
try {
awaitIndefinitely(lb.selectConnection(any(), null).retryWhen(retryWithConstantBackoffFullJitter((t) -> t instanceof DeliberateException || testExecutor.scheduledTasksPending() == 0, // try to prevent stack overflow
Duration.ofMillis(30), executorForRetries)));
} catch (Exception e) {
assertThat(e.getCause(), instanceOf(NoAvailableHostException.class));
} finally {
executorForRetries.closeAsync().toFuture().get();
}
// is not selected. If our assumption doesn't hold, it means more than one health check was scheduled.
for (int i = 0; i < timeAdvancementsTillHealthy - 1; ++i) {
unhealthyHostConnectionFactory.advanceTime(testExecutor);
// Assert still unhealthy
Exception e = assertThrows(ExecutionException.class, () -> lb.selectConnection(any(), null).toFuture().get());
assertThat(e.getCause(), instanceOf(NoAvailableHostException.class));
}
} finally {
// Shutdown the concurrent validation of unhealthiness.
executor.shutdownNow();
executor.awaitTermination(10, SECONDS);
}
unhealthyHostConnectionFactory.advanceTime(testExecutor);
final TestLoadBalancedConnection selectedConnection = lb.selectConnection(any(), null).toFuture().get();
assertThat(selectedConnection, equalTo(properConnection.toFuture().get()));
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class PublisherConcatMapIterableTest method exceptionFromOnCompleteIsPropagated.
@Test
void exceptionFromOnCompleteIsPropagated() {
toSource(publisher.flatMapConcatIterable(identity()).afterOnComplete(() -> {
throw DELIBERATE_EXCEPTION;
})).subscribe(subscriber);
subscriber.awaitSubscription();
DeliberateException exception = assertThrows(DeliberateException.class, () -> publisher.onComplete());
assertThat(exception, is(DELIBERATE_EXCEPTION));
}
Aggregations