use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableMostRecentTest method testSingleSourceManyIterators.
@Test(timeout = 1000)
public void testSingleSourceManyIterators() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingMostRecent(-1L);
for (int j = 0; j < 3; j++) {
Iterator<Long> it = iter.iterator();
Assert.assertEquals(Long.valueOf(-1), it.next());
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableLatestTest method testSimple.
@Test(timeout = 1000)
public void testSimple() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.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 < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableLatestTest method testHasNextThrows.
@Test(/* timeout = 1000, */
expected = RuntimeException.class)
public void testHasNextThrows() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.<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 BlockingFlowableLatestTest method testSameSourceMultipleIterators.
@Test(timeout = 1000)
public void testSameSourceMultipleIterators() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.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.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableDisposeOnTest method errorAfterCancel.
@Test
public void errorAfterCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> ps = PublishSubject.create();
TestObserver<Void> to = ps.ignoreElements().unsubscribeOn(scheduler).test();
to.dispose();
ps.onError(new TestException());
to.assertEmpty();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations