use of io.reactivex.rxjava3.internal.schedulers.ComputationScheduler 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]);
}
use of io.reactivex.rxjava3.internal.schedulers.ComputationScheduler in project RxJava by ReactiveX.
the class ComputationSchedulerTests method exceptionFromObservableShouldNotBeSwallowed.
@Test
public void exceptionFromObservableShouldNotBeSwallowed() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
// #3 thread's uncaught exception handler
Scheduler computationScheduler = new ComputationScheduler(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setUncaughtExceptionHandler((thread, throwable) -> {
latch.countDown();
});
return t;
}
});
// #2 RxJava exception handler
RxJavaPlugins.setErrorHandler(h -> {
latch.countDown();
});
// and should not be swallowed.
try {
// #1 observer's onError()
Observable.create(s -> {
s.onNext(1);
throw new OutOfMemoryError();
}).subscribeOn(computationScheduler).subscribe(v -> {
}, e -> {
latch.countDown();
});
assertTrue(latch.await(2, TimeUnit.SECONDS));
} finally {
RxJavaPlugins.reset();
computationScheduler.shutdown();
}
}
use of io.reactivex.rxjava3.internal.schedulers.ComputationScheduler in project RxJava by ReactiveX.
the class ComputationSchedulerTests method exceptionFromObserverShouldNotBeSwallowed.
@Test
public void exceptionFromObserverShouldNotBeSwallowed() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
// #3 thread's uncaught exception handler
Scheduler computationScheduler = new ComputationScheduler(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setUncaughtExceptionHandler((thread, throwable) -> {
latch.countDown();
});
return t;
}
});
// #2 RxJava exception handler
RxJavaPlugins.setErrorHandler(h -> {
latch.countDown();
});
// and should not be swallowed.
try {
// #1 observer's onError()
Flowable.interval(500, TimeUnit.MILLISECONDS, computationScheduler).subscribe(v -> {
throw new OutOfMemoryError();
}, e -> {
latch.countDown();
});
assertTrue(latch.await(2, TimeUnit.SECONDS));
} finally {
RxJavaPlugins.reset();
computationScheduler.shutdown();
}
}
Aggregations