use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.
the class SingleFlatMapTest method flatMapPublisherCancelDuringFlowable.
@Test
public void flatMapPublisherCancelDuringFlowable() {
final AtomicBoolean disposed = new AtomicBoolean();
TestSubscriberEx<Integer> ts = Single.just(1).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
return Flowable.<Integer>never().doOnCancel(new Action() {
@Override
public void run() throws Exception {
disposed.set(true);
}
});
}
}).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
assertFalse(disposed.get());
ts.cancel();
assertTrue(disposed.get());
ts.assertNotTerminated();
}
use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.
the class ObservableReplayEagerTruncateTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Observable<Integer>() {
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onError(new TestException("First"));
observer.onNext(1);
observer.onError(new TestException("Second"));
observer.onComplete();
}
}.replay().autoConnect().to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.testsupport.TestHelper 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.testsupport.TestHelper in project RxJava by ReactiveX.
the class FlowableSwitchMapSingleTest method innerErrorAfterTermination.
@Test
public void innerErrorAfterTermination() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final AtomicReference<SingleObserver<? 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"));
}
}.switchMapSingle(new Function<Integer, SingleSource<Integer>>() {
@Override
public SingleSource<Integer> apply(Integer v) throws Exception {
return new Single<Integer>() {
@Override
protected void subscribeActual(SingleObserver<? 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"));
TestHelper.assertUndeliverable(errors, 0, TestException.class, "inner");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.testsupport.TestHelper 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);
}
}
Aggregations