use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class MaybeFlattenStreamAsFlowableTest method requestOneByOne.
@Test
public void requestOneByOne() {
TestSubscriber<Integer> ts = new TestSubscriber<>();
Maybe.just(1).flattenStreamAsFlowable(v -> Stream.of(1, 2, 3, 4, 5)).subscribe(new FlowableSubscriber<Integer>() {
Subscription upstream;
@Override
public void onSubscribe(@NonNull Subscription s) {
ts.onSubscribe(new BooleanSubscription());
upstream = s;
s.request(1);
}
@Override
public void onNext(Integer t) {
ts.onNext(t);
upstream.request(1);
}
@Override
public void onError(Throwable t) {
ts.onError(t);
}
@Override
public void onComplete() {
ts.onComplete();
}
});
ts.assertResult(1, 2, 3, 4, 5);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class SingleFlattenStreamAsFlowableTest method requestOneByOne.
@Test
public void requestOneByOne() {
TestSubscriber<Integer> ts = new TestSubscriber<>();
Single.just(1).flattenStreamAsFlowable(v -> Stream.of(1, 2, 3, 4, 5)).subscribe(new FlowableSubscriber<Integer>() {
Subscription upstream;
@Override
public void onSubscribe(@NonNull Subscription s) {
ts.onSubscribe(new BooleanSubscription());
upstream = s;
s.request(1);
}
@Override
public void onNext(Integer t) {
ts.onNext(t);
upstream.request(1);
}
@Override
public void onError(Throwable t) {
ts.onError(t);
}
@Override
public void onComplete() {
ts.onComplete();
}
});
ts.assertResult(1, 2, 3, 4, 5);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber 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.subscribers.TestSubscriber 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.subscribers.TestSubscriber 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