Search in sources :

Example 6 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class SerializedSubscriberTest method onCompleteOnErrorRace.

@Test
public void onCompleteOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
            final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
            BooleanSubscription bs = new BooleanSubscription();
            so.onSubscribe(bs);
            final Throwable ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    so.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    so.onComplete();
                }
            };
            TestHelper.race(r1, r2);
            ts.awaitDone(5, TimeUnit.SECONDS);
            if (ts.completions() != 0) {
                ts.assertResult();
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            } else {
                ts.assertFailure(TestException.class).assertError(ex);
                assertTrue("" + errors, errors.isEmpty());
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 7 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class SerializedSubscriberTest method nullOnNext.

@Test
public void nullOnNext() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
    so.onSubscribe(new BooleanSubscription());
    so.onNext(null);
    ts.assertFailureAndMessage(NullPointerException.class, ExceptionHelper.nullWarning("onNext called with a null value."));
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 8 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowableWindowWithFlowableTest method takeOneAnotherBoundary.

@Test
public void takeOneAnotherBoundary() {
    final AtomicReference<Subscriber<? super Object>> refMain = new AtomicReference<>();
    final AtomicReference<Subscriber<? super Object>> ref = new AtomicReference<>();
    TestSubscriberEx<Flowable<Object>> ts = new Flowable<Object>() {

        @Override
        protected void subscribeActual(Subscriber<? super Object> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            refMain.set(subscriber);
        }
    }.window(new Flowable<Object>() {

        @Override
        protected void subscribeActual(Subscriber<? super Object> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            ref.set(subscriber);
        }
    }).to(TestHelper.<Flowable<Object>>testConsumer());
    ts.assertValueCount(1).assertNotTerminated().cancel();
    ref.get().onNext(1);
    ts.assertValueCount(1).assertNotTerminated();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 9 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowableWindowWithFlowableTest method mainCompleteBoundaryErrorRace.

@Test
public void mainCompleteBoundaryErrorRace() {
    final TestException ex = new TestException();
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final AtomicReference<Subscriber<? super Object>> refMain = new AtomicReference<>();
            final AtomicReference<Subscriber<? super Object>> ref = new AtomicReference<>();
            TestSubscriberEx<Flowable<Object>> ts = new Flowable<Object>() {

                @Override
                protected void subscribeActual(Subscriber<? super Object> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    refMain.set(subscriber);
                }
            }.window(new Flowable<Object>() {

                @Override
                protected void subscribeActual(Subscriber<? super Object> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    ref.set(subscriber);
                }
            }).to(TestHelper.<Flowable<Object>>testConsumer());
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    refMain.get().onComplete();
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    ref.get().onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertValueCount(1).assertTerminated();
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 10 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowablePublishTest method observeOn.

@Test
public void observeOn() {
    ConnectableFlowable<Integer> cf = Flowable.range(0, 1000).hide().publish();
    Flowable<Integer> obs = cf.observeOn(Schedulers.computation());
    for (int i = 0; i < 1000; i++) {
        for (int j = 1; j < 6; j++) {
            List<TestSubscriberEx<Integer>> tss = new ArrayList<>();
            for (int k = 1; k < j; k++) {
                TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
                tss.add(ts);
                obs.subscribe(ts);
            }
            Disposable connection = cf.connect();
            for (TestSubscriberEx<Integer> ts : tss) {
                ts.awaitDone(5, TimeUnit.SECONDS).assertSubscribed().assertValueCount(1000).assertNoErrors().assertComplete();
            }
            connection.dispose();
        }
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 TestException (io.reactivex.rxjava3.exceptions.TestException)15 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)12 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 TestSubscriberEx (io.reactivex.rxjava3.testsupport.TestSubscriberEx)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)3 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)3 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)2 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)2 Random (java.util.Random)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assert (org.junit.Assert)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)1 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)1 BiFunction (io.reactivex.rxjava3.functions.BiFunction)1 Functions (io.reactivex.rxjava3.internal.functions.Functions)1 FlattenIterableSubscriber (io.reactivex.rxjava3.internal.operators.flowable.FlowableFlattenIterable.FlattenIterableSubscriber)1