Search in sources :

Example 6 with TestHelper

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

the class FlowableSequenceEqualTest method doubleErrorFlowable.

@Test
public void doubleErrorFlowable() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.sequenceEqual(Flowable.never(), new Flowable<Object>() {

            @Override
            protected void subscribeActual(Subscriber<? super Object> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onError(new TestException("First"));
                s.onError(new TestException("Second"));
            }
        }, 8).toFlowable().to(TestHelper.<Boolean>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 7 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper 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 8 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper 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 9 with TestHelper

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

the class AsyncProcessorTest method onErrorCancelRace.

@Test
@SuppressUndeliverable
public void onErrorCancelRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final AsyncProcessor<Object> p = AsyncProcessor.create();
        final TestSubscriberEx<Object> ts1 = p.to(TestHelper.<Object>testConsumer());
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                ts1.cancel();
            }
        };
        final TestException ex = new TestException();
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                p.onError(ex);
            }
        };
        TestHelper.race(r1, r2);
        if (ts1.errors().size() != 0) {
            ts1.assertFailure(TestException.class);
        } else {
            ts1.assertEmpty();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 10 with TestHelper

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

the class CompletableTimeoutTest method errorTimeoutRace.

@Test
public void errorTimeoutRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final TestScheduler scheduler = new TestScheduler();
            final PublishSubject<Integer> ps = PublishSubject.create();
            TestObserverEx<Void> to = ps.ignoreElements().timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()).to(TestHelper.<Void>testConsumer());
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

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

                @Override
                public void run() {
                    scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
                }
            };
            TestHelper.race(r1, r2);
            to.assertTerminated();
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 TestException (io.reactivex.rxjava3.exceptions.TestException)19 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)3 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)3 TestObserver (io.reactivex.rxjava3.observers.TestObserver)3 Observable (io.reactivex.rxjava3.core.Observable)2 Observer (io.reactivex.rxjava3.core.Observer)2 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)2 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)2 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Action (io.reactivex.rxjava3.functions.Action)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Subscriber (org.reactivestreams.Subscriber)1