use of io.servicetalk.concurrent.CompletableSource.Subscriber in project servicetalk by apple.
the class CompletableDoOnUtils method doOnSubscribeSupplier.
static Supplier<Subscriber> doOnSubscribeSupplier(Consumer<Cancellable> onSubscribe) {
requireNonNull(onSubscribe);
Subscriber subscriber = new Subscriber() {
@Override
public void onSubscribe(Cancellable cancellable) {
onSubscribe.accept(cancellable);
}
@Override
public void onComplete() {
// NOOP
}
@Override
public void onError(Throwable t) {
// NOOP
}
};
return () -> subscriber;
}
use of io.servicetalk.concurrent.CompletableSource.Subscriber in project servicetalk by apple.
the class DefaultNettyConnection method write.
@Override
public Completable write(final Publisher<Write> write, final Supplier<FlushStrategy> flushStrategySupplier, final Supplier<WriteDemandEstimator> demandEstimatorSupplier) {
return cleanupStateWhenDone(new SubscribableCompletable() {
@Override
protected void handleSubscribe(Subscriber completableSubscriber) {
final WriteObserver writeObserver = DefaultNettyConnection.this.dataObserver.onNewWrite();
WriteStreamSubscriber subscriber = new WriteStreamSubscriber(channel(), demandEstimatorSupplier.get(), completableSubscriber, closeHandler, writeObserver, enrichProtocolError, isClient, shouldWait);
if (failIfWriteActive(subscriber, completableSubscriber)) {
toSource(composeFlushes(channel(), write, flushStrategySupplier.get(), writeObserver)).subscribe(subscriber);
}
}
}).onErrorMap(this::enrichError);
}
use of io.servicetalk.concurrent.CompletableSource.Subscriber in project servicetalk by apple.
the class TimeoutCompletableTest method cancelDoesOnError.
@Test
void cancelDoesOnError() throws Exception {
DelayedOnSubscribeCompletable delayedCompletable = new DelayedOnSubscribeCompletable();
init(delayedCompletable, false);
CountDownLatch cancelLatch = new CountDownLatch(1);
CompletableSource.Subscriber subscriber = delayedCompletable.subscriber;
assertNotNull(subscriber);
subscriber.onSubscribe(() -> {
subscriber.onError(DELIBERATE_EXCEPTION);
cancelLatch.countDown();
});
testExecutor.advanceTimeBy(1, NANOSECONDS);
assertThat(testExecutor.scheduledTasksPending(), is(0));
assertThat(testExecutor.scheduledTasksExecuted(), is(1));
cancelLatch.await();
Throwable error = listener.awaitOnError();
assertThat(error, instanceOf(TimeoutException.class));
}
use of io.servicetalk.concurrent.CompletableSource.Subscriber in project servicetalk by apple.
the class TimeoutCompletableTest method defaultExecutorSubscribeTimeout.
@Test
@Disabled("Requires the notion of globally mocked time source using a TestExecutor")
void defaultExecutorSubscribeTimeout() {
DelayedOnSubscribeCompletable delayedCompletable = new DelayedOnSubscribeCompletable();
// Assume the timeout call is not under the user's control, e.g. comes from a library of Completable providers
final Completable operationThatInternallyTimesOut = delayedCompletable.timeout(Duration.ofDays(1));
TestExecutor testExecutor = new TestExecutor();
// TODO(dariusz): Replace all executors created with the test instance
// Executors.setFactory(AllExecutorFactory.create(() -> testExecutor));
toSource(operationThatInternallyTimesOut).subscribe(listener);
testExecutor.advanceTimeBy(1, DAYS);
CompletableSource.Subscriber subscriber = delayedCompletable.subscriber;
assertNotNull(subscriber);
assertThat(listener.awaitOnError(), instanceOf(TimeoutException.class));
}
use of io.servicetalk.concurrent.CompletableSource.Subscriber in project servicetalk by apple.
the class BeforeSubscribeTest method testCallbackThrowsError.
@Test
void testCallbackThrowsError() {
List<Throwable> failures = new ArrayList<>();
toSource(doSubscribe(Completable.completed(), s -> {
throw DELIBERATE_EXCEPTION;
})).subscribe(new Subscriber() {
@Override
public void onSubscribe(final Cancellable c) {
failures.add(new AssertionError("onSubscribe invoked unexpectedly."));
}
@Override
public void onError(final Throwable t) {
failures.add(t);
}
@Override
public void onComplete() {
failures.add(new AssertionError("onComplete invoked unexpectedly."));
}
});
assertThat("Unexpected errors: " + failures, failures, contains(DELIBERATE_EXCEPTION));
}
Aggregations