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 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));
}
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 PublisherConcatWithSingleTest method initState.
private void initState() {
subscription = new TestSubscription();
cancellable = new TestCancellable();
source = new TestPublisher<>();
subscriber = new TestPublisherSubscriber<>();
single = new TestSingle<>();
}
use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class RepeatWhenTest method testCancelBeforeRetry.
@Test
void testCancelBeforeRetry() {
init();
final TestSubscription subscription = new TestSubscription();
source.onSubscribe(subscription);
subscriber.awaitSubscription().request(2);
source.onNext(1, 2);
assertThat(subscriber.takeOnNext(2), contains(1, 2));
subscriber.awaitSubscription().cancel();
source.onComplete();
assertTrue(subscription.isCancelled());
}
Aggregations