use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class TestSchedulerTest method workerDisposed.
@Test
public void workerDisposed() {
TestScheduler scheduler = new TestScheduler();
Worker w = scheduler.createWorker();
w.dispose();
assertTrue(w.isDisposed());
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class TestSchedulerTest method nestedSchedule.
@Test
public final void nestedSchedule() {
final TestScheduler scheduler = new TestScheduler();
final Scheduler.Worker inner = scheduler.createWorker();
try {
final Runnable calledOp = mock(Runnable.class);
Flowable<Object> poller;
poller = Flowable.unsafeCreate(new Publisher<Object>() {
@Override
public void subscribe(final Subscriber<? super Object> aSubscriber) {
final BooleanSubscription bs = new BooleanSubscription();
aSubscriber.onSubscribe(bs);
inner.schedule(new Runnable() {
@Override
public void run() {
if (!bs.isCancelled()) {
calledOp.run();
inner.schedule(this, 5, TimeUnit.SECONDS);
}
}
});
}
});
InOrder inOrder = Mockito.inOrder(calledOp);
Disposable sub;
sub = poller.subscribe();
scheduler.advanceTimeTo(6, TimeUnit.SECONDS);
inOrder.verify(calledOp, times(2)).run();
sub.dispose();
scheduler.advanceTimeTo(11, TimeUnit.SECONDS);
inOrder.verify(calledOp, never()).run();
sub = poller.subscribe();
scheduler.advanceTimeTo(12, TimeUnit.SECONDS);
inOrder.verify(calledOp, times(1)).run();
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method rejectingExecutor.
@Test
public void rejectingExecutor() {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
exec.shutdown();
Scheduler s = Schedulers.from(exec);
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
assertSame(EmptyDisposable.INSTANCE, s.scheduleDirect(Functions.EMPTY_RUNNABLE));
assertSame(EmptyDisposable.INSTANCE, s.scheduleDirect(Functions.EMPTY_RUNNABLE, 10, TimeUnit.MILLISECONDS));
assertSame(EmptyDisposable.INSTANCE, s.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 10, 10, TimeUnit.MILLISECONDS));
TestHelper.assertUndeliverable(errors, 0, RejectedExecutionException.class);
TestHelper.assertUndeliverable(errors, 1, RejectedExecutionException.class);
TestHelper.assertUndeliverable(errors, 2, RejectedExecutionException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method unwrapScheduleDirectTaskAfterDispose.
@Test
public void unwrapScheduleDirectTaskAfterDispose() {
Scheduler scheduler = getScheduler();
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();
assertSame(Functions.EMPTY_RUNNABLE, wrapper.getWrappedRunnable());
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class NewThreadSchedulerTest method npeRegression.
/**
* Regression test to ensure there is no NPE when the worker has been disposed.
* @throws Exception on error
*/
@Test
@SuppressUndeliverable
public void npeRegression() throws Exception {
Scheduler s = getScheduler();
NewThreadWorker w = (NewThreadWorker) s.createWorker();
w.dispose();
// This method used to throw a NPE when the worker has been disposed and the parent is null
w.scheduleActual(new Runnable() {
@Override
public void run() {
}
}, 0, TimeUnit.MILLISECONDS, null);
}
Aggregations