Search in sources :

Example 91 with Worker

use of io.reactivex.rxjava3.core.Scheduler.Worker in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerScheduleOncePostsImmediately.

@Test
public void workerScheduleOncePostsImmediately() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter);
    runUiThreadTasks();
    assertEquals(1, counter.get());
}
Also used : CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 92 with Worker

use of io.reactivex.rxjava3.core.Scheduler.Worker in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerDisposableTracksDisposedState.

@Test
public void workerDisposableTracksDisposedState() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter);
    assertFalse(disposable.isDisposed());
    disposable.dispose();
    assertTrue(disposable.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 93 with Worker

use of io.reactivex.rxjava3.core.Scheduler.Worker in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerSchedulePeriodicallyThrowingDoesNotReschedule.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyThrowingDoesNotReschedule() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable() {

        @Override
        public void run() {
            super.run();
            if (get() == 2) {
                throw new RuntimeException("Broken!");
            }
        }
    };
    worker.schedulePeriodically(counter, 1, 1, MINUTES);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    // Exception will have happened here during the last run() execution.
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 94 with Worker

use of io.reactivex.rxjava3.core.Scheduler.Worker in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerSchedulePeriodicallyReschedulesItself.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyReschedulesItself() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    worker.schedulePeriodically(counter, 1, 1, MINUTES);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(3, counter.get());
}
Also used : CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 95 with Worker

use of io.reactivex.rxjava3.core.Scheduler.Worker in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerSchedulePeriodicallySetAsync.

@Test
public void workerSchedulePeriodicallySetAsync() {
    ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
    Worker worker = scheduler.createWorker();
    worker.schedulePeriodically(new Runnable() {

        @Override
        public void run() {
        }
    }, 1, 1, MINUTES);
    Message message = mainMessageQueue.getHead();
    assertEquals(async, message.isAsynchronous());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue) Message(android.os.Message) CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Aggregations

Worker (io.reactivex.rxjava3.core.Scheduler.Worker)91 Test (org.junit.Test)87 Disposable (io.reactivex.rxjava3.disposables.Disposable)28 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)22 Scheduler (io.reactivex.rxjava3.core.Scheduler)18 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Ignore (org.junit.Ignore)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)4 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)4 SuppressUndeliverable (io.reactivex.rxjava3.testsupport.SuppressUndeliverable)4 IoScheduler (io.reactivex.rxjava3.internal.schedulers.IoScheduler)3 WorkerCallback (io.reactivex.rxjava3.internal.schedulers.SchedulerMultiWorkerSupport.WorkerCallback)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ThrowingRunnable (org.junit.function.ThrowingRunnable)3 Message (android.os.Message)2 CompositeDisposable (io.reactivex.rxjava3.disposables.CompositeDisposable)2 TestException (io.reactivex.rxjava3.exceptions.TestException)2 NewThreadWorker (io.reactivex.rxjava3.internal.schedulers.NewThreadWorker)2