use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.
the class CompletableConcatWithPublisherTest method setUp.
@BeforeEach
void setUp() {
subscriber = new TestPublisherSubscriber<>();
cancellable = new TestCancellable();
source = new TestCompletable.Builder().disableAutoOnSubscribe().build();
next = new TestPublisher.Builder<Integer>().disableAutoOnSubscribe().build();
subscription = new TestSubscription();
toSource(source.concat(next)).subscribe(subscriber);
source.onSubscribe(cancellable);
subscriber.awaitSubscription();
}
use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.
the class CompletableConcatWithCompletablesTest method testCancelNext.
@ParameterizedTest
@ValueSource(ints = { 1, 2 })
void testCancelNext(int num) {
initNexts(num);
toSource(source.concat(nexts)).subscribe(subscriber);
source.onComplete();
assertThat(subscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
subscriber.awaitSubscription().cancel();
TestCancellable sourceCancellable = new TestCancellable();
source.onSubscribe(sourceCancellable);
assertFalse(sourceCancellable.isCancelled());
TestCancellable nextCancellable = new TestCancellable();
source.onSubscribe(nextCancellable);
assertTrue(nextCancellable.isCancelled());
}
use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.
the class SingleToPublisherTest method publishOnOriginalIsPreserved0.
private CountDownLatch publishOnOriginalIsPreserved0(final ConcurrentLinkedQueue<AssertionError> errors, final io.servicetalk.concurrent.test.internal.TestPublisherSubscriber<String> subscriber, final TestSingle<String> single, @Nullable final CountDownLatch receivedOnSuccessFromSingle) throws Exception {
final Thread testThread = currentThread();
CountDownLatch analyzed = new CountDownLatch(1);
CountDownLatch receivedOnSubscribe = new CountDownLatch(1);
toSource(single.publishOn(EXEC.executor()).beforeOnSuccess(__ -> {
if (currentThread() == testThread) {
errors.add(new AssertionError("Invalid thread invoked onSuccess " + "(from Single). Thread: " + currentThread()));
}
}).afterOnSuccess(__ -> {
if (receivedOnSuccessFromSingle != null) {
receivedOnSuccessFromSingle.countDown();
}
}).beforeOnError(__ -> {
if (currentThread() == testThread) {
errors.add(new AssertionError("Invalid thread invoked onError" + "(from Single). Thread: " + currentThread()));
}
}).toPublisher().beforeOnNext(__ -> {
if (currentThread() == testThread) {
errors.add(new AssertionError("Invalid thread invoked onNext " + "(from Publisher). Thread: " + currentThread()));
}
}).beforeOnError(__ -> {
if (currentThread() == testThread) {
errors.add(new AssertionError("Invalid thread invoked onError " + "(from Publisher). Thread: " + currentThread()));
}
}).afterOnSubscribe(__ -> receivedOnSubscribe.countDown()).afterOnComplete(analyzed::countDown).afterOnError(__ -> analyzed.countDown())).subscribe(subscriber);
// await subscribe
single.onSubscribe(new TestCancellable());
receivedOnSubscribe.await();
assertThat("Single not subscribed.", single.isSubscribed(), is(true));
return analyzed;
}
use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.
the class SingleToPublisherTest method subscribeOnOriginalIsPreserved.
@Test
void subscribeOnOriginalIsPreserved() throws Exception {
final Thread testThread = currentThread();
final CountDownLatch analyzed = new CountDownLatch(1);
ConcurrentLinkedQueue<AssertionError> errors = new ConcurrentLinkedQueue<>();
TestSingle<String> single = new TestSingle.Builder<String>().disableAutoOnSubscribe().build();
TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();
toSource(single.beforeCancel(() -> {
if (currentThread() == testThread) {
errors.add(new AssertionError("Invalid thread invoked cancel. Thread: " + currentThread()));
}
}).afterCancel(analyzed::countDown).subscribeOn(EXEC.executor()).toPublisher()).subscribe(subscriber);
TestCancellable cancellable = new TestCancellable();
// waits till subscribed.
single.onSubscribe(cancellable);
assertThat("Single not subscribed.", single.isSubscribed(), is(true));
subscriber.awaitSubscription().cancel();
analyzed.await();
assertThat("Single did not get a cancel.", cancellable.isCancelled(), is(true));
assertNoAsyncErrors(errors);
}
use of io.servicetalk.concurrent.api.TestCancellable 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