Search in sources :

Example 11 with TestSubscription

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));
}
Also used : TestSubscription(io.servicetalk.concurrent.api.TestSubscription) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) Subscription(java.util.concurrent.Flow.Subscription) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) ScalarValueSubscription(io.servicetalk.concurrent.internal.ScalarValueSubscription) Test(org.junit.jupiter.api.Test)

Example 12 with TestSubscription

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));
}
Also used : TestSubscription(io.servicetalk.concurrent.api.TestSubscription) TestSingle(io.servicetalk.concurrent.api.TestSingle) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) ScalarValueSubscription(io.servicetalk.concurrent.internal.ScalarValueSubscription) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Example 13 with TestSubscription

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());
}
Also used : TestSubscription(io.servicetalk.concurrent.api.TestSubscription) Test(org.junit.jupiter.api.Test)

Example 14 with TestSubscription

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());
}
Also used : TestSubscription(io.servicetalk.concurrent.api.TestSubscription) Test(org.junit.jupiter.api.Test)

Example 15 with TestSubscription

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));
}
Also used : TestSubscription(io.servicetalk.concurrent.api.TestSubscription) Test(org.junit.jupiter.api.Test)

Aggregations

TestSubscription (io.servicetalk.concurrent.api.TestSubscription)26 Test (org.junit.jupiter.api.Test)19 TestPublisher (io.servicetalk.concurrent.api.TestPublisher)7 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)7 Buffer (io.servicetalk.buffer.api.Buffer)4 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)4 AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)4 ScalarValueSubscription (io.servicetalk.concurrent.internal.ScalarValueSubscription)4 HttpExecutionStrategies.defaultStrategy (io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy)4 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)4 ServerContext (io.servicetalk.transport.api.ServerContext)4 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)4 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)4 ClientGroup (io.servicetalk.client.api.ClientGroup)3 ServiceDiscoverer (io.servicetalk.client.api.ServiceDiscoverer)3 AVAILABLE (io.servicetalk.client.api.ServiceDiscovererEvent.Status.AVAILABLE)3 DefaultPartitionAttributesBuilder (io.servicetalk.client.api.internal.partition.DefaultPartitionAttributesBuilder)3 PartitionAttributes (io.servicetalk.client.api.partition.PartitionAttributes)3 PartitionAttributesBuilder (io.servicetalk.client.api.partition.PartitionAttributesBuilder)3 PartitionedServiceDiscovererEvent (io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent)3