use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerInterruptibleTest 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 AbstractSchedulerTests method recursiveExecutionWithDelayTime.
@Test
public final void recursiveExecutionWithDelayTime() throws InterruptedException {
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() {
int state;
@Override
public void run() {
i.set(state);
if (state++ < 100) {
inner.schedule(this, 1, TimeUnit.MILLISECONDS);
} else {
latch.countDown();
}
}
});
latch.await();
assertEquals(100, i.get());
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method schedulePeriodicallyDirectZeroPeriod.
@Test
public void schedulePeriodicallyDirectZeroPeriod() throws Exception {
Scheduler s = getScheduler();
if (s instanceof TrampolineScheduler) {
// can't properly stop a trampolined periodic task
return;
}
for (int initial = 0; initial < 2; initial++) {
final CountDownLatch cdl = new CountDownLatch(1);
final SequentialDisposable sd = new SequentialDisposable();
try {
sd.replace(s.schedulePeriodicallyDirect(new Runnable() {
int count;
@Override
public void run() {
if (++count == 10) {
sd.dispose();
cdl.countDown();
}
}
}, initial, 0, TimeUnit.MILLISECONDS));
assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
} finally {
sd.dispose();
}
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method nestedActions.
@Test
public void nestedActions() throws InterruptedException {
Scheduler scheduler = getScheduler();
final Scheduler.Worker inner = scheduler.createWorker();
try {
final CountDownLatch latch = new CountDownLatch(1);
final Runnable firstStepStart = mock(Runnable.class);
final Runnable firstStepEnd = mock(Runnable.class);
final Runnable secondStepStart = mock(Runnable.class);
final Runnable secondStepEnd = mock(Runnable.class);
final Runnable thirdStepStart = mock(Runnable.class);
final Runnable thirdStepEnd = mock(Runnable.class);
final Runnable firstAction = new Runnable() {
@Override
public void run() {
firstStepStart.run();
firstStepEnd.run();
latch.countDown();
}
};
final Runnable secondAction = new Runnable() {
@Override
public void run() {
secondStepStart.run();
inner.schedule(firstAction);
secondStepEnd.run();
}
};
final Runnable thirdAction = new Runnable() {
@Override
public void run() {
thirdStepStart.run();
inner.schedule(secondAction);
thirdStepEnd.run();
}
};
InOrder inOrder = inOrder(firstStepStart, firstStepEnd, secondStepStart, secondStepEnd, thirdStepStart, thirdStepEnd);
inner.schedule(thirdAction);
latch.await();
inOrder.verify(thirdStepStart, times(1)).run();
inOrder.verify(thirdStepEnd, times(1)).run();
inOrder.verify(secondStepStart, times(1)).run();
inOrder.verify(secondStepEnd, times(1)).run();
inOrder.verify(firstStepStart, times(1)).run();
inOrder.verify(firstStepEnd, times(1)).run();
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method subscribeOnNestedConcurrency.
@Test
public final void subscribeOnNestedConcurrency() throws InterruptedException {
final Scheduler scheduler = getScheduler();
Flowable<String> f = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten").flatMap(new Function<String, Flowable<String>>() {
@Override
public Flowable<String> apply(final String v) {
return Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext("value_after_map-" + v);
subscriber.onComplete();
}
}).subscribeOn(scheduler);
}
});
ConcurrentObserverValidator<String> observer = new ConcurrentObserverValidator<>();
f.subscribe(observer);
if (!observer.completed.await(3000, TimeUnit.MILLISECONDS)) {
fail("timed out");
}
if (observer.error.get() != null) {
observer.error.get().printStackTrace();
fail("Error: " + observer.error.get().getMessage());
}
}
Aggregations