use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableMergeTest method mergeErrors.
@Test
public void mergeErrors() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Observable<Integer> source1 = Observable.error(new TestException("First"));
Observable<Integer> source2 = Observable.error(new TestException("Second"));
Observable.merge(source1, source2).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableObserveOnTest method observeOnTheSameSchedulerTwice.
@Test
public void observeOnTheSameSchedulerTwice() {
Scheduler scheduler = ImmediateThinScheduler.INSTANCE;
Observable<Integer> o = Observable.just(1, 2, 3);
Observable<Integer> o2 = o.observeOn(scheduler);
Observer<Object> observer1 = TestHelper.mockObserver();
Observer<Object> observer2 = TestHelper.mockObserver();
InOrder inOrder1 = inOrder(observer1);
InOrder inOrder2 = inOrder(observer2);
o2.subscribe(observer1);
o2.subscribe(observer2);
inOrder1.verify(observer1, times(1)).onNext(1);
inOrder1.verify(observer1, times(1)).onNext(2);
inOrder1.verify(observer1, times(1)).onNext(3);
inOrder1.verify(observer1, times(1)).onComplete();
verify(observer1, never()).onError(any(Throwable.class));
inOrder1.verifyNoMoreInteractions();
inOrder2.verify(observer2, times(1)).onNext(1);
inOrder2.verify(observer2, times(1)).onNext(2);
inOrder2.verify(observer2, times(1)).onNext(3);
inOrder2.verify(observer2, times(1)).onComplete();
verify(observer2, never()).onError(any(Throwable.class));
inOrder2.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextTest method functionThrowsError.
/**
* Test that when a function throws an exception this is propagated through onError.
*/
@Test
public void functionThrowsError() {
Subscription s = mock(Subscription.class);
TestObservable w = new TestObservable(s, "one");
Function<Throwable, Observable<String>> resume = new Function<Throwable, Observable<String>>() {
@Override
public Observable<String> apply(Throwable t1) {
throw new RuntimeException("exception from function");
}
};
Observable<String> o = Observable.unsafeCreate(w).onErrorResumeNext(resume);
Observer<String> observer = TestHelper.mockObserver();
o.subscribe(observer);
try {
w.t.join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
// we should get the "one" value before the error
verify(observer, times(1)).onNext("one");
// we should have received an onError call on the Observer since the resume function threw an exception
verify(observer, times(1)).onError(any(Throwable.class));
verify(observer, times(0)).onComplete();
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextTest method resumeNextWithAsyncExecution.
@Test
public void resumeNextWithAsyncExecution() {
final AtomicReference<Throwable> receivedException = new AtomicReference<>();
Subscription s = mock(Subscription.class);
TestObservable w = new TestObservable(s, "one");
Function<Throwable, Observable<String>> resume = new Function<Throwable, Observable<String>>() {
@Override
public Observable<String> apply(Throwable t1) {
receivedException.set(t1);
return Observable.just("twoResume", "threeResume");
}
};
Observable<String> o = Observable.unsafeCreate(w).onErrorResumeNext(resume);
Observer<String> observer = TestHelper.mockObserver();
o.subscribe(observer);
try {
w.t.join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
verify(observer, Mockito.never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
verify(observer, times(1)).onNext("one");
verify(observer, Mockito.never()).onNext("two");
verify(observer, Mockito.never()).onNext("three");
verify(observer, times(1)).onNext("twoResume");
verify(observer, times(1)).onNext("threeResume");
assertNotNull(receivedException.get());
}
use of io.reactivex.rxjava3.core.Observable 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