use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method testHasNextThrows.
@Test(/* timeout = 1000, */
expected = RuntimeException.class)
public void testHasNextThrows() {
TestScheduler scheduler = new TestScheduler();
Observable<Long> source = Observable.<Long>error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> it = iter.iterator();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
it.hasNext();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class MaybeDelayTest method disposeDuringDelay.
@Test
public void disposeDuringDelay() {
TestScheduler scheduler = new TestScheduler();
TestObserver<Integer> ts = Maybe.just(1).delay(100, TimeUnit.MILLISECONDS, scheduler).test();
ts.cancel();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertEmpty();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method testSimpleJustNext.
@Test(timeout = 1000, expected = NoSuchElementException.class)
public void testSimpleJustNext() {
TestScheduler scheduler = new TestScheduler();
Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> it = iter.iterator();
// which onComplete will overwrite the previous value
for (int i = 0; i < 10; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(Long.valueOf(i), it.next());
}
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableThrottleFirstTest method before.
@Before
public void before() {
scheduler = new TestScheduler();
innerScheduler = scheduler.createWorker();
observer = TestHelper.mockObserver();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableThrottleFirstTest method testThrottle.
@Test
public void testThrottle() {
Observer<Integer> observer = TestHelper.mockObserver();
TestScheduler s = new TestScheduler();
PublishSubject<Integer> o = PublishSubject.create();
o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(observer);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
// deliver
o.onNext(1);
// skip
o.onNext(2);
s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
// deliver
o.onNext(3);
s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
// skip
o.onNext(4);
s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
// skip
o.onNext(5);
// skip
o.onNext(6);
s.advanceTimeTo(1001, TimeUnit.MILLISECONDS);
// deliver
o.onNext(7);
s.advanceTimeTo(1501, TimeUnit.MILLISECONDS);
o.onComplete();
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onNext(1);
inOrder.verify(observer).onNext(3);
inOrder.verify(observer).onNext(7);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
}
Aggregations