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();
}
}
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();
}
}
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();
}
}
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();
}
}
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);
});
}
Aggregations