Search in sources :

Example 1 with CompletableSource

use of io.servicetalk.concurrent.CompletableSource in project servicetalk by apple.

the class CompletableConcatWithCompletablesTest method testSourceSuccessReentrant.

@ParameterizedTest
@ValueSource(ints = { 1, 2, 10000 })
void testSourceSuccessReentrant(int num) {
    Completable[] mockCompletables = new Completable[num];
    for (int i = 0; i < mockCompletables.length; ++i) {
        CompletableSource mockCompletable = mock(CompletableSource.class);
        doAnswer((Answer<Void>) invocation -> {
            CompletableSource.Subscriber sub = invocation.getArgument(0);
            sub.onSubscribe(IGNORE_CANCEL);
            sub.onComplete();
            return null;
        }).when(mockCompletable).subscribe(any());
        mockCompletables[i] = fromSource(mockCompletable);
    }
    toSource(source.concat(mockCompletables)).subscribe(subscriber);
    source.onComplete();
    subscriber.awaitOnComplete();
}
Also used : ValueSource(org.junit.jupiter.params.provider.ValueSource) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Completable(io.servicetalk.concurrent.api.Completable) TestCancellable(io.servicetalk.concurrent.api.TestCancellable) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) CompletableSource(io.servicetalk.concurrent.CompletableSource) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) Test(org.junit.jupiter.api.Test) SourceAdapters.fromSource(io.servicetalk.concurrent.api.SourceAdapters.fromSource) Answer(org.mockito.stubbing.Answer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IGNORE_CANCEL(io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Mockito.mock(org.mockito.Mockito.mock) Completable(io.servicetalk.concurrent.api.Completable) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) CompletableSource(io.servicetalk.concurrent.CompletableSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CompletableSource

use of io.servicetalk.concurrent.CompletableSource in project servicetalk by apple.

the class ReactiveStreamsAdaptersTest method completableToRSFromSourceError.

@Test
void completableToRSFromSourceError() {
    CompletableSource source = s -> {
        s.onSubscribe(EMPTY_SUBSCRIPTION);
        s.onError(DELIBERATE_EXCEPTION);
    };
    verifyRSError(toRSPublisherFromSourceAndSubscribe(source));
}
Also used : ReactiveStreamsAdapters.toReactiveStreamsPublisher(io.servicetalk.concurrent.reactivestreams.ReactiveStreamsAdapters.toReactiveStreamsPublisher) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) TestSingle(io.servicetalk.concurrent.api.TestSingle) SingleSource(io.servicetalk.concurrent.SingleSource) Cancellable(io.servicetalk.concurrent.Cancellable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Future(java.util.concurrent.Future) ArgumentCaptor(org.mockito.ArgumentCaptor) EMPTY_SUBSCRIPTION(io.servicetalk.concurrent.internal.EmptySubscriptions.EMPTY_SUBSCRIPTION) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Mockito.doAnswer(org.mockito.Mockito.doAnswer) BiConsumer(java.util.function.BiConsumer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Subscriber(org.reactivestreams.Subscriber) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) PublisherSource(io.servicetalk.concurrent.PublisherSource) Single(io.servicetalk.concurrent.api.Single) Publisher(org.reactivestreams.Publisher) Completable(io.servicetalk.concurrent.api.Completable) CompletableSource(io.servicetalk.concurrent.CompletableSource) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) ScalarValueSubscription(io.servicetalk.concurrent.internal.ScalarValueSubscription) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) IGNORE_CANCEL(io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL) Publisher.failed(io.servicetalk.concurrent.api.Publisher.failed) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) Subscription(org.reactivestreams.Subscription) ReactiveStreamsAdapters.fromReactiveStreamsPublisher(io.servicetalk.concurrent.reactivestreams.ReactiveStreamsAdapters.fromReactiveStreamsPublisher) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) CompletableSource(io.servicetalk.concurrent.CompletableSource) Test(org.junit.jupiter.api.Test)

Example 3 with CompletableSource

use of io.servicetalk.concurrent.CompletableSource in project servicetalk by apple.

the class ReactiveStreamsAdaptersTest method completableToRSFromSourceSuccess.

@Test
void completableToRSFromSourceSuccess() {
    CompletableSource source = s -> {
        s.onSubscribe(IGNORE_CANCEL);
        s.onComplete();
    };
    verifyRSSuccess(toRSPublisherFromSourceAndSubscribe(source), false);
}
Also used : ReactiveStreamsAdapters.toReactiveStreamsPublisher(io.servicetalk.concurrent.reactivestreams.ReactiveStreamsAdapters.toReactiveStreamsPublisher) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) TestSingle(io.servicetalk.concurrent.api.TestSingle) SingleSource(io.servicetalk.concurrent.SingleSource) Cancellable(io.servicetalk.concurrent.Cancellable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Future(java.util.concurrent.Future) ArgumentCaptor(org.mockito.ArgumentCaptor) EMPTY_SUBSCRIPTION(io.servicetalk.concurrent.internal.EmptySubscriptions.EMPTY_SUBSCRIPTION) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Mockito.doAnswer(org.mockito.Mockito.doAnswer) BiConsumer(java.util.function.BiConsumer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Subscriber(org.reactivestreams.Subscriber) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) PublisherSource(io.servicetalk.concurrent.PublisherSource) Single(io.servicetalk.concurrent.api.Single) Publisher(org.reactivestreams.Publisher) Completable(io.servicetalk.concurrent.api.Completable) CompletableSource(io.servicetalk.concurrent.CompletableSource) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) ScalarValueSubscription(io.servicetalk.concurrent.internal.ScalarValueSubscription) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) IGNORE_CANCEL(io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL) Publisher.failed(io.servicetalk.concurrent.api.Publisher.failed) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) Subscription(org.reactivestreams.Subscription) ReactiveStreamsAdapters.fromReactiveStreamsPublisher(io.servicetalk.concurrent.reactivestreams.ReactiveStreamsAdapters.fromReactiveStreamsPublisher) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) CompletableSource(io.servicetalk.concurrent.CompletableSource) Test(org.junit.jupiter.api.Test)

Example 4 with CompletableSource

use of io.servicetalk.concurrent.CompletableSource in project servicetalk by apple.

the class SourceAdaptersTest method completableFromSourceSuccess.

@Test
void completableFromSourceSuccess() throws Exception {
    CompletableSource src = s -> {
        s.onSubscribe(IGNORE_CANCEL);
        s.onComplete();
    };
    fromSource(src).toFuture().get();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SingleSource(io.servicetalk.concurrent.SingleSource) Cancellable(io.servicetalk.concurrent.Cancellable) SourceAdapters.fromSource(io.servicetalk.concurrent.api.SourceAdapters.fromSource) Future(java.util.concurrent.Future) ArgumentCaptor(org.mockito.ArgumentCaptor) EMPTY_SUBSCRIPTION(io.servicetalk.concurrent.internal.EmptySubscriptions.EMPTY_SUBSCRIPTION) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) PublisherSource(io.servicetalk.concurrent.PublisherSource) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) CompletableSource(io.servicetalk.concurrent.CompletableSource) ScalarValueSubscription(io.servicetalk.concurrent.internal.ScalarValueSubscription) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) IGNORE_CANCEL(io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL) ArgumentCaptor.forClass(org.mockito.ArgumentCaptor.forClass) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) CompletableSource(io.servicetalk.concurrent.CompletableSource) Test(org.junit.jupiter.api.Test)

Example 5 with CompletableSource

use of io.servicetalk.concurrent.CompletableSource in project servicetalk by apple.

the class SourceAdaptersTest method toSourceAndSubscribe.

private CompletableSource.Subscriber toSourceAndSubscribe(Completable completable) {
    CompletableSource src = toSource(completable);
    CompletableSource.Subscriber subscriber = mock(CompletableSource.Subscriber.class);
    src.subscribe(subscriber);
    verify(subscriber).onSubscribe(any());
    return subscriber;
}
Also used : CompletableSource(io.servicetalk.concurrent.CompletableSource)

Aggregations

CompletableSource (io.servicetalk.concurrent.CompletableSource)8 IGNORE_CANCEL (io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL)7 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Matchers.is (org.hamcrest.Matchers.is)7 Test (org.junit.jupiter.api.Test)7 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)7 Mockito.mock (org.mockito.Mockito.mock)7 Cancellable (io.servicetalk.concurrent.Cancellable)6 PublisherSource (io.servicetalk.concurrent.PublisherSource)6 SingleSource (io.servicetalk.concurrent.SingleSource)6 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)6 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)6 EMPTY_SUBSCRIPTION (io.servicetalk.concurrent.internal.EmptySubscriptions.EMPTY_SUBSCRIPTION)6 ScalarValueSubscription (io.servicetalk.concurrent.internal.ScalarValueSubscription)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)6 ArgumentCaptor (org.mockito.ArgumentCaptor)6