use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableFlatMapStreamTest method mapperThrowsWhenUpstreamErrors.
@Test
public void mapperThrowsWhenUpstreamErrors() throws Throwable {
TestHelper.withErrorTracking(errors -> {
PublishProcessor<Integer> pp = PublishProcessor.create();
AtomicInteger counter = new AtomicInteger();
TestSubscriber<Integer> ts = pp.hide().concatMapStream(v -> {
if (counter.getAndIncrement() == 0) {
return Stream.of(1, 2);
}
pp.onError(new IOException());
throw new TestException();
}).test();
pp.onNext(1);
pp.onNext(2);
ts.assertFailure(IOException.class, 1, 2);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
});
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableFlatMapStreamTest method upstreamCancelled.
@Test
public void upstreamCancelled() {
PublishProcessor<Integer> pp = PublishProcessor.create();
AtomicInteger calls = new AtomicInteger();
TestSubscriber<Integer> ts = pp.flatMapStream(v -> Stream.of(v + 1, v + 2).onClose(() -> calls.getAndIncrement())).test(1);
assertTrue(pp.hasSubscribers());
pp.onNext(1);
ts.assertValuesOnly(2);
ts.cancel();
assertFalse(pp.hasSubscribers());
assertEquals(1, calls.get());
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableZipIterableTest method zipIterableNextThrows.
@Test
public void zipIterableNextThrows() {
PublishProcessor<String> r1 = PublishProcessor.create();
/* define a Subscriber to receive aggregated events */
Subscriber<String> subscriber = TestHelper.mockSubscriber();
InOrder io = inOrder(subscriber);
Iterable<String> r2 = new Iterable<String>() {
@Override
public Iterator<String> iterator() {
return new Iterator<String>() {
@Override
public boolean hasNext() {
return true;
}
@Override
public String next() {
throw new TestException();
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
};
r1.zipWith(r2, zipr2).subscribe(subscriber);
r1.onError(new TestException());
io.verify(subscriber).onError(any(TestException.class));
verify(subscriber, never()).onNext(any(String.class));
verify(subscriber, never()).onComplete();
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class MaybeAmbTest method innerErrorRace.
@Test
public void innerErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp0 = PublishProcessor.create();
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final TestObserver<Integer> to = Maybe.amb(Arrays.asList(pp0.singleElement(), pp1.singleElement())).test();
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
pp0.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
pp1.onError(ex);
}
};
TestHelper.race(r1, r2);
to.assertFailure(TestException.class);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class MaybeCacheTest method crossCancelOnError.
@Test
public void crossCancelOnError() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
PublishProcessor<Integer> pp = PublishProcessor.create();
Maybe<Integer> source = pp.singleElement().cache();
source.subscribe(Functions.emptyConsumer(), new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
ts.cancel();
}
});
source.toFlowable().subscribe(ts);
pp.onError(new TestException());
ts.assertEmpty();
}
Aggregations