Search in sources :

Example 36 with Worker

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

the class HandlerSchedulerTest method workerScheduleOnceWithNegativeDelayPostsImmediately.

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

Example 37 with Worker

use of io.reactivex.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.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Test(org.junit.Test)

Example 38 with Worker

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

the class HandlerSchedulerTest method workerScheduleOnceWithDelayDisposedDoesNotRun.

@Test
public void workerScheduleOnceWithDelayDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter, 1, MINUTES);
    idleMainLooper(30, SECONDS);
    disposable.dispose();
    idleMainLooper(30, SECONDS);
    runUiThreadTasks();
    assertEquals(0, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Test(org.junit.Test)

Example 39 with Worker

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

the class HandlerSchedulerTest method workerScheduleOnceWithDelayPostsWithDelay.

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

Example 40 with Worker

use of io.reactivex.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.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Test(org.junit.Test)

Aggregations

Worker (io.reactivex.Scheduler.Worker)61 Test (org.junit.Test)40 CountingRunnable (io.reactivex.android.testutil.CountingRunnable)20 Disposable (io.reactivex.disposables.Disposable)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Ignore (org.junit.Ignore)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)3 EmptyDisposable (io.reactivex.internal.disposables.EmptyDisposable)2 Scheduler (io.reactivex.Scheduler)1 ConditionalSubscriber (io.reactivex.internal.fuseable.ConditionalSubscriber)1 SubscribeOnSubscriber (io.reactivex.internal.operators.flowable.FlowableSubscribeOn.SubscribeOnSubscriber)1 SpscArrayQueue (io.reactivex.internal.queue.SpscArrayQueue)1 ComputationScheduler (io.reactivex.internal.schedulers.ComputationScheduler)1 IoScheduler (io.reactivex.internal.schedulers.IoScheduler)1 NewThreadWorker (io.reactivex.internal.schedulers.NewThreadWorker)1 ScheduledWorker (io.reactivex.internal.schedulers.SingleScheduler.ScheduledWorker)1 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)1 TestScheduler (io.reactivex.schedulers.TestScheduler)1 TestSubscriber (io.reactivex.subscribers.TestSubscriber)1