Search in sources :

Example 1 with EMPTY_SUBSCRIPTION

use of io.servicetalk.concurrent.internal.EmptySubscriptions.EMPTY_SUBSCRIPTION 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 2 with EMPTY_SUBSCRIPTION

use of io.servicetalk.concurrent.internal.EmptySubscriptions.EMPTY_SUBSCRIPTION in project servicetalk by apple.

the class SourceAdaptersTest method publisherFromSourceError.

@Test
void publisherFromSourceError() {
    PublisherSource<Integer> src = s -> {
        s.onSubscribe(EMPTY_SUBSCRIPTION);
        s.onError(DELIBERATE_EXCEPTION);
    };
    Future<Integer> future = fromSource(src).firstOrElse(() -> null).toFuture();
    Exception e = assertThrows(ExecutionException.class, () -> future.get());
    assertThat(e.getCause(), sameInstance(DELIBERATE_EXCEPTION));
}
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) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

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