use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class SingleTimeoutTest method shouldUnsubscribeFromUnderlyingSubscriptionOnDispose.
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
final PublishSubject<String> subject = PublishSubject.create();
final TestScheduler scheduler = new TestScheduler();
final TestObserver<String> observer = subject.single("").timeout(100, TimeUnit.MILLISECONDS, scheduler).test();
assertTrue(subject.hasObservers());
observer.dispose();
assertFalse(subject.hasObservers());
}
use of io.reactivex.rxjava3.core.Scheduler 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.core.Scheduler 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.core.Scheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method sequenceOfDelayedActions.
@Test
public void sequenceOfDelayedActions() throws InterruptedException {
Scheduler scheduler = getScheduler();
final Scheduler.Worker inner = scheduler.createWorker();
try {
final CountDownLatch latch = new CountDownLatch(1);
final Runnable first = mock(Runnable.class);
final Runnable second = mock(Runnable.class);
inner.schedule(new Runnable() {
@Override
public void run() {
inner.schedule(first, 30, TimeUnit.MILLISECONDS);
inner.schedule(second, 10, TimeUnit.MILLISECONDS);
inner.schedule(new Runnable() {
@Override
public void run() {
latch.countDown();
}
}, 40, TimeUnit.MILLISECONDS);
}
});
latch.await();
InOrder inOrder = inOrder(first, second);
inOrder.verify(second, times(1)).run();
inOrder.verify(first, times(1)).run();
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method recursiveExecution.
@Test
public final void recursiveExecution() throws InterruptedException {
final Scheduler scheduler = getScheduler();
final Scheduler.Worker inner = scheduler.createWorker();
try {
final AtomicInteger i = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1);
inner.schedule(new Runnable() {
@Override
public void run() {
if (i.incrementAndGet() < 100) {
inner.schedule(this);
} else {
latch.countDown();
}
}
});
latch.await();
assertEquals(100, i.get());
} finally {
inner.dispose();
}
}
Aggregations