use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method hasNextThrows.
@Test(expected = RuntimeException.class)
public void hasNextThrows() {
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.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method nextThrows.
@Test(expected = RuntimeException.class)
public void nextThrows() {
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.next();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method sameSourceMultipleIterators.
@Test
public void sameSourceMultipleIterators() {
TestScheduler scheduler = new TestScheduler();
Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingLatest();
for (int j = 0; j < 3; j++) {
Iterator<Long> it = iter.iterator();
// which onComplete will overwrite the previous value
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertTrue(it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertFalse(it.hasNext());
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SchedulerWhenTest method syncDelaySubscription.
@Test
public void syncDelaySubscription() {
final TestScheduler tSched = new TestScheduler();
SchedulerWhen sched = throttleScheduler(tSched);
TestSubscriber<Long> tSub = TestSubscriber.create();
syncWork(sched).subscribe(tSub);
tSub.assertValueCount(0);
tSched.advanceTimeBy(0, SECONDS);
tSub.assertValueCount(1);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(2);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(3);
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 SchedulerWhenTest method asyncDelaySubscription.
@Test
public void asyncDelaySubscription() {
final TestScheduler tSched = new TestScheduler();
SchedulerWhen sched = throttleScheduler(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(1);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(1);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(2);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(2);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(3);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(3);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(4);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(4);
tSched.advanceTimeBy(1, SECONDS);
tSub.assertValueCount(5);
tSub.assertComplete();
sched.dispose();
}
Aggregations