use of io.reactivex.Scheduler.Worker in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerUnsubscriptionDoesNotAffectOtherWorkers.
@Test
public void workerUnsubscriptionDoesNotAffectOtherWorkers() {
Worker workerA = scheduler.createWorker();
CountingRunnable counterA = new CountingRunnable();
workerA.schedule(counterA, 1, MINUTES);
Worker workerB = scheduler.createWorker();
CountingRunnable counterB = new CountingRunnable();
workerB.schedule(counterB, 1, MINUTES);
workerA.dispose();
runUiThreadTasksIncludingDelayedTasks();
assertEquals(0, counterA.get());
assertEquals(1, counterB.get());
}
use of io.reactivex.Scheduler.Worker in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerScheduleOnceUsesHook.
@Test
public void workerScheduleOnceUsesHook() {
final CountingRunnable newCounter = new CountingRunnable();
final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
@Override
public Runnable apply(Runnable runnable) {
runnableRef.set(runnable);
return newCounter;
}
});
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
worker.schedule(counter);
// Verify our runnable was passed to the schedulers hook.
assertSame(counter, runnableRef.get());
runUiThreadTasks();
// Verify the scheduled runnable was the one returned from the hook.
assertEquals(1, newCounter.get());
assertEquals(0, counter.get());
}
use of io.reactivex.Scheduler.Worker in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerDisposeCancelsScheduled.
@Test
public void workerDisposeCancelsScheduled() {
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
worker.schedule(counter, 1, MINUTES);
worker.dispose();
runUiThreadTasks();
assertEquals(0, counter.get());
}
use of io.reactivex.Scheduler.Worker in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method throwingActionRoutedToHookAndThreadHandler.
@Test
public void throwingActionRoutedToHookAndThreadHandler() {
// TODO Test hook as well. Requires https://github.com/ReactiveX/RxJava/pull/3820.
Thread thread = Thread.currentThread();
UncaughtExceptionHandler originalHandler = thread.getUncaughtExceptionHandler();
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
throwableRef.set(ex);
}
});
Worker worker = scheduler.createWorker();
final NullPointerException npe = new NullPointerException();
Runnable action = new Runnable() {
@Override
public void run() {
throw npe;
}
};
worker.schedule(action);
runUiThreadTasks();
Throwable throwable = throwableRef.get();
assertTrue(throwable instanceof IllegalStateException);
assertEquals("Fatal Exception thrown on Scheduler.", throwable.getMessage());
assertSame(npe, throwable.getCause());
// Restore the original uncaught exception handler.
thread.setUncaughtExceptionHandler(originalHandler);
}
use of io.reactivex.Scheduler.Worker in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerTracksDisposedState.
@Test
public void workerTracksDisposedState() {
Worker worker = scheduler.createWorker();
assertFalse(worker.isDisposed());
worker.dispose();
assertTrue(worker.isDisposed());
}
Aggregations