use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableSkipTimedTest method skipTimedErrorBeforeTime.
@Test
public void skipTimedErrorBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableSkipTimedTest method skipTimedFinishBeforeTime.
@Test
public void skipTimedFinishBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onComplete();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableSkipTimedTest method skipTimed.
@Test
public void skipTimed() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onNext(5);
source.onNext(6);
source.onComplete();
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber, never()).onNext(1);
inOrder.verify(subscriber, never()).onNext(2);
inOrder.verify(subscriber, never()).onNext(3);
inOrder.verify(subscriber).onNext(4);
inOrder.verify(subscriber).onNext(5);
inOrder.verify(subscriber).onNext(6);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableTimerTest method timerInterruptible.
@Test
public void timerInterruptible() throws Exception {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
try {
for (Scheduler s : new Scheduler[] { Schedulers.single(), Schedulers.computation(), Schedulers.newThread(), Schedulers.io(), Schedulers.from(exec, true) }) {
final AtomicBoolean interrupted = new AtomicBoolean();
TestSubscriber<Long> ts = Flowable.timer(1, TimeUnit.MILLISECONDS, s).map(new Function<Long, Long>() {
@Override
public Long apply(Long v) throws Exception {
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
interrupted.set(true);
}
return v;
}
}).test();
Thread.sleep(500);
ts.cancel();
Thread.sleep(500);
assertTrue(s.getClass().getSimpleName(), interrupted.get());
}
} finally {
exec.shutdown();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class RxJavaPluginsTest method createNewThreadScheduler.
@Test
public void createNewThreadScheduler() {
final String name = "NewThreadSchedulerTest";
ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, name);
}
};
final Scheduler customScheduler = RxJavaPlugins.createNewThreadScheduler(factory);
RxJavaPlugins.setNewThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler scheduler) throws Exception {
return customScheduler;
}
});
try {
verifyThread(Schedulers.newThread(), name);
} finally {
customScheduler.shutdown();
RxJavaPlugins.reset();
}
}
Aggregations