Search in sources :

Example 46 with Scheduler

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

the class ExecutorSchedulerFairTest method runnableDisposedAsync2.

@Test
public void runnableDisposedAsync2() throws Exception {
    final Scheduler s = Schedulers.from(executor, false, true);
    Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE);
    while (!d.isDisposed()) {
        Thread.sleep(1);
    }
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 47 with Scheduler

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

the class ExecutorSchedulerFairTest method unwrapScheduleDirectTaskAfterDispose.

@Test
public void unwrapScheduleDirectTaskAfterDispose() {
    Scheduler scheduler = getScheduler();
    final CountDownLatch cdl = new CountDownLatch(1);
    Runnable countDownRunnable = new Runnable() {

        @Override
        public void run() {
            cdl.countDown();
        }
    };
    Disposable disposable = scheduler.scheduleDirect(countDownRunnable, 100, TimeUnit.MILLISECONDS);
    SchedulerRunnableIntrospection wrapper = (SchedulerRunnableIntrospection) disposable;
    assertSame(countDownRunnable, wrapper.getWrappedRunnable());
    disposable.dispose();
    assertSame(Functions.EMPTY_RUNNABLE, wrapper.getWrappedRunnable());
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 48 with Scheduler

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

the class ExecutorSchedulerFairTest method cancelledWorkerDoesntRunTasks.

@Test
public void cancelledWorkerDoesntRunTasks() {
    final AtomicInteger calls = new AtomicInteger();
    Runnable task = new Runnable() {

        @Override
        public void run() {
            calls.getAndIncrement();
        }
    };
    TestExecutor exec = new TestExecutor();
    Scheduler custom = Schedulers.from(exec, false, true);
    Worker w = custom.createWorker();
    try {
        w.schedule(task);
        w.schedule(task);
        w.schedule(task);
    } finally {
        w.dispose();
    }
    exec.executeAll();
    assertEquals(0, calls.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 49 with Scheduler

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

the class ExecutorSchedulerTest method runnableDisposedAsync.

@Test
public void runnableDisposedAsync() throws Exception {
    final Scheduler s = Schedulers.from(new Executor() {

        @Override
        public void execute(Runnable r) {
            new Thread(r).start();
        }
    });
    Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE);
    while (!d.isDisposed()) {
        Thread.sleep(1);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Scheduler(io.reactivex.rxjava3.core.Scheduler) Test(org.junit.Test)

Example 50 with Scheduler

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

the class ExecutorSchedulerTest method cancelledWorkerDoesntRunTasks.

@Test
public void cancelledWorkerDoesntRunTasks() {
    final AtomicInteger calls = new AtomicInteger();
    Runnable task = new Runnable() {

        @Override
        public void run() {
            calls.getAndIncrement();
        }
    };
    TestExecutor exec = new TestExecutor();
    Scheduler custom = Schedulers.from(exec);
    Worker w = custom.createWorker();
    try {
        w.schedule(task);
        w.schedule(task);
        w.schedule(task);
    } finally {
        w.dispose();
    }
    exec.executeAll();
    assertEquals(0, calls.get());
}
Also used : Scheduler(io.reactivex.rxjava3.core.Scheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) 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