Search in sources :

Example 51 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable 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 52 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable 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 53 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable 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 54 with Disposable

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

the class ExecutorSchedulerTest method runnableDisposedAsyncCrash.

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

        @Override
        public void execute(Runnable r) {
            new Thread(r).start();
        }
    });
    Disposable d = s.scheduleDirect(new Runnable() {

        @Override
        public void run() {
            throw new IllegalStateException();
        }
    });
    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 55 with Disposable

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

the class ExecutorSchedulerTest method reuseScheduledExecutorAsWorker.

@Test
public void reuseScheduledExecutorAsWorker() throws Exception {
    ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
    Worker s = Schedulers.from(exec).createWorker();
    assertFalse(s.isDisposed());
    try {
        final CountDownLatch cdl = new CountDownLatch(8);
        Runnable r = new Runnable() {

            @Override
            public void run() {
                cdl.countDown();
            }
        };
        s.schedule(r);
        s.schedule(r, 10, TimeUnit.MILLISECONDS);
        Disposable d = s.schedulePeriodically(r, 10, 10, TimeUnit.MILLISECONDS);
        try {
            assertTrue(cdl.await(5, TimeUnit.SECONDS));
        } finally {
            d.dispose();
        }
    } finally {
        s.dispose();
        exec.shutdown();
    }
    assertTrue(s.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)250 Disposable (io.reactivex.rxjava3.disposables.Disposable)219 TestException (io.reactivex.rxjava3.exceptions.TestException)74 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)56 IOException (java.io.IOException)37 Scheduler (io.reactivex.rxjava3.core.Scheduler)36 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)35 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)34 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)32 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 TestObserver (io.reactivex.rxjava3.observers.TestObserver)18 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)15 QueueDisposable (io.reactivex.rxjava3.operators.QueueDisposable)13 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)10 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)9 Observable (io.reactivex.rxjava3.core.Observable)6 Observer (io.reactivex.rxjava3.core.Observer)6 ScalarDisposable (io.reactivex.rxjava3.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)6 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)6