use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class ObservableFlattenIterableTest method failingInnerCancelsSource.
@Test
public void failingInnerCancelsSource() {
final AtomicInteger counter = new AtomicInteger();
Observable.range(1, 5).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer v) throws Exception {
counter.getAndIncrement();
}
}).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
return new Iterable<Integer>() {
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
@Override
public boolean hasNext() {
return true;
}
@Override
public Integer next() {
throw new TestException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
}).test().assertFailure(TestException.class);
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class ObservableGroupByTest method newGroupValueSelectorFails.
@Test
public void newGroupValueSelectorFails() {
TestObserver<Object> to1 = new TestObserver<>();
final TestObserver<Object> to2 = new TestObserver<>();
Observable.just(1).groupBy(Functions.<Integer>identity(), new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Throwable {
throw new TestException();
}
}).doOnNext(new Consumer<GroupedObservable<Integer, Object>>() {
@Override
public void accept(GroupedObservable<Integer, Object> g) throws Throwable {
g.subscribe(to2);
}
}).subscribe(to1);
to1.assertValueCount(1).assertError(TestException.class).assertNotComplete();
to2.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class XFlatMapTest method flowableCompletable.
@Test
public void flowableCompletable() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestObserver<Void> to = Flowable.just(1).subscribeOn(Schedulers.io()).flatMapCompletable(new Function<Integer, Completable>() {
@Override
public Completable apply(Integer v) throws Exception {
sleep();
return Completable.error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(to);
to.dispose();
Thread.sleep(SLEEP_AFTER_CANCEL);
to.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class XFlatMapTest method maybeObservable.
@Test
public void maybeObservable() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestObserver<Integer> to = Maybe.just(1).subscribeOn(Schedulers.io()).flatMapObservable(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer v) throws Exception {
sleep();
return Observable.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(to);
to.dispose();
Thread.sleep(SLEEP_AFTER_CANCEL);
to.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class XFlatMapTest method flowableFlowable.
@Test
public void flowableFlowable() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = Flowable.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
sleep();
return Flowable.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(ts);
ts.cancel();
Thread.sleep(SLEEP_AFTER_CANCEL);
ts.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
Aggregations