use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableDelayTest method onErrorFinal.
@Test
public void onErrorFinal() {
TestScheduler scheduler = new TestScheduler();
Observable.error(new TestException()).delay(1, TimeUnit.MILLISECONDS, scheduler).subscribe(new DisposableObserver<Object>() {
@Override
public void onNext(Object value) {
}
@Override
public void onError(Throwable e) {
throw new TestException();
}
@Override
public void onComplete() {
}
});
try {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableMostRecentTest method singleSourceManyIterators.
@Test
public void singleSourceManyIterators() {
TestScheduler scheduler = new TestScheduler();
Observable<Long> source = Observable.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 FlowableObserveOnTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestScheduler scheduler = new TestScheduler();
TestSubscriber<Integer> ts = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onComplete();
subscriber.onNext(1);
subscriber.onError(new TestException());
subscriber.onComplete();
}
}.observeOn(scheduler).test();
scheduler.triggerActions();
ts.assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableReplayEagerTruncateTest method timedAndSizedTruncationError.
@Test
public void timedAndSizedTruncationError() {
TestScheduler test = new TestScheduler();
SizeAndTimeBoundReplayBuffer<Integer> buf = new SizeAndTimeBoundReplayBuffer<>(2, 2000, TimeUnit.MILLISECONDS, test, true);
Assert.assertFalse(buf.hasCompleted());
Assert.assertFalse(buf.hasError());
List<Integer> values = new ArrayList<>();
buf.next(1);
test.advanceTimeBy(1, TimeUnit.SECONDS);
buf.next(2);
test.advanceTimeBy(1, TimeUnit.SECONDS);
buf.collect(values);
Assert.assertEquals(Arrays.asList(2), values);
buf.next(3);
buf.next(4);
values.clear();
buf.collect(values);
Assert.assertEquals(Arrays.asList(3, 4), values);
test.advanceTimeBy(2, TimeUnit.SECONDS);
buf.next(5);
values.clear();
buf.collect(values);
Assert.assertEquals(Arrays.asList(5), values);
Assert.assertFalse(buf.hasCompleted());
Assert.assertFalse(buf.hasError());
test.advanceTimeBy(2, TimeUnit.SECONDS);
buf.error(new TestException());
values.clear();
buf.collect(values);
Assert.assertTrue(values.isEmpty());
Assert.assertEquals(1, buf.size);
Assert.assertFalse(buf.hasCompleted());
Assert.assertTrue(buf.hasError());
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSkipLastTimedTest method skipLastTimedErrorBeforeTime.
@Test
public void skipLastTimedErrorBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skipLast(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
scheduler.advanceTimeBy(1050, TimeUnit.MILLISECONDS);
verify(o).onError(any(TestException.class));
verify(o, never()).onComplete();
verify(o, never()).onNext(any());
}
Aggregations