Search in sources :

Example 81 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class ObservableWindowWithStartEndObservableTest method before.

@Before
public void before() {
    scheduler = new TestScheduler();
    innerScheduler = scheduler.createWorker();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 82 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class SchedulerWhenTest method testAsyncMaxConcurrent.

@Test
public void testAsyncMaxConcurrent() {
    TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = maxConcurrentScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    asyncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 83 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class SchedulerWhenTest method testAsyncDelaySubscription.

@Test
public void testAsyncDelaySubscription() {
    final TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = throttleScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    asyncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 84 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class SchedulerWhenTest method testSyncDelaySubscription.

@Test
public void testSyncDelaySubscription() {
    final TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = throttleScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    syncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 85 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class MaybeTimerTest method timer.

@Test
public void timer() {
    final TestScheduler testScheduler = new TestScheduler();
    final AtomicLong atomicLong = new AtomicLong();
    Maybe.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Consumer<Long>() {

        @Override
        public void accept(final Long value) throws Exception {
            atomicLong.incrementAndGet();
        }
    });
    assertEquals(0, atomicLong.get());
    testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    assertEquals(0, atomicLong.get());
    testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    assertEquals(1, atomicLong.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

TestScheduler (io.reactivex.schedulers.TestScheduler)94 Test (org.junit.Test)53 InOrder (org.mockito.InOrder)26 TestException (io.reactivex.exceptions.TestException)11 Worker (io.reactivex.Scheduler.Worker)6 TestSubscriber (io.reactivex.subscribers.TestSubscriber)6 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)5 TestObserver (io.reactivex.observers.TestObserver)5 Disposable (io.reactivex.disposables.Disposable)3 Action (io.reactivex.functions.Action)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NonBlockingConnectionPool (org.davidmoten.rx.jdbc.pool.NonBlockingConnectionPool)1 Before (org.junit.Before)1