Search in sources :

Example 6 with TestCancellable

use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.

the class CompletableConcatWithCompletablesTest method testCancelNext.

@ParameterizedTest
@ValueSource(ints = { 1, 2 })
void testCancelNext(int num) {
    initNexts(num);
    toSource(source.concat(nexts)).subscribe(subscriber);
    source.onComplete();
    assertThat(subscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
    subscriber.awaitSubscription().cancel();
    TestCancellable sourceCancellable = new TestCancellable();
    source.onSubscribe(sourceCancellable);
    assertFalse(sourceCancellable.isCancelled());
    TestCancellable nextCancellable = new TestCancellable();
    source.onSubscribe(nextCancellable);
    assertTrue(nextCancellable.isCancelled());
}
Also used : TestCancellable(io.servicetalk.concurrent.api.TestCancellable) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with TestCancellable

use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.

the class CompletableConcatWithPublisherTest method setUp.

@BeforeEach
void setUp() {
    subscriber = new TestPublisherSubscriber<>();
    cancellable = new TestCancellable();
    source = new TestCompletable.Builder().disableAutoOnSubscribe().build();
    next = new TestPublisher.Builder<Integer>().disableAutoOnSubscribe().build();
    subscription = new TestSubscription();
    toSource(source.concat(next)).subscribe(subscriber);
    source.onSubscribe(cancellable);
    subscriber.awaitSubscription();
}
Also used : TestSubscription(io.servicetalk.concurrent.api.TestSubscription) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) TestCancellable(io.servicetalk.concurrent.api.TestCancellable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with TestCancellable

use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.

the class CompletableConcatWithSingleTest method testCancelNext.

@Test
void testCancelNext() {
    source.onComplete();
    assertThat(subscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
    subscriber.awaitSubscription().cancel();
    TestCancellable sourceCancellable = new TestCancellable();
    source.onSubscribe(sourceCancellable);
    assertFalse(sourceCancellable.isCancelled());
    TestCancellable nextCancellable = new TestCancellable();
    next.onSubscribe(nextCancellable);
    assertTrue(nextCancellable.isCancelled());
}
Also used : TestCancellable(io.servicetalk.concurrent.api.TestCancellable) Test(org.junit.jupiter.api.Test)

Example 9 with TestCancellable

use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.

the class CompletableConcatWithSingleTest method testCancelSource.

@Test
void testCancelSource() {
    assertThat(subscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
    subscriber.awaitSubscription().cancel();
    TestCancellable cancellable = new TestCancellable();
    source.onSubscribe(cancellable);
    assertTrue(cancellable.isCancelled());
    assertFalse(next.isSubscribed());
}
Also used : TestCancellable(io.servicetalk.concurrent.api.TestCancellable) Test(org.junit.jupiter.api.Test)

Example 10 with TestCancellable

use of io.servicetalk.concurrent.api.TestCancellable in project servicetalk by apple.

the class CompletableToPublisherTest method invalidRequestNCancelsCompletable.

@Test
void invalidRequestNCancelsCompletable() {
    TestCompletable completable = new TestCompletable.Builder().disableAutoOnSubscribe().build();
    toSource(completable.<String>toPublisher()).subscribe(subscriber);
    TestCancellable cancellable = new TestCancellable();
    completable.onSubscribe(cancellable);
    subscriber.awaitSubscription().request(-1);
    assertThat(subscriber.awaitOnError(), is(instanceOf(IllegalArgumentException.class)));
    assertThat("Completable not cancelled for invalid request-n", cancellable.isCancelled(), is(true));
}
Also used : TestCompletable(io.servicetalk.concurrent.api.TestCompletable) TestCancellable(io.servicetalk.concurrent.api.TestCancellable) Test(org.junit.jupiter.api.Test)

Aggregations

TestCancellable (io.servicetalk.concurrent.api.TestCancellable)16 Test (org.junit.jupiter.api.Test)12 TestCompletable (io.servicetalk.concurrent.api.TestCompletable)4 TestPublisherSubscriber (io.servicetalk.concurrent.test.internal.TestPublisherSubscriber)3 Thread.currentThread (java.lang.Thread.currentThread)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Cancellable (io.servicetalk.concurrent.Cancellable)2 DelegatingExecutor (io.servicetalk.concurrent.api.DelegatingExecutor)2 TestSubscription (io.servicetalk.concurrent.api.TestSubscription)2 TimeUnit (java.util.concurrent.TimeUnit)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 Executor (io.servicetalk.concurrent.api.Executor)1 ExecutorExtension (io.servicetalk.concurrent.api.ExecutorExtension)1 Single (io.servicetalk.concurrent.api.Single)1 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)1 TestPublisher (io.servicetalk.concurrent.api.TestPublisher)1 TestSingle (io.servicetalk.concurrent.api.TestSingle)1 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)1