Search in sources :

Example 1 with CompositeDisposable

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

the class ScheduledRunnableTest method crashReported.

@Test
public void crashReported() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        CompositeDisposable set = new CompositeDisposable();
        final ScheduledRunnable run = new ScheduledRunnable(new Runnable() {

            @Override
            public void run() {
                throw new TestException("First");
            }
        }, set);
        set.add(run);
        run.run();
        assertTrue(run.isDisposed());
        assertEquals(0, set.size());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Test(org.junit.Test)

Example 2 with CompositeDisposable

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

the class ScheduledRunnableTest method disposeRun.

@Test
public void disposeRun() {
    CompositeDisposable set = new CompositeDisposable();
    ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
    set.add(run);
    assertFalse(run.isDisposed());
    run.dispose();
    run.dispose();
    assertTrue(run.isDisposed());
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Test(org.junit.Test)

Example 3 with CompositeDisposable

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

the class ScheduledRunnableTest method pluginCrash.

@Test
public void pluginCrash() {
    Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            throw new TestException("Second");
        }
    });
    CompositeDisposable set = new CompositeDisposable();
    final ScheduledRunnable run = new ScheduledRunnable(new Runnable() {

        @Override
        public void run() {
            throw new TestException("First");
        }
    }, set);
    set.add(run);
    try {
        run.run();
        fail("Should have thrown!");
    } catch (TestException ex) {
        assertEquals("Second", ex.getMessage());
    } finally {
        Thread.currentThread().setUncaughtExceptionHandler(null);
    }
    assertTrue(run.isDisposed());
    assertEquals(0, set.size());
}
Also used : TestException(io.reactivex.exceptions.TestException) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Test(org.junit.Test)

Example 4 with CompositeDisposable

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

the class ScheduledRunnableTest method setFutureRunRace.

@Test
public void setFutureRunRace() {
    for (int i = 0; i < 500; i++) {
        CompositeDisposable set = new CompositeDisposable();
        final ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
        set.add(run);
        final FutureTask<Object> ft = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, 0);
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                run.setFuture(ft);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                run.run();
            }
        };
        TestHelper.race(r1, r2);
        assertEquals(0, set.size());
    }
}
Also used : FutureTask(java.util.concurrent.FutureTask) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Test(org.junit.Test)

Example 5 with CompositeDisposable

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

the class ScheduledRunnableTest method disposeRace.

@Test
public void disposeRace() {
    for (int i = 0; i < 500; i++) {
        CompositeDisposable set = new CompositeDisposable();
        final ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
        set.add(run);
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                run.dispose();
            }
        };
        TestHelper.race(r1, r1);
        assertEquals(0, set.size());
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Test(org.junit.Test)

Aggregations

CompositeDisposable (io.reactivex.disposables.CompositeDisposable)78 Nullable (android.support.annotation.Nullable)15 Test (org.junit.Test)11 Bundle (android.os.Bundle)10 View (android.view.View)10 Consumer (io.reactivex.functions.Consumer)10 TimeUnit (java.util.concurrent.TimeUnit)10 Flowable (io.reactivex.Flowable)9 NonNull (android.support.annotation.NonNull)8 TextUtils (android.text.TextUtils)7 ViewGroup (android.view.ViewGroup)7 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)7 TextView (android.widget.TextView)6 BindView (butterknife.BindView)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Intent (android.content.Intent)5 LayoutInflater (android.view.LayoutInflater)5 Task (bolts.Task)5 TaskCompletionSource (bolts.TaskCompletionSource)5