use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableLatestTest method simpleJustNext.
@Test(expected = NoSuchElementException.class)
public void simpleJustNext() {
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 < 10; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(Long.valueOf(i), it.next());
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableDelaySubscriptionTest method timestep.
@Test
public void timestep() {
TestScheduler scheduler = new TestScheduler();
final AtomicInteger counter = new AtomicInteger();
Completable result = Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
counter.incrementAndGet();
}
}).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
TestObserver<Void> to = result.test();
scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
to.assertEmpty();
scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
to.assertResult();
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableDelaySubscriptionTest method disposeMain.
@Test
public void disposeMain() {
CompletableSubject cs = CompletableSubject.create();
TestScheduler scheduler = new TestScheduler();
TestObserver<Void> to = cs.delaySubscription(1, TimeUnit.SECONDS, scheduler).test();
assertFalse(cs.hasObservers());
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertTrue(cs.hasObservers());
to.dispose();
assertFalse(cs.hasObservers());
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableMostRecentTest method singleSourceManyIterators.
@Test
public void singleSourceManyIterators() {
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.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 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]);
}
Aggregations