Search in sources :

Example 1 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 2 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)

Example 3 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 4 with TestSubscription

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

Example 5 with TestSubscription

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());
}
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