Search in sources :

Example 1 with TestCompletable

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

the class CompletableConcatWithCompletablesTest method setUp.

@BeforeEach
void setUp() {
    subscriber = new TestCompletableSubscriber();
    source = new TestCompletable();
}
Also used : TestCompletable(io.servicetalk.concurrent.api.TestCompletable) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with TestCompletable

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

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

the class CompletableToPublisherTest method publishOnOriginalIsPreservedOnComplete.

@Test
void publishOnOriginalIsPreservedOnComplete() throws Exception {
    ConcurrentLinkedQueue<AssertionError> errors = new ConcurrentLinkedQueue<>();
    TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();
    TestCompletable completable = new TestCompletable();
    CountDownLatch analyzed = publishOnOriginalIsPreserved0(errors, subscriber, completable);
    completable.onComplete();
    analyzed.await();
    assertThat("Unexpected errors observed: " + errors, errors, hasSize(0));
    subscriber.awaitOnComplete();
}
Also used : TestPublisherSubscriber(io.servicetalk.concurrent.test.internal.TestPublisherSubscriber) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 4 with TestCompletable

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

the class CompletableToPublisherTest method publishOnOriginalIsPreserved0.

private CountDownLatch publishOnOriginalIsPreserved0(final ConcurrentLinkedQueue<AssertionError> errors, final TestPublisherSubscriber<String> subscriber, final TestCompletable completable) {
    final Thread testThread = currentThread();
    CountDownLatch analyzed = new CountDownLatch(1);
    CountDownLatch receivedOnSubscribe = new CountDownLatch(1);
    toSource(completable.publishOn(EXEC.executor()).beforeOnComplete(() -> {
        if (currentThread() == testThread) {
            errors.add(new AssertionError("Invalid thread invoked onComplete " + "(from Completable). Thread: " + currentThread()));
        }
    }).beforeOnError(__ -> {
        if (currentThread() == testThread) {
            errors.add(new AssertionError("Invalid thread invoked onError" + "(from Completable). Thread: " + currentThread()));
        }
    }).<String>toPublisher().beforeOnComplete(() -> {
        if (currentThread() == testThread) {
            errors.add(new AssertionError("Invalid thread invoked onComplete " + "(from Publisher). Thread: " + currentThread()));
        }
    }).beforeOnError(__ -> {
        if (currentThread() == testThread) {
            errors.add(new AssertionError("Invalid thread invoked onError " + "(from Publisher). Thread: " + currentThread()));
        }
    }).afterOnComplete(analyzed::countDown).afterOnError(__ -> analyzed.countDown()).afterOnSubscribe(__ -> receivedOnSubscribe.countDown())).subscribe(subscriber);
    assertThat("Completable not subscribed.", completable.isSubscribed(), is(true));
    return analyzed;
}
Also used : TestPublisherSubscriber(io.servicetalk.concurrent.test.internal.TestPublisherSubscriber) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) Completable(io.servicetalk.concurrent.api.Completable) TestCancellable(io.servicetalk.concurrent.api.TestCancellable) Thread.currentThread(java.lang.Thread.currentThread) Disabled(org.junit.jupiter.api.Disabled) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) Executor(io.servicetalk.concurrent.api.Executor) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Thread.currentThread(java.lang.Thread.currentThread)

Example 5 with TestCompletable

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

the class CompletableConcatWithCompletableTest method setUp.

@BeforeEach
void setUp() {
    subscriber = new TestCompletableSubscriber();
    source = new TestCompletable();
    next = new TestCompletable();
}
Also used : TestCompletable(io.servicetalk.concurrent.api.TestCompletable) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TestCompletable (io.servicetalk.concurrent.api.TestCompletable)14 Test (org.junit.jupiter.api.Test)7 TestPublisherSubscriber (io.servicetalk.concurrent.test.internal.TestPublisherSubscriber)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 TestCancellable (io.servicetalk.concurrent.api.TestCancellable)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 TestCompletableSubscriber (io.servicetalk.concurrent.test.internal.TestCompletableSubscriber)2 Thread.currentThread (java.lang.Thread.currentThread)2 Disabled (org.junit.jupiter.api.Disabled)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 Completable (io.servicetalk.concurrent.api.Completable)1 Executor (io.servicetalk.concurrent.api.Executor)1 ExecutorExtension (io.servicetalk.concurrent.api.ExecutorExtension)1 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)1 TestSubscription (io.servicetalk.concurrent.api.TestSubscription)1 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)1 ScalarValueSubscription (io.servicetalk.concurrent.internal.ScalarValueSubscription)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1