Search in sources :

Example 6 with SuppressUndeliverable

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

the class ObservableCreateTest method basicWithCancellable.

@Test
@SuppressUndeliverable
public void basicWithCancellable() {
    final Disposable d1 = Disposable.empty();
    final Disposable d2 = Disposable.empty();
    Observable.<Integer>create(new ObservableOnSubscribe<Integer>() {

        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e.setDisposable(d1);
            e.setCancellable(new Cancellable() {

                @Override
                public void cancel() throws Exception {
                    d2.dispose();
                }
            });
            e.onNext(1);
            e.onNext(2);
            e.onNext(3);
            e.onComplete();
            e.onError(new TestException());
            e.onNext(4);
            e.onError(new TestException());
            e.onComplete();
        }
    }).test().assertResult(1, 2, 3);
    assertTrue(d1.isDisposed());
    assertTrue(d2.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) Cancellable(io.reactivex.rxjava3.functions.Cancellable) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with SuppressUndeliverable

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

the class CachedThreadSchedulerTest method shutdownRejects.

@Test
@SuppressUndeliverable
public void shutdownRejects() {
    final int[] calls = { 0 };
    Runnable r = new Runnable() {

        @Override
        public void run() {
            calls[0]++;
        }
    };
    IoScheduler s = new IoScheduler();
    s.shutdown();
    s.shutdown();
    s.scheduleDirect(r);
    s.scheduleDirect(r, 1, TimeUnit.SECONDS);
    s.schedulePeriodicallyDirect(r, 1, 1, TimeUnit.SECONDS);
    Worker w = s.createWorker();
    w.dispose();
    assertEquals(Disposable.disposed(), w.schedule(r));
    assertEquals(Disposable.disposed(), w.schedule(r, 1, TimeUnit.SECONDS));
    assertEquals(Disposable.disposed(), w.schedulePeriodically(r, 1, 1, TimeUnit.SECONDS));
    assertEquals(0, calls[0]);
}
Also used : IoScheduler(io.reactivex.rxjava3.internal.schedulers.IoScheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test) SuppressUndeliverable(io.reactivex.rxjava3.testsupport.SuppressUndeliverable)

Example 8 with SuppressUndeliverable

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

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

the class AsyncProcessorTest method onErrorCrossCancel.

@Test
@SuppressUndeliverable
public void onErrorCrossCancel() {
    AsyncProcessor<Object> p = AsyncProcessor.create();
    final TestSubscriber<Object> ts2 = new TestSubscriber<>();
    TestSubscriber<Object> ts1 = new TestSubscriber<Object>() {

        @Override
        public void onError(Throwable t) {
            ts2.cancel();
            super.onError(t);
        }
    };
    p.subscribe(ts1);
    p.subscribe(ts2);
    p.onError(new TestException());
    ts1.assertFailure(TestException.class);
    ts2.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 10 with SuppressUndeliverable

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

the class CompletableFromCallableTest method fromActionErrorsDisposed.

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

        @Override
        public Object call() 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