Search in sources :

Example 1 with SingleSource

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

the class ReactiveStreamsAdaptersTest method singleToRSFromSourceCancel.

@Test
void singleToRSFromSourceCancel() {
    Cancellable srcCancellable = mock(Cancellable.class);
    SingleSource<Integer> source = s -> s.onSubscribe(srcCancellable);
    Subscriber<Integer> subscriber = toRSPublisherFromSourceAndSubscribe(source);
    ArgumentCaptor<Subscription> rsSubscriptionCaptor = ArgumentCaptor.forClass(Subscription.class);
    verify(subscriber).onSubscribe(rsSubscriptionCaptor.capture());
    rsSubscriptionCaptor.getValue().cancel();
    verify(srcCancellable).cancel();
}
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) Cancellable(io.servicetalk.concurrent.Cancellable) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) ScalarValueSubscription(io.servicetalk.concurrent.internal.ScalarValueSubscription) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Example 2 with SingleSource

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

the class SourceAdaptersTest method singleFromSourceError.

@Test
void singleFromSourceError() {
    SingleSource<Integer> src = s -> {
        s.onSubscribe(IGNORE_CANCEL);
        s.onError(DELIBERATE_EXCEPTION);
    };
    Future<Integer> future = fromSource(src).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)

Example 3 with SingleSource

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

the class SourceAdaptersTest method singleFromSourceCancel.

@Test
void singleFromSourceCancel() {
    Cancellable srcCancellable = mock(Cancellable.class);
    SingleSource<Integer> source = s -> s.onSubscribe(srcCancellable);
    fromSource(source).toFuture().cancel(true);
    verify(srcCancellable).cancel();
}
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) Cancellable(io.servicetalk.concurrent.Cancellable) Test(org.junit.jupiter.api.Test)

Aggregations

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