use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class ObservableRepeatTest method noCancelPreviousRepeat.
@Test
public void noCancelPreviousRepeat() {
final AtomicInteger counter = new AtomicInteger();
Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.repeat(5).test().assertResult(1, 1, 1, 1, 1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Action 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);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableSubscriberTest method suppressAfterCompleteEvents.
@Test
public void suppressAfterCompleteEvents() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
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 {
ts.onNext(v);
return true;
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
s.onComplete();
s.onNext(1);
s.onError(new TestException());
s.onComplete();
ts.assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class DisposableTest method fromAction.
@Test
public void fromAction() throws Throwable {
Action action = mock(Action.class);
Disposable d = Disposable.fromAction(action);
assertTrue(d.toString(), d.toString().contains("ActionDisposable(disposed=false, "));
d.dispose();
assertTrue(d.toString(), d.toString().contains("ActionDisposable(disposed=true, "));
d.dispose();
assertTrue(d.toString(), d.toString().contains("ActionDisposable(disposed=true, "));
verify(action, times(1)).run();
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableRetryTest method retryTimesPredicateWithMatchingPredicate.
@Test
public void retryTimesPredicateWithMatchingPredicate() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
Completable.fromAction(new Action() {
@Override
public void run() 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());
}
Aggregations