Search in sources :

Example 1 with TestCancellable

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

the class SingleConcatWithCompletableTest 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 2 with TestCancellable

use of io.servicetalk.concurrent.api.TestCancellable 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 3 with TestCancellable

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

the class TimeoutCompletableTest method executorScheduleThrows.

@Test
void executorScheduleThrows() {
    toSource(source.ignoreElement().timeout(1, NANOSECONDS, new DelegatingExecutor(testExecutor) {

        @Override
        public Cancellable schedule(final Runnable task, final long delay, final TimeUnit unit) {
            throw DELIBERATE_EXCEPTION;
        }
    })).subscribe(listener);
    assertThat(listener.awaitOnError(), is(DELIBERATE_EXCEPTION));
    TestCancellable cancellable = new TestCancellable();
    source.onSubscribe(cancellable);
    assertTrue(cancellable.isCancelled());
}
Also used : DelegatingExecutor(io.servicetalk.concurrent.api.DelegatingExecutor) Cancellable(io.servicetalk.concurrent.Cancellable) TestCancellable(io.servicetalk.concurrent.api.TestCancellable) TimeUnit(java.util.concurrent.TimeUnit) TestCancellable(io.servicetalk.concurrent.api.TestCancellable) Test(org.junit.jupiter.api.Test)

Example 4 with TestCancellable

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

the class CompletableConcatWithCompletablesTest method testCancelSource.

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

Example 5 with TestCancellable

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

the class CompletableConcatWithCompletableTest method testCancelNext.

@Test
void testCancelNext() {
    toSource(source.concat(next)).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) 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