Search in sources :

Example 21 with SuppressUndeliverable

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

the class ObservableWindowWithTimeTest method skipTimeAndSizeBoundNoInterruptWindowOutputOnError.

@Test
@SuppressUndeliverable
public void skipTimeAndSizeBoundNoInterruptWindowOutputOnError() throws Exception {
    final AtomicBoolean isInterrupted = new AtomicBoolean();
    final PublishSubject<Integer> ps = PublishSubject.create();
    final CountDownLatch doOnNextDone = new CountDownLatch(1);
    final CountDownLatch secondWindowProcessing = new CountDownLatch(1);
    ps.window(90, 100, TimeUnit.MILLISECONDS).doOnNext(new Consumer<Observable<Integer>>() {

        int count;

        @Override
        public void accept(Observable<Integer> v) throws Exception {
            System.out.println(Thread.currentThread());
            if (count++ == 1) {
                secondWindowProcessing.countDown();
                try {
                    Thread.sleep(200);
                    isInterrupted.set(Thread.interrupted());
                } catch (InterruptedException ex) {
                    isInterrupted.set(true);
                }
                doOnNextDone.countDown();
            }
        }
    }).test();
    ps.onNext(1);
    assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS));
    ps.onError(new TestException());
    assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS));
    assertFalse("The doOnNext got interrupted!", isInterrupted.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Observable(io.reactivex.rxjava3.core.Observable)

Example 22 with SuppressUndeliverable

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

the class ObservableWindowWithTimeTest method skipOnError.

@Test
@SuppressUndeliverable
public void skipOnError() {
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<Integer> ps = PublishSubject.create();
    TestObserver<Integer> to = ps.window(1, 2, TimeUnit.SECONDS, scheduler).flatMap(Functions.<Observable<Integer>>identity()).test();
    ps.onError(new TestException());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Observable(io.reactivex.rxjava3.core.Observable)

Example 23 with SuppressUndeliverable

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

the class ObservableWindowWithStartEndObservableTest method endError.

@Test
@SuppressUndeliverable
public void endError() {
    PublishSubject<Integer> source = PublishSubject.create();
    PublishSubject<Integer> start = PublishSubject.create();
    final PublishSubject<Integer> end = PublishSubject.create();
    TestObserver<Integer> to = source.window(start, new Function<Integer, ObservableSource<Integer>>() {

        @Override
        public ObservableSource<Integer> apply(Integer v) throws Exception {
            return end;
        }
    }).flatMap(Functions.<Observable<Integer>>identity()).test();
    start.onNext(1);
    end.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("Source has observers!", source.hasObservers());
    assertFalse("Start has observers!", start.hasObservers());
    assertFalse("End has observers!", end.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Observable(io.reactivex.rxjava3.core.Observable)

Example 24 with SuppressUndeliverable

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

the class FlowableWindowWithFlowableTest method disposeMainBoundaryErrorRace.

@Test
@SuppressUndeliverable
public void disposeMainBoundaryErrorRace() {
    final TestException ex = new TestException();
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        final AtomicReference<Subscriber<? super Object>> refMain = new AtomicReference<>();
        final AtomicReference<Subscriber<? super Object>> ref = new AtomicReference<>();
        final TestSubscriber<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) {
                final AtomicInteger counter = new AtomicInteger();
                subscriber.onSubscribe(new Subscription() {

                    @Override
                    public void cancel() {
                        // about a microsecond
                        for (int i = 0; i < 100; i++) {
                            counter.incrementAndGet();
                        }
                    }

                    @Override
                    public void request(long n) {
                    }
                });
                ref.set(subscriber);
            }
        }).test();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                ts.cancel();
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                Subscriber<Object> subscriber = ref.get();
                subscriber.onNext(1);
                subscriber.onError(ex);
            }
        };
        TestHelper.race(r1, r2);
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 25 with SuppressUndeliverable

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

the class FutureSubscriberTest method onErrorCancelRace.

@Test
@SuppressUndeliverable
public void onErrorCancelRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
        final TestException ex = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                fs.cancel(false);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                fs.onError(ex);
            }
        };
        TestHelper.race(r1, r2);
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)31 Test (org.junit.Test)30 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Observable (io.reactivex.rxjava3.core.Observable)8 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)8 IOException (java.io.IOException)8 SuppressUndeliverable (io.reactivex.rxjava3.testsupport.SuppressUndeliverable)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)6 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)5 Scheduler (io.reactivex.rxjava3.core.Scheduler)3 TestObserver (io.reactivex.rxjava3.observers.TestObserver)3 NewThreadWorker (io.reactivex.rxjava3.internal.schedulers.NewThreadWorker)2 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)2 Observer (io.reactivex.rxjava3.core.Observer)1 Cancellable (io.reactivex.rxjava3.functions.Cancellable)1 ComputationScheduler (io.reactivex.rxjava3.internal.schedulers.ComputationScheduler)1 DelayedRunnable (io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.DelayedRunnable)1 IoScheduler (io.reactivex.rxjava3.internal.schedulers.IoScheduler)1 ScheduledWorker (io.reactivex.rxjava3.internal.schedulers.SingleScheduler.ScheduledWorker)1