use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableIgnoreElementsTest method doesNotHangAndProcessesAllUsingBackpressure.
@Test
public void doesNotHangAndProcessesAllUsingBackpressure() {
final AtomicInteger upstreamCount = new AtomicInteger();
final AtomicInteger count = new AtomicInteger(0);
int num = 10;
Flowable.range(1, num).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t) {
upstreamCount.incrementAndGet();
}
}).ignoreElements().subscribe(new DisposableCompletableObserver() {
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
assertEquals(num, upstreamCount.get());
assertEquals(0, count.get());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class ObservableReplayEagerTruncateTest method connectConsumerThrows.
@Test
public void connectConsumerThrows() {
ConnectableObservable<Integer> co = Observable.range(1, 2).replay();
try {
co.connect(new Consumer<Disposable>() {
@Override
public void accept(Disposable t) throws Exception {
throw new TestException();
}
});
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
co.test().assertEmpty().dispose();
co.connect();
co.test().assertResult(1, 2);
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class ObservableFlattenIterableTest method failingInnerCancelsSource.
@Test
public void failingInnerCancelsSource() {
final AtomicInteger counter = new AtomicInteger();
Observable.range(1, 5).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer v) throws Exception {
counter.getAndIncrement();
}
}).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
return new Iterable<Integer>() {
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
@Override
public boolean hasNext() {
return true;
}
@Override
public Integer next() {
throw new TestException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
}).test().assertFailure(TestException.class);
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class ObservableGroupByTest method newGroupValueSelectorFails.
@Test
public void newGroupValueSelectorFails() {
TestObserver<Object> to1 = new TestObserver<>();
final TestObserver<Object> to2 = new TestObserver<>();
Observable.just(1).groupBy(Functions.<Integer>identity(), new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Throwable {
throw new TestException();
}
}).doOnNext(new Consumer<GroupedObservable<Integer, Object>>() {
@Override
public void accept(GroupedObservable<Integer, Object> g) throws Throwable {
g.subscribe(to2);
}
}).subscribe(to1);
to1.assertValueCount(1).assertError(TestException.class).assertNotComplete();
to2.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableSubscriberTest method onNextCrashes.
@Test
public void onNextCrashes() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
ts.onSubscribe(new BooleanSubscription());
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
BooleanSubscription b = new BooleanSubscription();
s.onSubscribe(b);
s.onNext(1);
assertTrue(b.isCancelled());
ts.assertFailure(TestException.class);
}
Aggregations