use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class SchedulerTest method disposePeriodicDirect.
@Test
public void disposePeriodicDirect() {
final int[] count = { 0 };
TestScheduler scheduler = new TestScheduler();
Disposable d = scheduler.schedulePeriodicallyDirect(new Runnable() {
@Override
public void run() {
count[0]++;
}
}, 100, 100, TimeUnit.MILLISECONDS);
d.dispose();
assertEquals(0, count[0]);
assertTrue(d.isDisposed());
scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
assertEquals(0, count[0]);
assertTrue(d.isDisposed());
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class SchedulerTest method disposeSelfPeriodicDirect.
@Test
public void disposeSelfPeriodicDirect() {
final int[] count = { 0 };
TestScheduler scheduler = new TestScheduler();
final SequentialDisposable sd = new SequentialDisposable();
Disposable d = scheduler.schedulePeriodicallyDirect(new Runnable() {
@Override
public void run() {
count[0]++;
sd.dispose();
}
}, 100, 100, TimeUnit.MILLISECONDS);
sd.set(d);
assertEquals(0, count[0]);
assertFalse(d.isDisposed());
scheduler.advanceTimeBy(400, TimeUnit.MILLISECONDS);
assertEquals(1, count[0]);
assertTrue(d.isDisposed());
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerFairTest method plainExecutor.
@Test
public void plainExecutor() throws Exception {
Scheduler s = Schedulers.from(new Executor() {
@Override
public void execute(Runnable r) {
r.run();
}
}, false, true);
final CountDownLatch cdl = new CountDownLatch(5);
Runnable r = new Runnable() {
@Override
public void run() {
cdl.countDown();
}
};
s.scheduleDirect(r);
s.scheduleDirect(r, 50, TimeUnit.MILLISECONDS);
Disposable d = s.schedulePeriodicallyDirect(r, 10, 10, TimeUnit.MILLISECONDS);
try {
assertTrue(cdl.await(5, TimeUnit.SECONDS));
} finally {
d.dispose();
}
assertTrue(d.isDisposed());
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerFairTest method runnableDisposed.
@Test
public void runnableDisposed() {
final Scheduler s = Schedulers.from(new Executor() {
@Override
public void execute(Runnable r) {
r.run();
}
}, false, true);
Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE);
assertTrue(d.isDisposed());
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerFairTest method runnableDisposedAsyncTimed2.
@Test
public void runnableDisposedAsyncTimed2() throws Exception {
ExecutorService executorScheduler = Executors.newScheduledThreadPool(1, new RxThreadFactory("TestCustomPoolTimed"));
try {
final Scheduler s = Schedulers.from(executorScheduler, false, true);
Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
while (!d.isDisposed()) {
Thread.sleep(1);
}
} finally {
executorScheduler.shutdownNow();
}
}
Aggregations