Search in sources :

Example 36 with Action

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());
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 37 with Action

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();
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 38 with Action

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());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 39 with Action

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());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 40 with Action

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action(io.reactivex.rxjava3.functions.Action) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)109 TestException (io.reactivex.rxjava3.exceptions.TestException)64 Action (io.reactivex.rxjava3.functions.Action)49 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)13 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 TestObserver (io.reactivex.rxjava3.observers.TestObserver)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)9 IOException (java.io.IOException)9 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 Observable (io.reactivex.rxjava3.core.Observable)4 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)4 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)3 Flowable (io.reactivex.rxjava3.core.Flowable)3 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)3 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3