use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SingleDelayTest method delayOnError.
@Test
public void delayOnError() {
final TestScheduler scheduler = new TestScheduler();
final TestObserver<?> observer = Single.error(new TestException()).delay(5, TimeUnit.SECONDS, scheduler).test();
scheduler.triggerActions();
observer.assertError(TestException.class);
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SchedulerWhenTest method asyncMaxConcurrent.
@Test
public void asyncMaxConcurrent() {
TestScheduler tSched = new TestScheduler();
SchedulerWhen sched = maxConcurrentScheduler(tSched);
TestSubscriber<Long> tSub = TestSubscriber.create();
asyncWork(sched).subscribe(tSub);
tSub.assertValueCount(0);
tSched.advanceTimeBy(0, SECONDS);
tSub.assertValueCount(0);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(2);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(4);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(5);
tSub.assertComplete();
sched.dispose();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableWindowTests method timeSizeWindowAlternatingBounds.
@Test
public void timeSizeWindowAlternatingBounds() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> pp = PublishProcessor.create();
TestSubscriber<List<Integer>> ts = pp.window(5, TimeUnit.SECONDS, scheduler, 2).flatMapSingle(new Function<Flowable<Integer>, SingleSource<List<Integer>>>() {
@Override
public SingleSource<List<Integer>> apply(Flowable<Integer> v) throws Throwable {
return v.toList();
}
}).test();
pp.onNext(1);
pp.onNext(2);
// size bound hit
ts.assertValueCount(1);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
pp.onNext(3);
scheduler.advanceTimeBy(6, TimeUnit.SECONDS);
// time bound hit
ts.assertValueCount(2);
pp.onNext(4);
pp.onNext(5);
// size bound hit again
ts.assertValueCount(3);
pp.onNext(4);
scheduler.advanceTimeBy(6, TimeUnit.SECONDS);
ts.assertValueCount(4).assertNoErrors().assertNotComplete();
ts.cancel();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableTimerTest method timer.
@Test
public void timer() {
final TestScheduler testScheduler = new TestScheduler();
final AtomicLong atomicLong = new AtomicLong();
Completable.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Action() {
@Override
public void run() throws Exception {
atomicLong.incrementAndGet();
}
});
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(1, atomicLong.get());
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSkipLastTimedTest method skipLastTimedErrorBeforeTimeDelayError.
@Test
public void skipLastTimedErrorBeforeTimeDelayError() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skipLast(1, TimeUnit.SECONDS, scheduler, true);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
scheduler.advanceTimeBy(1050, TimeUnit.MILLISECONDS);
verify(o).onError(any(TestException.class));
verify(o, never()).onComplete();
verify(o, never()).onNext(any());
}
Aggregations