Search in sources :

Example 11 with Disposable

use of io.reactivex.disposables.Disposable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directScheduleOnceWithDelayDisposedDoesNotRun.

@Test
public void directScheduleOnceWithDelayDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.scheduleDirect(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) Test(org.junit.Test)

Example 12 with Disposable

use of io.reactivex.disposables.Disposable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerSchedulePeriodicallyDisposedDoesNotRun.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = 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());
    disposable.dispose();
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with Disposable

use of io.reactivex.disposables.Disposable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directSchedulePeriodicallyDisposedDoesNotRun.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.schedulePeriodicallyDirect(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());
    disposable.dispose();
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with Disposable

use of io.reactivex.disposables.Disposable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerScheduleOnceDisposedDoesNotRun.

@Test
public void workerScheduleOnceDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter);
    disposable.dispose();
    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 15 with Disposable

use of io.reactivex.disposables.Disposable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directSchedulePeriodicallyDisposedDuringRunDoesNotReschedule.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyDisposedDuringRunDoesNotReschedule() {
    final AtomicReference<Disposable> disposableRef = new AtomicReference<>();
    CountingRunnable counter = new CountingRunnable() {

        @Override
        public void run() {
            super.run();
            if (get() == 2) {
                disposableRef.get().dispose();
            }
        }
    };
    Disposable disposable = scheduler.schedulePeriodicallyDirect(counter, 1, 1, MINUTES);
    disposableRef.set(disposable);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    // Dispose will have happened here during the last run() execution.
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.disposables.Disposable)199 Test (org.junit.Test)95 Logger (chat.rocket.android.helper.Logger)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)17 Worker (io.reactivex.Scheduler.Worker)15 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)13 CountingRunnable (io.reactivex.android.testutil.CountingRunnable)10 EmptyDisposable (io.reactivex.internal.disposables.EmptyDisposable)10 TestSubscriber (io.reactivex.subscribers.TestSubscriber)10 Optional (com.fernandocejas.arrow.optional.Optional)9 Single (io.reactivex.Single)9 Nullable (android.support.annotation.Nullable)8 Function (io.reactivex.functions.Function)8 Bundle (android.os.Bundle)7 Pair (android.support.v4.util.Pair)7 ANError (com.androidnetworking.error.ANError)7 AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)7 List (java.util.List)7 NonNull (android.support.annotation.NonNull)6