use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class FlowableSwitchMapMaybeTest method innerErrorAfterTermination.
@Test
public void innerErrorAfterTermination() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final AtomicReference<MaybeObserver<? super Integer>> moRef = new AtomicReference<>();
TestSubscriberEx<Integer> ts = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onError(new TestException("outer"));
}
}.switchMapMaybe(new Function<Integer, MaybeSource<Integer>>() {
@Override
public MaybeSource<Integer> apply(Integer v) throws Exception {
return new Maybe<Integer>() {
@Override
protected void subscribeActual(MaybeObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
moRef.set(observer);
}
};
}
}).to(TestHelper.<Integer>testConsumer());
ts.assertFailureAndMessage(TestException.class, "outer");
moRef.get().onError(new TestException("inner"));
moRef.get().onComplete();
TestHelper.assertUndeliverable(errors, 0, TestException.class, "inner");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class MaybeSwitchOnNextTest method delaySwitch.
@Test
public void delaySwitch() {
PublishProcessor<Maybe<Integer>> pp = PublishProcessor.create();
TestSubscriber<Integer> ts = Maybe.switchOnNextDelayError(pp).test();
assertTrue(pp.hasSubscribers());
ts.assertEmpty();
MaybeSubject<Integer> ms1 = MaybeSubject.create();
MaybeSubject<Integer> ms2 = MaybeSubject.create();
pp.onNext(ms1);
assertTrue(ms1.hasObservers());
pp.onNext(ms2);
assertFalse(ms1.hasObservers());
assertTrue(ms2.hasObservers());
assertTrue(ms2.hasObservers());
ms2.onError(new TestException());
assertTrue(pp.hasSubscribers());
ts.assertEmpty();
pp.onComplete();
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class MaybeTimeoutTest method fallbackError.
@Test
public void fallbackError() {
PublishProcessor<Integer> pp1 = PublishProcessor.create();
PublishProcessor<Integer> pp2 = PublishProcessor.create();
TestObserver<Integer> to = pp1.singleElement().timeout(pp2.singleElement(), Maybe.<Integer>error(new TestException())).test();
assertTrue(pp1.hasSubscribers());
assertTrue(pp2.hasSubscribers());
pp2.onNext(1);
pp2.onComplete();
assertFalse(pp1.hasSubscribers());
assertFalse(pp2.hasSubscribers());
to.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class MaybeMergeTest method delayErrorWithMaxConcurrencyAsyncError.
@Test
public void delayErrorWithMaxConcurrencyAsyncError() {
final AtomicInteger count = new AtomicInteger();
@SuppressWarnings("unchecked") Maybe<Integer>[] sources = new Maybe[3];
for (int i = 0; i < 3; i++) {
final int j = i + 1;
sources[i] = Maybe.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return count.incrementAndGet() - j;
}
}).subscribeOn(Schedulers.io());
}
sources[1] = Maybe.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
throw new TestException("" + count.incrementAndGet());
}
}).subscribeOn(Schedulers.io());
for (int i = 0; i < 1000; i++) {
count.set(0);
Maybe.mergeDelayError(Flowable.fromArray(sources), 1).to(TestHelper.<Integer>testConsumer()).awaitDone(5, TimeUnit.SECONDS).assertFailureAndMessage(TestException.class, "2", 0, 0);
}
}
use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.
the class MaybeOfTypeTest method error.
@Test
public void error() {
TestObserver<Number> to = Maybe.<Integer>error(new TestException()).ofType(Number.class).test();
// don't make this fluent, target type required!
to.assertFailure(TestException.class);
}
Aggregations