Search in sources :

Example 1 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class MaybeFlattenStreamAsFlowableTest method requestOneByOne.

@Test
public void requestOneByOne() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    Maybe.just(1).flattenStreamAsFlowable(v -> Stream.of(1, 2, 3, 4, 5)).subscribe(new FlowableSubscriber<Integer>() {

        Subscription upstream;

        @Override
        public void onSubscribe(@NonNull Subscription s) {
            ts.onSubscribe(new BooleanSubscription());
            upstream = s;
            s.request(1);
        }

        @Override
        public void onNext(Integer t) {
            ts.onNext(t);
            upstream.request(1);
        }

        @Override
        public void onError(Throwable t) {
            ts.onError(t);
        }

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    });
    ts.assertResult(1, 2, 3, 4, 5);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) Test(org.junit.Test) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) NonNull(io.reactivex.rxjava3.annotations.NonNull) AtomicReference(java.util.concurrent.atomic.AtomicReference) Mockito(org.mockito.Mockito) QueueFuseable(io.reactivex.rxjava3.operators.QueueFuseable) Function(io.reactivex.rxjava3.functions.Function) Subscription(org.reactivestreams.Subscription) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) MaybeSubject(io.reactivex.rxjava3.subjects.MaybeSubject) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscription(org.reactivestreams.Subscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) Test(org.junit.Test)

Example 2 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class SingleFlattenStreamAsFlowableTest method requestOneByOne.

@Test
public void requestOneByOne() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    Single.just(1).flattenStreamAsFlowable(v -> Stream.of(1, 2, 3, 4, 5)).subscribe(new FlowableSubscriber<Integer>() {

        Subscription upstream;

        @Override
        public void onSubscribe(@NonNull Subscription s) {
            ts.onSubscribe(new BooleanSubscription());
            upstream = s;
            s.request(1);
        }

        @Override
        public void onNext(Integer t) {
            ts.onNext(t);
            upstream.request(1);
        }

        @Override
        public void onError(Throwable t) {
            ts.onError(t);
        }

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    });
    ts.assertResult(1, 2, 3, 4, 5);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) Test(org.junit.Test) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) NonNull(io.reactivex.rxjava3.annotations.NonNull) AtomicReference(java.util.concurrent.atomic.AtomicReference) SingleSubject(io.reactivex.rxjava3.subjects.SingleSubject) Mockito(org.mockito.Mockito) QueueFuseable(io.reactivex.rxjava3.operators.QueueFuseable) Function(io.reactivex.rxjava3.functions.Function) Subscription(org.reactivestreams.Subscription) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscription(org.reactivestreams.Subscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) Test(org.junit.Test)

Example 3 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowableFlatMapStreamTest method mapperThrowsWhenUpstreamErrors.

@Test
public void mapperThrowsWhenUpstreamErrors() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        PublishProcessor<Integer> pp = PublishProcessor.create();
        AtomicInteger counter = new AtomicInteger();
        TestSubscriber<Integer> ts = pp.hide().concatMapStream(v -> {
            if (counter.getAndIncrement() == 0) {
                return Stream.of(1, 2);
            }
            pp.onError(new IOException());
            throw new TestException();
        }).test();
        pp.onNext(1);
        pp.onNext(2);
        ts.assertFailure(IOException.class, 1, 2);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowableFlatMapStreamTest method upstreamCancelled.

@Test
public void upstreamCancelled() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    AtomicInteger calls = new AtomicInteger();
    TestSubscriber<Integer> ts = pp.flatMapStream(v -> Stream.of(v + 1, v + 2).onClose(() -> calls.getAndIncrement())).test(1);
    assertTrue(pp.hasSubscribers());
    pp.onNext(1);
    ts.assertValuesOnly(2);
    ts.cancel();
    assertFalse(pp.hasSubscribers());
    assertEquals(1, calls.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 5 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class MaybeCacheTest method crossCancelOnError.

@Test
public void crossCancelOnError() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    Maybe<Integer> source = pp.singleElement().cache();
    source.subscribe(Functions.emptyConsumer(), new Consumer<Object>() {

        @Override
        public void accept(Object v) throws Exception {
            ts.cancel();
        }
    });
    source.toFlowable().subscribe(ts);
    pp.onError(new TestException());
    ts.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)169 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)116 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)106 TestException (io.reactivex.rxjava3.exceptions.TestException)56 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)27 TimeUnit (java.util.concurrent.TimeUnit)19 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)18 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)17 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)15 IOException (java.io.IOException)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Flowable (io.reactivex.rxjava3.core.Flowable)13 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)13 ClientBuilder (javax.ws.rs.client.ClientBuilder)13 MediaType (javax.ws.rs.core.MediaType)13 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)13 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)13 Assert.assertTrue (org.junit.Assert.assertTrue)13 BeforeClass (org.junit.BeforeClass)13 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)12