Search in sources :

Example 1 with SuppressUndeliverable

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

the class ExecutorSchedulerDelayedRunnableTest method delayedRunnableCrash.

@Test(expected = TestException.class)
@SuppressUndeliverable
public void delayedRunnableCrash() {
    DelayedRunnable dl = new DelayedRunnable(new Runnable() {

        @Override
        public void run() {
            throw new TestException();
        }
    });
    dl.run();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) DelayedRunnable(io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.DelayedRunnable) DelayedRunnable(io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.DelayedRunnable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test) SuppressUndeliverable(io.reactivex.rxjava3.testsupport.SuppressUndeliverable)

Example 2 with SuppressUndeliverable

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

the class ComputationSchedulerTests method shutdownRejects.

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

        @Override
        public void run() {
            calls[0]++;
        }
    };
    Scheduler s = new ComputationScheduler();
    s.shutdown();
    s.shutdown();
    assertEquals(Disposable.disposed(), s.scheduleDirect(r));
    assertEquals(Disposable.disposed(), s.scheduleDirect(r, 1, TimeUnit.SECONDS));
    assertEquals(Disposable.disposed(), s.schedulePeriodicallyDirect(r, 1, 1, TimeUnit.SECONDS));
    Worker w = s.createWorker();
    w.dispose();
    assertTrue(w.isDisposed());
    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 : ComputationScheduler(io.reactivex.rxjava3.internal.schedulers.ComputationScheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) ComputationScheduler(io.reactivex.rxjava3.internal.schedulers.ComputationScheduler) Test(org.junit.Test) SuppressUndeliverable(io.reactivex.rxjava3.testsupport.SuppressUndeliverable)

Example 3 with SuppressUndeliverable

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

the class NewThreadSchedulerTest method npeRegression.

/**
 * Regression test to ensure there is no NPE when the worker has been disposed.
 * @throws Exception on error
 */
@Test
@SuppressUndeliverable
public void npeRegression() throws Exception {
    Scheduler s = getScheduler();
    NewThreadWorker w = (NewThreadWorker) s.createWorker();
    w.dispose();
    // This method used to throw a NPE when the worker has been disposed and the parent is null
    w.scheduleActual(new Runnable() {

        @Override
        public void run() {
        }
    }, 0, TimeUnit.MILLISECONDS, null);
}
Also used : Scheduler(io.reactivex.rxjava3.core.Scheduler) NewThreadWorker(io.reactivex.rxjava3.internal.schedulers.NewThreadWorker) Test(org.junit.Test) SuppressUndeliverable(io.reactivex.rxjava3.testsupport.SuppressUndeliverable)

Example 4 with SuppressUndeliverable

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

the class AsyncSubjectTest method onErrorCrossCancel.

@Test
@SuppressUndeliverable
public void onErrorCrossCancel() {
    AsyncSubject<Object> p = AsyncSubject.create();
    final TestObserver<Object> to2 = new TestObserver<>();
    TestObserver<Object> to1 = new TestObserver<Object>() {

        @Override
        public void onError(Throwable t) {
            to2.dispose();
            super.onError(t);
        }
    };
    p.subscribe(to1);
    p.subscribe(to2);
    p.onError(new TestException());
    to1.assertFailure(TestException.class);
    to2.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 5 with SuppressUndeliverable

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

the class ObservableCreateTest method basicSerialized.

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

        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e = e.serialize();
            e.setDisposable(d);
            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(d.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) 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