use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableBlockingSubscribeTest method twoArgCompleteFails.
@Test
public void twoArgCompleteFails() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Action action = mock(Action.class);
doThrow(new TestException()).when(action).run();
@SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
Completable.complete().blockingSubscribe(action, consumer);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
verify(action).run();
verify(consumer, never()).accept(any());
});
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableConcatArrayDelayErrorTest method normal.
@Test
public void normal() throws Throwable {
Action action1 = mock(Action.class);
Action action2 = mock(Action.class);
Completable.concatArrayDelayError(Completable.fromAction(action1), Completable.error(new TestException()), Completable.fromAction(action2)).test().assertFailure(TestException.class);
verify(action1).run();
verify(action2).run();
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableDelaySubscriptionTest method timestep.
@Test
public void timestep() {
TestScheduler scheduler = new TestScheduler();
final AtomicInteger counter = new AtomicInteger();
Completable result = Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
counter.incrementAndGet();
}
}).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
TestObserver<Void> to = result.test();
scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
to.assertEmpty();
scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
to.assertResult();
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableDelaySubscriptionTest method normal.
@Test
public void normal() {
final AtomicInteger counter = new AtomicInteger();
Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
counter.incrementAndGet();
}
}).delaySubscription(100, TimeUnit.MILLISECONDS).test().awaitDone(5, TimeUnit.SECONDS).assertResult();
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableTimerTest method timerInterruptible.
@Test
public void timerInterruptible() throws Exception {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
try {
for (Scheduler s : new Scheduler[] { Schedulers.single(), Schedulers.computation(), Schedulers.newThread(), Schedulers.io(), Schedulers.from(exec, true) }) {
final AtomicBoolean interrupted = new AtomicBoolean();
TestObserver<Void> to = Completable.timer(1, TimeUnit.MILLISECONDS, s).doOnComplete(new Action() {
@Override
public void run() throws Exception {
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
interrupted.set(true);
}
}
}).test();
Thread.sleep(500);
to.dispose();
Thread.sleep(500);
assertTrue(s.getClass().getSimpleName(), interrupted.get());
}
} finally {
exec.shutdown();
}
}
Aggregations