Search in sources :

Example 1 with Scheduler

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

the class RxAndroidPluginsTest method resetClearsMainThreadHandler.

@Test
public void resetClearsMainThreadHandler() {
    RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {

        @Override
        public Scheduler apply(Scheduler scheduler) {
            throw new AssertionError();
        }
    });
    RxAndroidPlugins.reset();
    Scheduler scheduler = new EmptyScheduler();
    Scheduler actual = RxAndroidPlugins.onMainThreadScheduler(scheduler);
    assertSame(scheduler, actual);
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Test(org.junit.Test)

Example 2 with Scheduler

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

the class RxAndroidPluginsTest method initMainThreadHandlerCalled.

@Test
public void initMainThreadHandlerCalled() {
    final AtomicReference<Callable<Scheduler>> schedulerRef = new AtomicReference<>();
    final Scheduler newScheduler = new EmptyScheduler();
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() {

        @Override
        public Scheduler apply(Callable<Scheduler> scheduler) {
            schedulerRef.set(scheduler);
            return newScheduler;
        }
    });
    Callable<Scheduler> scheduler = new Callable<Scheduler>() {

        @Override
        public Scheduler call() throws Exception {
            throw new AssertionError();
        }
    };
    Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(scheduler);
    assertSame(newScheduler, actual);
    assertSame(scheduler, schedulerRef.get());
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 3 with Scheduler

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

the class RxAndroidPluginsTest method resetClearsInitMainThreadHandler.

@Test
public void resetClearsInitMainThreadHandler() throws Exception {
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() {

        @Override
        public Scheduler apply(Callable<Scheduler> scheduler) {
            throw new AssertionError();
        }
    });
    final Scheduler scheduler = new EmptyScheduler();
    Callable<Scheduler> schedulerCallable = new Callable<Scheduler>() {

        @Override
        public Scheduler call() throws Exception {
            return scheduler;
        }
    };
    RxAndroidPlugins.reset();
    Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(schedulerCallable);
    assertSame(schedulerCallable.call(), actual);
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 4 with Scheduler

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

the class AndroidSchedulersTest method asyncIgnoredPre16.

@Test
public void asyncIgnoredPre16() {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 14);
    ShadowLooper mainLooper = shadowOf(Looper.getMainLooper());
    mainLooper.pause();
    ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
    Scheduler main = AndroidSchedulers.from(Looper.getMainLooper(), true);
    main.scheduleDirect(new Runnable() {

        @Override
        public void run() {
        }
    });
    Message message = mainMessageQueue.getHead();
    assertFalse(message.isAsynchronous());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue) Message(android.os.Message) Build(android.os.Build) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) ShadowLooper(org.robolectric.shadows.ShadowLooper) Test(org.junit.Test)

Example 5 with Scheduler

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

the class AndroidSchedulersTest method fromAsyncMessagesByDefault.

@Test
public void fromAsyncMessagesByDefault() {
    ShadowLooper mainLooper = shadowOf(Looper.getMainLooper());
    mainLooper.pause();
    ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
    Scheduler main = AndroidSchedulers.from(Looper.getMainLooper());
    main.scheduleDirect(new Runnable() {

        @Override
        public void run() {
        }
    });
    Message message = mainMessageQueue.getHead();
    assertTrue(message.isAsynchronous());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue) Message(android.os.Message) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) ShadowLooper(org.robolectric.shadows.ShadowLooper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)169 Disposable (io.reactivex.rxjava3.disposables.Disposable)69 Scheduler (io.reactivex.rxjava3.core.Scheduler)61 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)54 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)50 TestException (io.reactivex.rxjava3.exceptions.TestException)34 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)32 InOrder (org.mockito.InOrder)32 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)20 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 EmptyScheduler (io.reactivex.rxjava3.android.testutil.EmptyScheduler)8 Observable (io.reactivex.rxjava3.core.Observable)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)6 Action (io.reactivex.rxjava3.functions.Action)5 SuppressUndeliverable (io.reactivex.rxjava3.testsupport.SuppressUndeliverable)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5