use of io.servicetalk.concurrent.api.TestSingle in project servicetalk by apple.
the class ReactiveStreamsAdaptersTest method singleToRSCancel.
@Test
void singleToRSCancel() {
TestSingle<Integer> stSingle = new TestSingle<>();
Subscriber<Integer> subscriber = toRSPublisherAndSubscribe(stSingle);
TestSubscription subscription = new TestSubscription();
stSingle.onSubscribe(subscription);
assertThat("Source not subscribed.", stSingle.isSubscribed(), is(true));
ArgumentCaptor<Subscription> subscriptionCaptor = ArgumentCaptor.forClass(Subscription.class);
verify(subscriber).onSubscribe(subscriptionCaptor.capture());
subscriptionCaptor.getValue().cancel();
assertThat("Subscription not cancelled.", subscription.isCancelled(), is(true));
}
use of io.servicetalk.concurrent.api.TestSingle 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;
}
Aggregations