use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class SingleZip4Test method cancelAfterCompleteOutOfOrder.
@Test
void cancelAfterCompleteOutOfOrder() throws InterruptedException {
TestCancellable cancellable1 = new TestCancellable();
TestSingle<Integer> first = new TestSingle.Builder<Integer>().disableAutoOnSubscribe().build(subscriber1 -> {
subscriber1.onSubscribe(cancellable1);
return subscriber1;
});
TestCancellable cancellable3 = new TestCancellable();
TestSingle<Short> third = new TestSingle.Builder<Short>().disableAutoOnSubscribe().build(subscriber1 -> {
subscriber1.onSubscribe(cancellable3);
return subscriber1;
});
TestCancellable cancellable4 = new TestCancellable();
TestSingle<Byte> fourth = new TestSingle.Builder<Byte>().disableAutoOnSubscribe().build(subscriber1 -> {
subscriber1.onSubscribe(cancellable4);
return subscriber1;
});
toSource(zip(first, second, third, fourth, SingleZip4Test::combine)).subscribe(subscriber);
Cancellable c = subscriber.awaitSubscription();
second.onSuccess(10.1);
c.cancel();
cancellable1.awaitCancelled();
cancellable3.awaitCancelled();
cancellable4.awaitCancelled();
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class SingleZip5Test method cancelAfterCompleteOutOfOrder.
@Test
void cancelAfterCompleteOutOfOrder() throws InterruptedException {
TestCancellable cancellable1 = new TestCancellable();
TestSingle<Integer> first = new TestSingle.Builder<Integer>().disableAutoOnSubscribe().build(subscriber1 -> {
subscriber1.onSubscribe(cancellable1);
return subscriber1;
});
TestCancellable cancellable3 = new TestCancellable();
TestSingle<Short> third = new TestSingle.Builder<Short>().disableAutoOnSubscribe().build(subscriber1 -> {
subscriber1.onSubscribe(cancellable3);
return subscriber1;
});
TestCancellable cancellable4 = new TestCancellable();
TestSingle<Byte> fourth = new TestSingle.Builder<Byte>().disableAutoOnSubscribe().build(subscriber1 -> {
subscriber1.onSubscribe(cancellable4);
return subscriber1;
});
TestCancellable cancellable5 = new TestCancellable();
TestSingle<Byte> fifth = new TestSingle.Builder<Byte>().disableAutoOnSubscribe().build(subscriber1 -> {
subscriber1.onSubscribe(cancellable5);
return subscriber1;
});
toSource(zip(combineFunc(), first, second, third, fourth, fifth)).subscribe(subscriber);
Cancellable c = subscriber.awaitSubscription();
second.onSuccess(10.1);
c.cancel();
cancellable1.awaitCancelled();
cancellable3.awaitCancelled();
cancellable4.awaitCancelled();
cancellable5.awaitCancelled();
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class SourceAdaptersTest method completableFromSourceCancel.
@Test
void completableFromSourceCancel() {
Cancellable srcCancellable = mock(Cancellable.class);
CompletableSource source = s -> s.onSubscribe(srcCancellable);
fromSource(source).toFuture().cancel(true);
verify(srcCancellable).cancel();
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class SourceAdaptersTest method singleFromSourceCancel.
@Test
void singleFromSourceCancel() {
Cancellable srcCancellable = mock(Cancellable.class);
SingleSource<Integer> source = s -> s.onSubscribe(srcCancellable);
fromSource(source).toFuture().cancel(true);
verify(srcCancellable).cancel();
}
use of io.servicetalk.concurrent.Cancellable 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());
}
Aggregations