use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class JdkFlowAdaptersTest method toFlowCancel.
@Test
void toFlowCancel() {
TestPublisher<Integer> stPublisher = new TestPublisher<>();
Subscriber<Integer> subscriber = toFlowPublisherAndSubscribe(stPublisher);
TestSubscription subscription = new TestSubscription();
stPublisher.onSubscribe(subscription);
assertThat("Source not subscribed.", stPublisher.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.TestSubscription 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.TestSubscription in project servicetalk by apple.
the class PublisherStepVerifierTest method requestThenCancel.
@Test
void requestThenCancel() {
TestSubscription subscription = new TestSubscription();
TestPublisher<String> publisher = new TestPublisher.Builder<String>().disableAutoOnSubscribe().build();
StepVerifiers.create(publisher).then(() -> publisher.onSubscribe(subscription)).thenRequest(100).then(() -> {
assertThat(subscription.requested(), greaterThanOrEqualTo(100L));
publisher.onNext("foo", "bar");
}).expectNext("foo", "bar").thenCancel().verify();
assertTrue(subscription.isCancelled());
}
use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class PublisherStepVerifierTest method noSignalsSubscriptionCancelSucceeds.
@Test
void noSignalsSubscriptionCancelSucceeds() {
// expectNoSignals and subscription event are dequeued/processed sequentially on the Subscriber thread
// and the scenario isn't instructed to expect the subscription so we pass the test.
TestSubscription subscription = new TestSubscription();
TestPublisher<String> publisher = new TestPublisher.Builder<String>().disableAutoOnSubscribe().build();
StepVerifiers.create(publisher).then(() -> publisher.onSubscribe(subscription)).expectNoSignals(ofDays(1)).thenCancel().verify();
assertTrue(subscription.isCancelled());
}
use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class PublisherStepVerifierTest method multipleRequests.
@Test
void multipleRequests() {
TestSubscription subscription = new TestSubscription();
TestPublisher<String> publisher = new TestPublisher.Builder<String>().disableAutoOnSubscribe().build();
StepVerifiers.create(publisher).then(() -> publisher.onSubscribe(subscription)).thenRequest(1).thenRequest(2).then(() -> {
assertThat(subscription.requested(), greaterThanOrEqualTo(3L));
publisher.onNext("foo", "bar");
publisher.onComplete();
}).expectNext("foo", "bar").expectComplete().verify();
assertThat(subscription.requested(), greaterThanOrEqualTo(5L));
}
Aggregations