use of io.servicetalk.concurrent.api.DelegatingExecutor in project servicetalk by apple.
the class TimeoutCompletableTest method executorScheduleThrows.
@Test
void executorScheduleThrows() {
toSource(source.ignoreElement().timeout(1, NANOSECONDS, new DelegatingExecutor(testExecutor) {
@Override
public Cancellable schedule(final Runnable task, final long delay, final TimeUnit unit) {
throw DELIBERATE_EXCEPTION;
}
})).subscribe(listener);
assertThat(listener.awaitOnError(), is(DELIBERATE_EXCEPTION));
TestCancellable cancellable = new TestCancellable();
source.onSubscribe(cancellable);
assertTrue(cancellable.isCancelled());
}
use of io.servicetalk.concurrent.api.DelegatingExecutor in project servicetalk by apple.
the class RoundRobinLoadBalancerTest method healthCheckRecoversFromUnexpectedError.
@Test
void healthCheckRecoversFromUnexpectedError() throws Exception {
serviceDiscoveryPublisher.onComplete();
final Single<TestLoadBalancedConnection> properConnection = newRealizedConnectionSingle("address-1");
final UnhealthyHostConnectionFactory unhealthyHostConnectionFactory = new UnhealthyHostConnectionFactory("address-1", 4, properConnection);
final DelegatingConnectionFactory connectionFactory = unhealthyHostConnectionFactory.createFactory();
final AtomicInteger scheduleCnt = new AtomicInteger();
lb = (RoundRobinLoadBalancer<String, TestLoadBalancedConnection>) new RoundRobinLoadBalancerFactory.Builder<String, TestLoadBalancedConnection>().healthCheckFailedConnectionsThreshold(1).backgroundExecutor(new DelegatingExecutor(testExecutor) {
@Override
public Completable timer(final long delay, final TimeUnit unit) {
if (scheduleCnt.incrementAndGet() == 2) {
throw DELIBERATE_EXCEPTION;
}
return delegate().timer(delay, unit);
}
}).build().newLoadBalancer("test-service", serviceDiscoveryPublisher, connectionFactory);
sendServiceDiscoveryEvents(upEvent("address-1"));
// Trigger first health check:
Exception e = assertThrows(ExecutionException.class, () -> lb.selectConnection(any()).toFuture().get());
assertThat(e.getCause(), is(UNHEALTHY_HOST_EXCEPTION));
// second - due to an unexpected error from executor:
for (int i = 0; i < 2; ++i) {
unhealthyHostConnectionFactory.advanceTime(testExecutor);
}
// Trigger yet another health check:
e = assertThrows(ExecutionException.class, () -> lb.selectConnection(any()).toFuture().get());
assertThat(e.getCause(), is(UNHEALTHY_HOST_EXCEPTION));
// Execute two health checks: first will fail due to connectionFactory, second succeeds:
for (int i = 0; i < 2; ++i) {
unhealthyHostConnectionFactory.advanceTime(testExecutor);
}
// Make sure we can select a connection:
final TestLoadBalancedConnection selectedConnection = lb.selectConnection(any()).toFuture().get();
assertThat(selectedConnection, equalTo(properConnection.toFuture().get()));
assertThat(unhealthyHostConnectionFactory.requests.get(), equalTo(5));
}
use of io.servicetalk.concurrent.api.DelegatingExecutor in project servicetalk by apple.
the class TimeoutSingleTest method executorScheduleThrows.
@Test
void executorScheduleThrows() {
toSource(source.timeout(1, NANOSECONDS, new DelegatingExecutor(testExecutor) {
@Override
public Cancellable schedule(final Runnable task, final long delay, final TimeUnit unit) {
throw DELIBERATE_EXCEPTION;
}
})).subscribe(subscriber);
assertThat(subscriber.awaitOnError(), sameInstance(DELIBERATE_EXCEPTION));
TestCancellable cancellable = new TestCancellable();
source.onSubscribe(cancellable);
assertTrue(cancellable.isCancelled());
}
use of io.servicetalk.concurrent.api.DelegatingExecutor in project servicetalk by apple.
the class TimeoutPublisherTest method executorScheduleThrowsTerminalTimeout.
@Test
void executorScheduleThrowsTerminalTimeout() {
toSource(publisher.timeoutTerminal(1, NANOSECONDS, new DelegatingExecutor(testExecutor) {
@Override
public Cancellable schedule(final Runnable task, final long delay, final TimeUnit unit) {
throw DELIBERATE_EXCEPTION;
}
})).subscribe(subscriber);
publisher.onSubscribe(subscription);
assertThat(subscriber.awaitOnError(), sameInstance(DELIBERATE_EXCEPTION));
assertTrue(subscription.isCancelled());
}
use of io.servicetalk.concurrent.api.DelegatingExecutor in project servicetalk by apple.
the class TimeoutPublisherTest method executorScheduleThrowsIdleTimeout.
@Test
void executorScheduleThrowsIdleTimeout() {
toSource(publisher.timeout(1, NANOSECONDS, new DelegatingExecutor(testExecutor) {
@Override
public Cancellable schedule(final Runnable task, final long delay, final TimeUnit unit) {
throw DELIBERATE_EXCEPTION;
}
})).subscribe(subscriber);
publisher.onSubscribe(subscription);
assertThat(subscriber.awaitOnError(), sameInstance(DELIBERATE_EXCEPTION));
assertTrue(subscription.isCancelled());
}
Aggregations