Search in sources :

Example 56 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class InstantPeriodicTaskTest method dispose2CurrentThread.

@Test
public void dispose2CurrentThread() throws Exception {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    try {
        InstantPeriodicTask task = new InstantPeriodicTask(new Runnable() {

            @Override
            public void run() {
                throw new TestException();
            }
        }, exec);
        task.runner = Thread.currentThread();
        task.setFirst(new FutureTask<Void>(Functions.EMPTY_RUNNABLE, null));
        task.setRest(new FutureTask<Void>(Functions.EMPTY_RUNNABLE, null));
        assertFalse(task.isDisposed());
        task.dispose();
        assertTrue(task.isDisposed());
        task.dispose();
        assertTrue(task.isDisposed());
    } finally {
        exec.shutdownNow();
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 57 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class InstantPeriodicTaskTest method restCancelRace.

@Test
public void restCancelRace() throws Exception {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    try {
        for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
            final InstantPeriodicTask task = new InstantPeriodicTask(new Runnable() {

                @Override
                public void run() {
                    throw new TestException();
                }
            }, exec);
            final FutureTask<Void> f1 = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    task.setRest(f1);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    task.dispose();
                }
            };
            TestHelper.race(r1, r2);
            assertTrue(f1.isCancelled());
            assertTrue(task.isDisposed());
        }
    } finally {
        exec.shutdownNow();
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 58 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class InstantPeriodicTaskTest method disposeOnCurrentThread.

@Test
public void disposeOnCurrentThread() throws Exception {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    try {
        InstantPeriodicTask task = new InstantPeriodicTask(new Runnable() {

            @Override
            public void run() {
                throw new TestException();
            }
        }, exec);
        task.runner = Thread.currentThread();
        task.dispose();
        FutureTask<Void> f1 = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
        task.setFirst(f1);
        assertTrue(f1.isCancelled());
        FutureTask<Void> f2 = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
        task.setRest(f2);
        assertTrue(f2.isCancelled());
    } finally {
        exec.shutdownNow();
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 59 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class InstantPeriodicTaskTest method taskCrash.

@Test
public void taskCrash() throws Exception {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        InstantPeriodicTask task = new InstantPeriodicTask(new Runnable() {

            @Override
            public void run() {
                throw new TestException();
            }
        }, exec);
        try {
            task.call();
            fail("Should have thrown!");
        } catch (TestException excepted) {
        // excepted
        }
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        exec.shutdownNow();
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 60 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class SingleSafeSubscribeTest method onSuccessCrash.

@Test
public void onSuccessCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
        doThrow(new TestException()).when(consumer).onSuccess(any());
        new Single<Integer>() {

            @Override
            protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onSuccess(1);
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verify(consumer).onSuccess(1);
        order.verifyNoMoreInteractions();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)656 Test (org.junit.Test)555 IOException (java.io.IOException)95 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)90 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)81 Disposable (io.reactivex.rxjava3.disposables.Disposable)56 InOrder (org.mockito.InOrder)54 TestObserver (io.reactivex.rxjava3.observers.TestObserver)47 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)47 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)40 Observable (io.reactivex.rxjava3.core.Observable)38 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)20 Action (io.reactivex.rxjava3.functions.Action)20 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)20 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)18 Observer (io.reactivex.rxjava3.core.Observer)15 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)15 Assert (org.junit.Assert)15 java.util (java.util)13 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)12