Search in sources :

Example 31 with SuppressUndeliverable

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

the class ObservableWindowWithTimeTest method exactTimeBoundNoInterruptWindowOutputOnError.

@Test
@SuppressUndeliverable
public void exactTimeBoundNoInterruptWindowOutputOnError() 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(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 32 with SuppressUndeliverable

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

the class ObservableWindowWithTimeTest method exactOnError.

@Test
@SuppressUndeliverable
public void exactOnError() {
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<Integer> ps = PublishSubject.create();
    TestObserver<Integer> to = ps.window(1, 1, 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 33 with SuppressUndeliverable

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

the class ObservableWindowWithTimeTest method exactTimeAndSizeBoundNoInterruptWindowOutputOnError.

@Test
@SuppressUndeliverable
public void exactTimeAndSizeBoundNoInterruptWindowOutputOnError() 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(100, TimeUnit.MILLISECONDS, 10).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 34 with SuppressUndeliverable

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

the class SerializedSubscriberTest method onErrorQueuedUp.

@Test
@SuppressUndeliverable
public void onErrorQueuedUp() {
    AtomicReference<SerializedSubscriber<Integer>> ssRef = new AtomicReference<>();
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            ssRef.get().onNext(2);
            ssRef.get().onError(new TestException());
        }
    };
    final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts, true);
    ssRef.set(so);
    BooleanSubscription bs = new BooleanSubscription();
    so.onSubscribe(bs);
    so.onNext(1);
    ts.assertFailure(TestException.class, 1, 2);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 35 with SuppressUndeliverable

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

the class CompletableFromSupplierTest method fromActionErrorsDisposed.

@Test
@SuppressUndeliverable
public void fromActionErrorsDisposed() {
    final AtomicInteger calls = new AtomicInteger();
    Completable.fromSupplier(new Supplier<Object>() {

        @Override
        public Object get() throws Exception {
            calls.incrementAndGet();
            throw new TestException();
        }
    }).test(true).assertEmpty();
    assertEquals(1, calls.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

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