Search in sources :

Example 46 with Disposable

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

the class SchedulerTest method disposePeriodicDirect.

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

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

Example 47 with Disposable

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

the class SchedulerTest method disposeSelfPeriodicDirect.

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

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

Example 48 with Disposable

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

the class ExecutorSchedulerFairTest method plainExecutor.

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

        @Override
        public void execute(Runnable r) {
            r.run();
        }
    }, false, true);
    final CountDownLatch cdl = new CountDownLatch(5);
    Runnable r = new Runnable() {

        @Override
        public void run() {
            cdl.countDown();
        }
    };
    s.scheduleDirect(r);
    s.scheduleDirect(r, 50, TimeUnit.MILLISECONDS);
    Disposable d = s.schedulePeriodicallyDirect(r, 10, 10, TimeUnit.MILLISECONDS);
    try {
        assertTrue(cdl.await(5, TimeUnit.SECONDS));
    } finally {
        d.dispose();
    }
    assertTrue(d.isDisposed());
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 49 with Disposable

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

the class ExecutorSchedulerFairTest method runnableDisposed.

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

        @Override
        public void execute(Runnable r) {
            r.run();
        }
    }, false, true);
    Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE);
    assertTrue(d.isDisposed());
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 50 with Disposable

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

the class ExecutorSchedulerFairTest method runnableDisposedAsyncTimed2.

@Test
public void runnableDisposedAsyncTimed2() throws Exception {
    ExecutorService executorScheduler = Executors.newScheduledThreadPool(1, new RxThreadFactory("TestCustomPoolTimed"));
    try {
        final Scheduler s = Schedulers.from(executorScheduler, false, true);
        Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
        while (!d.isDisposed()) {
            Thread.sleep(1);
        }
    } finally {
        executorScheduler.shutdownNow();
    }
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) RxThreadFactory(io.reactivex.rxjava3.internal.schedulers.RxThreadFactory) 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