use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableRepeatTest method noCancelPreviousRepeatWhen.
@Test
public void noCancelPreviousRepeatWhen() {
final AtomicInteger counter = new AtomicInteger();
Flowable<Integer> source = Flowable.just(1).doOnCancel(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
final AtomicInteger times = new AtomicInteger();
source.repeatWhen(new Function<Flowable<Object>, Flowable<?>>() {
@Override
public Flowable<?> apply(Flowable<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());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableTimeoutTest method timeoutContinueOther.
@Test
public void timeoutContinueOther() throws Exception {
final int[] call = { 0 };
Completable other = Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
call[0]++;
}
});
Completable.never().timeout(100, TimeUnit.MILLISECONDS, Schedulers.io(), other).test().awaitDone(5, TimeUnit.SECONDS).assertResult();
assertEquals(1, call[0]);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableBlockingSubscribeTest method twoArgErrorFails.
@Test
public void twoArgErrorFails() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Action action = mock(Action.class);
@SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
doThrow(new TestException()).when(consumer).accept(any());
Completable.error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation(), true).blockingSubscribe(action, consumer);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
verify(action, never()).run();
verify(consumer).accept(any(TestException.class));
});
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableBlockingSubscribeTest method oneArgCompleteFails.
@Test
public void oneArgCompleteFails() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Action action = mock(Action.class);
doThrow(new TestException()).when(action).run();
Completable.complete().blockingSubscribe(action);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
verify(action).run();
});
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableBlockingSubscribeTest method twoArgErrorAsync.
@Test
public void twoArgErrorAsync() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Action action = mock(Action.class);
@SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
Completable.error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation(), true).blockingSubscribe(action, consumer);
assertTrue("" + errors, errors.isEmpty());
verify(action, never()).run();
verify(consumer).accept(any(TestException.class));
});
}
Aggregations