use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class SingleDoOnLifecycleTest method onDisposeCrash.
@Test
public void onDisposeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
Action onDispose = mock(Action.class);
doThrow(new TestException("First")).when(onDispose).run();
SingleSubject<Integer> ss = SingleSubject.create();
TestObserver<Integer> to = ss.doOnLifecycle(onSubscribe, onDispose).test();
assertTrue(ss.hasObservers());
to.dispose();
assertFalse(ss.hasObservers());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
verify(onSubscribe).accept(any());
verify(onDispose).run();
});
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class AbstractSchedulerTests method schedulePeriodicallyDirectDecoratesRunnable.
@Test
public void schedulePeriodicallyDirectDecoratesRunnable() throws InterruptedException {
final Scheduler scheduler = getScheduler();
if (scheduler instanceof TrampolineScheduler) {
// Can't properly stop a trampolined periodic task.
return;
}
final AtomicReference<Disposable> disposable = new AtomicReference<>();
try {
assertRunnableDecorated(new Runnable() {
@Override
public void run() {
disposable.set(scheduler.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 1, 10000, TimeUnit.MILLISECONDS));
}
});
} finally {
disposable.get().dispose();
}
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class AbstractSchedulerTests method scheduleDirectPeriodic.
@Test
public void scheduleDirectPeriodic() throws Exception {
Scheduler s = getScheduler();
if (s instanceof TrampolineScheduler) {
// can't properly stop a trampolined periodic task
return;
}
final CountDownLatch cdl = new CountDownLatch(5);
Disposable d = s.schedulePeriodicallyDirect(new Runnable() {
@Override
public void run() {
cdl.countDown();
}
}, 10, 10, TimeUnit.MILLISECONDS);
try {
assertTrue(cdl.await(5, TimeUnit.SECONDS));
} finally {
d.dispose();
}
assertTrue(d.isDisposed());
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class AbstractSchedulerTests method unwrapScheduleDirectTask.
@Test
public void unwrapScheduleDirectTask() {
Scheduler scheduler = getScheduler();
if (scheduler instanceof TrampolineScheduler) {
// TrampolineScheduler always return EmptyDisposable
return;
}
final CountDownLatch cdl = new CountDownLatch(1);
Runnable countDownRunnable = new Runnable() {
@Override
public void run() {
cdl.countDown();
}
};
Disposable disposable = scheduler.scheduleDirect(countDownRunnable, 100, TimeUnit.MILLISECONDS);
SchedulerRunnableIntrospection wrapper = (SchedulerRunnableIntrospection) disposable;
assertSame(countDownRunnable, wrapper.getWrappedRunnable());
disposable.dispose();
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class ExecutorSchedulerInterruptibleTest method runnableDisposedAsync2.
@Test
public void runnableDisposedAsync2() throws Exception {
final Scheduler s = Schedulers.from(executor, true);
Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE);
while (!d.isDisposed()) {
Thread.sleep(1);
}
}
Aggregations