Search in sources :

Example 36 with TestSubscriber

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

the class SerializedSubscriberTest method completeReentry.

@Test
public void completeReentry() {
    final AtomicReference<Subscriber<Integer>> serial = new AtomicReference<>();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onNext(Integer v) {
            serial.get().onComplete();
            serial.get().onComplete();
            super.onNext(v);
        }
    };
    SerializedSubscriber<Integer> sobs = new SerializedSubscriber<>(ts);
    sobs.onSubscribe(new BooleanSubscription());
    serial.set(sobs);
    sobs.onNext(1);
    ts.assertValue(1);
    ts.assertComplete();
    ts.assertNoErrors();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 37 with TestSubscriber

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

the class FlowableSubscriberTest method requestToFlowable.

@Test
public void requestToFlowable() {
    TestSubscriber<Integer> ts = new TestSubscriber<>(3L);
    final AtomicLong requested = new AtomicLong();
    Flowable.<Integer>unsafeCreate(new Publisher<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer> s) {
            s.onSubscribe(new Subscription() {

                @Override
                public void request(long n) {
                    requested.set(n);
                }

                @Override
                public void cancel() {
                }
            });
        }
    }).subscribe(ts);
    assertEquals(3, requested.get());
}
Also used : ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 38 with TestSubscriber

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

the class FlowableSubscriberTest method onNextCrashes.

@Test
public void onNextCrashes() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    ts.onSubscribe(new BooleanSubscription());
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            throw new TestException();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable e) throws Exception {
            ts.onError(e);
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            ts.onComplete();
        }
    });
    BooleanSubscription b = new BooleanSubscription();
    s.onSubscribe(b);
    s.onNext(1);
    assertTrue(b.isCancelled());
    ts.assertFailure(TestException.class);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) Test(org.junit.Test)

Example 39 with TestSubscriber

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

the class FlowableSubscriberTest method requestFromChainedOperator.

@Test
public void requestFromChainedOperator() throws Throwable {
    TestSubscriber<String> s = new TestSubscriber<>(10L);
    FlowableOperator<String, String> o = new FlowableOperator<String, String>() {

        @Override
        public Subscriber<? super String> apply(final Subscriber<? super String> s1) {
            return new FlowableSubscriber<String>() {

                @Override
                public void onSubscribe(Subscription a) {
                    s1.onSubscribe(a);
                }

                @Override
                public void onComplete() {
                }

                @Override
                public void onError(Throwable e) {
                }

                @Override
                public void onNext(String t) {
                }
            };
        }
    };
    Subscriber<? super String> ns = o.apply(s);
    final AtomicLong r = new AtomicLong();
    // set set the producer at the top of the chain (ns) and it should flow through the operator to the (s) subscriber
    // and then it should request up with the value set on the final Subscriber (s)
    ns.onSubscribe(new Subscription() {

        @Override
        public void request(long n) {
            r.set(n);
        }

        @Override
        public void cancel() {
        }
    });
    assertEquals(10, r.get());
}
Also used : ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 40 with TestSubscriber

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

the class FlowableSubscriberTest method suppressAfterCompleteEvents.

@Test
public void suppressAfterCompleteEvents() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final TestSubscriber<Integer> ts = new TestSubscriber<>();
        ts.onSubscribe(new BooleanSubscription());
        ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {

            @Override
            public boolean test(Integer v) throws Exception {
                ts.onNext(v);
                return true;
            }
        }, new Consumer<Throwable>() {

            @Override
            public void accept(Throwable e) throws Exception {
                ts.onError(e);
            }
        }, new Action() {

            @Override
            public void run() throws Exception {
                ts.onComplete();
            }
        });
        s.onComplete();
        s.onNext(1);
        s.onError(new TestException());
        s.onComplete();
        ts.assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) 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