use of io.reactivex.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.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleWithTimeoutTests method testThrottle.
@Test
public void testThrottle() {
Subscriber<Integer> observer = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s).subscribe(observer);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
// skip
o.onNext(1);
// deliver
o.onNext(2);
s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
// skip
o.onNext(3);
s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
// skip
o.onNext(4);
s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
// skip
o.onNext(5);
// deliver at 1300 after 500ms has passed since onNext(5)
o.onNext(6);
s.advanceTimeTo(1300, TimeUnit.MILLISECONDS);
// deliver
o.onNext(7);
s.advanceTimeTo(1800, TimeUnit.MILLISECONDS);
o.onComplete();
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onNext(2);
inOrder.verify(observer).onNext(6);
inOrder.verify(observer).onNext(7);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableDebounceTest method before.
@Before
public void before() {
scheduler = new TestScheduler();
observer = TestHelper.mockSubscriber();
innerScheduler = scheduler.createWorker();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableDisposeOnTest method error.
@Test
public void error() {
TestScheduler scheduler = new TestScheduler();
final int[] call = { 0 };
Completable.error(new TestException()).doOnDispose(new Action() {
@Override
public void run() throws Exception {
call[0]++;
}
}).unsubscribeOn(scheduler).test().assertFailure(TestException.class);
scheduler.triggerActions();
assertEquals(0, call[0]);
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableDisposeOnTest method cancelDelayed.
@Test
public void cancelDelayed() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> ps = PublishSubject.create();
ps.ignoreElements().unsubscribeOn(scheduler).test().cancel();
assertTrue(ps.hasObservers());
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertFalse(ps.hasObservers());
}
Aggregations