use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableSkipTimedTest method skipTimedFinishBeforeTime.
@Test
public void skipTimedFinishBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onComplete();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableSkipTimedTest method skipTimed.
@Test
public void skipTimed() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onNext(5);
source.onNext(6);
source.onComplete();
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber, never()).onNext(1);
inOrder.verify(subscriber, never()).onNext(2);
inOrder.verify(subscriber, never()).onNext(3);
inOrder.verify(subscriber).onNext(4);
inOrder.verify(subscriber).onNext(5);
inOrder.verify(subscriber).onNext(6);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableTimeoutTest method errorTimeoutRace.
@Test
public void errorTimeoutRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final TestScheduler scheduler = new TestScheduler();
final PublishSubject<Integer> ps = PublishSubject.create();
TestObserverEx<Void> to = ps.ignoreElements().timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()).to(TestHelper.<Void>testConsumer());
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
ps.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
}
};
TestHelper.race(r1, r2);
to.assertTerminated();
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableLatestTest method hasNextThrows.
@Test(expected = RuntimeException.class)
public void hasNextThrows() {
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.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableLatestTest method simple.
@Test
public void simple() {
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.assertTrue(it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertFalse(it.hasNext());
}
Aggregations