Search in sources :

Example 66 with Disposable

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

the class ResourceSingleObserverTest method onErrorCleansUp.

@Test
public void onErrorCleansUp() {
    TestResourceSingleObserver<Integer> rso = new TestResourceSingleObserver<Integer>();
    assertFalse(rso.isDisposed());
    Disposable d = Disposables.empty();
    rso.add(d);
    assertFalse(d.isDisposed());
    rso.onError(new TestException());
    assertTrue(rso.isDisposed());
    assertTrue(d.isDisposed());
}
Also used : Disposable(io.reactivex.disposables.Disposable) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 67 with Disposable

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

the class ResourceCompletableObserverTest method dispose.

@Test
public void dispose() {
    TestResourceCompletableObserver rco = new TestResourceCompletableObserver();
    rco.dispose();
    Disposable d = Disposables.empty();
    rco.onSubscribe(d);
    assertTrue(d.isDisposed());
    assertEquals(0, rco.start);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 68 with Disposable

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

the class ResourceCompletableObserverTest method startOnce.

@Test
public void startOnce() {
    List<Throwable> error = TestHelper.trackPluginErrors();
    try {
        TestResourceCompletableObserver rco = new TestResourceCompletableObserver();
        rco.onSubscribe(Disposables.empty());
        Disposable d = Disposables.empty();
        rco.onSubscribe(d);
        assertTrue(d.isDisposed());
        assertEquals(1, rco.start);
        TestHelper.assertError(error, 0, IllegalStateException.class, "Disposable already set!");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 69 with Disposable

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

the class SchedulerTest method defaultPeriodicTask.

@Test
public void defaultPeriodicTask() {
    final int[] count = { 0 };
    TestScheduler scheduler = new TestScheduler();
    Disposable d = scheduler.schedulePeriodicallyDirect(new Runnable() {

        @Override
        public void run() {
            count[0]++;
        }
    }, 100, 100, TimeUnit.MILLISECONDS);
    assertEquals(0, count[0]);
    assertFalse(d.isDisposed());
    scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
    assertEquals(2, count[0]);
    d.dispose();
    assertTrue(d.isDisposed());
    scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
    assertEquals(2, count[0]);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 70 with Disposable

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

the class SchedulerTest method periodicDirectTaskRaceIO.

@Test
public void periodicDirectTaskRaceIO() throws Exception {
    final Scheduler scheduler = Schedulers.io();
    for (int i = 0; i < 100; i++) {
        final Disposable d = scheduler.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 0, 0, TimeUnit.MILLISECONDS);
        Thread.sleep(1);
        d.dispose();
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.disposables.Disposable)224 Test (org.junit.Test)95 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)31 Logger (chat.rocket.android.helper.Logger)19 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 Worker (io.reactivex.Scheduler.Worker)15 List (java.util.List)14 Single (io.reactivex.Single)13 Function (io.reactivex.functions.Function)13 NonNull (io.reactivex.annotations.NonNull)12 Nullable (android.support.annotation.Nullable)11 Bundle (android.os.Bundle)10 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 Schedulers (io.reactivex.schedulers.Schedulers)9 TimeUnit (java.util.concurrent.TimeUnit)8 NonNull (android.support.annotation.NonNull)7