use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class SingleDelayTest method delayedErrorOnError.
@Test
public void delayedErrorOnError() {
final TestScheduler scheduler = new TestScheduler();
final TestObserver<?> observer = Single.error(new TestException()).delay(5, TimeUnit.SECONDS, scheduler, true).test();
scheduler.advanceTimeTo(2, TimeUnit.SECONDS);
observer.assertNoErrors();
scheduler.advanceTimeTo(5, TimeUnit.SECONDS);
observer.assertError(TestException.class);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class SingleDetachTest method errorDetaches.
@Test
public void errorDetaches() throws Exception {
Disposable d = Disposable.empty();
final WeakReference<Disposable> wr = new WeakReference<>(d);
TestObserver<Integer> to = new Single<Integer>() {
@Override
protected void subscribeActual(SingleObserver<? super Integer> observer) {
observer.onSubscribe(wr.get());
observer.onError(new TestException());
observer.onError(new IOException());
}
}.onTerminateDetach().test();
d = null;
System.gc();
Thread.sleep(200);
to.assertFailure(TestException.class);
assertNull(wr.get());
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class SingleDoOnLifecycleTest method onDisposeCrash.
@Test
public void onDisposeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
Action onDispose = mock(Action.class);
doThrow(new TestException("First")).when(onDispose).run();
SingleSubject<Integer> ss = SingleSubject.create();
TestObserver<Integer> to = ss.doOnLifecycle(onSubscribe, onDispose).test();
assertTrue(ss.hasObservers());
to.dispose();
assertFalse(ss.hasObservers());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
verify(onSubscribe).accept(any());
verify(onDispose).run();
});
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class SingleTakeUntilTest method untilPublisherOtherError.
@Test
public void untilPublisherOtherError() {
SingleSubject<Integer> main = SingleSubject.create();
PublishProcessor<Integer> other = PublishProcessor.create();
TestObserver<Integer> to = main.takeUntil(other).test();
assertTrue("Main no observers?", main.hasObservers());
assertTrue("Other no observers?", other.hasSubscribers());
other.onError(new TestException());
assertFalse("Main has observers?", main.hasObservers());
assertFalse("Other has observers?", other.hasSubscribers());
to.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class SingleTimeoutTest method successTimeoutRace.
@Test
public void successTimeoutRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final SingleSubject<Integer> subj = SingleSubject.create();
SingleSubject<Integer> fallback = SingleSubject.create();
final TestScheduler sch = new TestScheduler();
TestObserver<Integer> to = subj.timeout(1, TimeUnit.MILLISECONDS, sch, fallback).test();
Runnable r1 = new Runnable() {
@Override
public void run() {
subj.onSuccess(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
sch.advanceTimeBy(1, TimeUnit.MILLISECONDS);
}
};
TestHelper.race(r1, r2);
if (!fallback.hasObservers()) {
to.assertResult(1);
} else {
to.assertEmpty();
}
}
}
Aggregations