use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableSubscriberTest method onErrorThrows.
@Test
public void onErrorThrows() {
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
return true;
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
throw new TestException("Inner");
}
}, new Action() {
@Override
public void run() throws Exception {
}
});
List<Throwable> list = TestHelper.trackPluginErrors();
try {
s.onSubscribe(new BooleanSubscription());
s.onError(new TestException("Outer"));
TestHelper.assertError(list, 0, CompositeException.class);
List<Throwable> cel = TestHelper.compositeList(list.get(0));
TestHelper.assertError(cel, 0, TestException.class, "Outer");
TestHelper.assertError(cel, 1, TestException.class, "Inner");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableSubscriberTest method onCompleteThrows.
@Test
public void onCompleteThrows() {
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
return true;
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
}
}, new Action() {
@Override
public void run() throws Exception {
throw new TestException("Inner");
}
});
List<Throwable> list = TestHelper.trackPluginErrors();
try {
s.onSubscribe(new BooleanSubscription());
s.onComplete();
TestHelper.assertUndeliverable(list, 0, TestException.class, "Inner");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate 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());
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableFilterTest method sourceIgnoresCancelConditional.
@Test
public void sourceIgnoresCancelConditional() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
ConditionalSubscriber<? super Integer> cs = (ConditionalSubscriber<? super Integer>) s;
cs.onSubscribe(new BooleanSubscription());
cs.tryOnNext(1);
cs.tryOnNext(2);
cs.onError(new IOException());
cs.onComplete();
}
}).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
return true;
}
}).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableRepeatTest method noCancelPreviousRepeatWhen.
@Test
public void noCancelPreviousRepeatWhen() {
final AtomicInteger counter = new AtomicInteger();
Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
final AtomicInteger times = new AtomicInteger();
source.repeatWhen(new Function<Observable<Object>, ObservableSource<?>>() {
@Override
public ObservableSource<?> apply(Observable<Object> e) throws Exception {
return e.takeWhile(new Predicate<Object>() {
@Override
public boolean test(Object v) throws Exception {
return times.getAndIncrement() < 4;
}
});
}
}).test().assertResult(1, 1, 1, 1, 1);
assertEquals(0, counter.get());
}
Aggregations