use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class FlowableMapTest method mapFilterMapperCrashFused.
@Test
public void mapFilterMapperCrashFused() {
TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>().setInitialFusionMode(QueueFuseable.ANY);
Flowable.range(1, 2).hide().map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
throw new TestException();
}
}).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
return true;
}
}).subscribe(ts);
ts.assertFuseable().assertFusionMode(QueueFuseable.NONE).assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class FlowableMapTest method sourceIgnoresCancel.
@Test
public void sourceIgnoresCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
}).map(new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class FlowableOnErrorResumeNextViaFunctionTest method resumeNextWithAsyncExecution.
@Test
public void resumeNextWithAsyncExecution() {
final AtomicReference<Throwable> receivedException = new AtomicReference<>();
Subscription s = mock(Subscription.class);
TestFlowable w = new TestFlowable(s, "one");
Function<Throwable, Flowable<String>> resume = new Function<Throwable, Flowable<String>>() {
@Override
public Flowable<String> apply(Throwable t1) {
receivedException.set(t1);
return Flowable.just("twoResume", "threeResume");
}
};
Flowable<String> flowable = Flowable.unsafeCreate(w).onErrorResumeNext(resume);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
flowable.subscribe(subscriber);
try {
w.t.join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
verify(subscriber, Mockito.never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
verify(subscriber, times(1)).onNext("one");
verify(subscriber, Mockito.never()).onNext("two");
verify(subscriber, Mockito.never()).onNext("three");
verify(subscriber, times(1)).onNext("twoResume");
verify(subscriber, times(1)).onNext("threeResume");
assertNotNull(receivedException.get());
}
use of io.reactivex.rxjava3.functions.Function 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.functions.Function 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());
}
Aggregations