use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class ObservableCollectWithCollectorTest method collectorAccumulatorDropSignals.
@Test
public void collectorAccumulatorDropSignals() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Observable<Integer> source = new Observable<Integer>() {
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(1);
observer.onNext(2);
observer.onError(new IOException());
observer.onComplete();
}
};
source.collect(new Collector<Integer, Integer, Integer>() {
@Override
public Supplier<Integer> supplier() {
return () -> 1;
}
@Override
public BiConsumer<Integer, Integer> accumulator() {
return (a, b) -> {
throw new TestException();
};
}
@Override
public BinaryOperator<Integer> combiner() {
return (a, b) -> a + b;
}
@Override
public Function<Integer, Integer> finisher() {
return a -> a;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
});
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class FlowableCollectWithCollectorTest method collectorAccumulatorDropSignalsToFlowable.
@Test
public void collectorAccumulatorDropSignalsToFlowable() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Flowable<Integer> source = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
};
source.collect(new Collector<Integer, Integer, Integer>() {
@Override
public Supplier<Integer> supplier() {
return () -> 1;
}
@Override
public BiConsumer<Integer, Integer> accumulator() {
return (a, b) -> {
throw new TestException();
};
}
@Override
public BinaryOperator<Integer> combiner() {
return (a, b) -> a + b;
}
@Override
public Function<Integer, Integer> finisher() {
return a -> a;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
}).toFlowable().test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
});
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class FlowableCollectWithCollectorTest method collectorAccumulatorCrashToFlowable.
@Test
public void collectorAccumulatorCrashToFlowable() {
BehaviorProcessor<Integer> source = BehaviorProcessor.createDefault(1);
source.collect(new Collector<Integer, Integer, Integer>() {
@Override
public Supplier<Integer> supplier() {
return () -> 1;
}
@Override
public BiConsumer<Integer, Integer> accumulator() {
return (a, b) -> {
throw new TestException();
};
}
@Override
public BinaryOperator<Integer> combiner() {
return (a, b) -> a + b;
}
@Override
public Function<Integer, Integer> finisher() {
return a -> a;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
}).toFlowable().test().assertFailure(TestException.class);
assertFalse(source.hasSubscribers());
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class FlowableRetryTest method noCancelPreviousRetryWhile2.
@Test
public void noCancelPreviousRetryWhile2() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Flowable<Integer> source = Flowable.defer(new Supplier<Flowable<Integer>>() {
@Override
public Flowable<Integer> get() throws Exception {
if (times.getAndIncrement() < 4) {
return Flowable.error(new TestException());
}
return Flowable.just(1);
}
}).doOnCancel(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retry(new BiPredicate<Integer, Throwable>() {
@Override
public boolean test(Integer a, Throwable b) throws Exception {
return a < 5;
}
}).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class FlowableRetryTest method noCancelPreviousRepeatWhen.
@Test
public void noCancelPreviousRepeatWhen() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Flowable<Integer> source = Flowable.defer(new Supplier<Flowable<Integer>>() {
@Override
public Flowable<Integer> get() throws Exception {
if (times.get() < 4) {
return Flowable.error(new TestException());
}
return Flowable.just(1);
}
}).doOnCancel(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retryWhen(new Function<Flowable<Throwable>, Flowable<?>>() {
@Override
public Flowable<?> apply(Flowable<Throwable> e) throws Exception {
return e.takeWhile(new Predicate<Object>() {
@Override
public boolean test(Object v) throws Exception {
return times.getAndIncrement() < 4;
}
});
}
}).test().assertResult(1);
assertEquals(0, counter.get());
}
Aggregations