use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableOnErrorResumeNextViaFlowableTest method normalBackpressure.
@Test
public void normalBackpressure() {
TestSubscriber<Integer> ts = TestSubscriber.create(0);
PublishProcessor<Integer> pp = PublishProcessor.create();
pp.onErrorResumeWith(Flowable.range(3, 2)).subscribe(ts);
ts.request(2);
pp.onNext(1);
pp.onNext(2);
pp.onError(new TestException("Forced failure"));
ts.assertValues(1, 2);
ts.assertNoErrors();
ts.assertNotComplete();
ts.request(2);
ts.assertValues(1, 2, 3, 4);
ts.assertNoErrors();
ts.assertComplete();
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableOnErrorReturnTest method normalBackpressure.
@Test
public void normalBackpressure() {
TestSubscriber<Integer> ts = TestSubscriber.create(0);
PublishProcessor<Integer> pp = PublishProcessor.create();
pp.onErrorReturn(new Function<Throwable, Integer>() {
@Override
public Integer apply(Throwable e) {
return 3;
}
}).subscribe(ts);
ts.request(2);
pp.onNext(1);
pp.onNext(2);
pp.onError(new TestException("Forced failure"));
ts.assertValues(1, 2);
ts.assertNoErrors();
ts.assertNotComplete();
ts.request(2);
ts.assertValues(1, 2, 3);
ts.assertNoErrors();
ts.assertComplete();
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableRetryTest method repeatFloodNoSubscriptionError.
@Test
public void repeatFloodNoSubscriptionError() {
List<Throwable> errors = TestHelper.trackPluginErrors();
final TestException error = new TestException();
try {
final PublishProcessor<Integer> source = PublishProcessor.create();
final PublishProcessor<Integer> signaller = PublishProcessor.create();
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestSubscriber<Integer> ts = source.take(1).map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
throw error;
}
}).retryWhen(new Function<Flowable<Throwable>, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Flowable<Throwable> v) throws Exception {
return signaller;
}
}).test();
Runnable r1 = new Runnable() {
@Override
public void run() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
source.onNext(1);
}
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
signaller.offer(1);
}
}
};
TestHelper.race(r1, r2);
ts.cancel();
}
if (!errors.isEmpty()) {
for (Throwable e : errors) {
e.printStackTrace();
}
fail(errors + "");
}
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableRetryTest method shouldDisposeInnerFlowable.
@Test
public void shouldDisposeInnerFlowable() {
final PublishProcessor<Object> processor = PublishProcessor.create();
final Disposable disposable = Flowable.error(new RuntimeException("Leak")).retryWhen(new Function<Flowable<Throwable>, Flowable<Object>>() {
@Override
public Flowable<Object> apply(Flowable<Throwable> errors) throws Exception {
return errors.switchMap(new Function<Throwable, Flowable<Object>>() {
@Override
public Flowable<Object> apply(Throwable ignore) throws Exception {
return processor;
}
});
}
}).subscribe();
assertTrue(processor.hasSubscribers());
disposable.dispose();
assertFalse(processor.hasSubscribers());
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableMergeWithMaybeTest method cancelMainOnOtherError.
@Test
public void cancelMainOnOtherError() {
PublishProcessor<Integer> pp = PublishProcessor.create();
MaybeSubject<Integer> ms = MaybeSubject.create();
TestSubscriber<Integer> ts = pp.mergeWith(ms).test();
assertTrue(pp.hasSubscribers());
assertTrue(ms.hasObservers());
ms.onError(new TestException());
ts.assertFailure(TestException.class);
assertFalse("main has observers!", pp.hasSubscribers());
assertFalse("other has observers", ms.hasObservers());
}
Aggregations