use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableRetryBiPredicate method subscribeActual.
@Override
public void subscribeActual(Subscriber<? super T> s) {
SubscriptionArbiter sa = new SubscriptionArbiter(false);
s.onSubscribe(sa);
RetryBiSubscriber<T> rs = new RetryBiSubscriber<>(s, predicate, sa, source);
rs.subscribeNext();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class SingleRetryTest method retryTimesPredicateWithMatchingPredicate.
@Test
public void retryTimesPredicateWithMatchingPredicate() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
Single.fromCallable(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}
throw new IllegalArgumentException();
}
}).retry(Integer.MAX_VALUE, new Predicate<Throwable>() {
@Override
public boolean test(final Throwable throwable) throws Exception {
return !(throwable instanceof IllegalArgumentException);
}
}).test().assertFailure(IllegalArgumentException.class);
assertEquals(3, numberOfSubscribeCalls.get());
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableFirstTest method firstOrDefaultWithPredicateAndEmpty.
@Test
public void firstOrDefaultWithPredicateAndEmpty() {
Single<Integer> o = Observable.just(1).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).first(2);
o.subscribe(wo);
InOrder inOrder = inOrder(wo);
inOrder.verify(wo, times(1)).onSuccess(2);
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableFirstTest method firstWithPredicateAndOneElement.
@Test
public void firstWithPredicateAndOneElement() {
Maybe<Integer> o = Observable.just(1, 2).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).firstElement();
o.subscribe(wm);
InOrder inOrder = inOrder(wm);
inOrder.verify(wm, times(1)).onSuccess(2);
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableFirstTest method firstOrDefaultWithPredicate.
@Test
public void firstOrDefaultWithPredicate() {
Single<Integer> o = Observable.just(1, 2, 3, 4, 5, 6).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).first(8);
o.subscribe(wo);
InOrder inOrder = inOrder(wo);
inOrder.verify(wo, times(1)).onSuccess(2);
inOrder.verifyNoMoreInteractions();
}
Aggregations