use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class MaybeTimerTest method timer.
@Test
public void timer() {
final TestScheduler testScheduler = new TestScheduler();
final AtomicLong atomicLong = new AtomicLong();
Maybe.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Consumer<Long>() {
@Override
public void accept(final Long value) 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.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method takeSizeAndTime.
@Test
public void takeSizeAndTime() {
TestScheduler scheduler = new TestScheduler();
ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
rp.onNext(1);
rp.onNext(2);
rp.onNext(3);
rp.take(1).test().assertResult(2);
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method timedNoOutdatedData.
@Test
public void timedNoOutdatedData() {
TestScheduler scheduler = new TestScheduler();
ReplayProcessor<Integer> source = ReplayProcessor.createWithTime(2, TimeUnit.SECONDS, scheduler);
source.onNext(1);
source.onComplete();
source.test().assertResult(1);
source.test().assertResult(1);
scheduler.advanceTimeBy(3, TimeUnit.SECONDS);
source.test().assertResult();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method timedSkipOld.
@Test
public void timedSkipOld() {
TestScheduler scheduler = new TestScheduler();
ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
rp.onNext(1);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
rp.test().assertEmpty();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method reentrantDrain.
@Test
public void reentrantDrain() {
TestScheduler scheduler = new TestScheduler();
final ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
if (t == 1) {
rp.onNext(2);
}
super.onNext(t);
}
};
rp.subscribe(ts);
rp.onNext(1);
rp.onComplete();
ts.assertResult(1, 2);
}
Aggregations