Search in sources :

Example 96 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)

Example 97 with TestScheduler

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

the class ReplayProcessorTest method takeSizeAndTime.

@Test
public void takeSizeAndTime() {
    TestScheduler scheduler = new TestScheduler();
    ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    rp.onNext(1);
    rp.onNext(2);
    rp.onNext(3);
    rp.take(1).test().assertResult(2);
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 98 with TestScheduler

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

the class ReplayProcessorTest method timedNoOutdatedData.

@Test
public void timedNoOutdatedData() {
    TestScheduler scheduler = new TestScheduler();
    ReplayProcessor<Integer> source = ReplayProcessor.createWithTime(2, TimeUnit.SECONDS, scheduler);
    source.onNext(1);
    source.onComplete();
    source.test().assertResult(1);
    source.test().assertResult(1);
    scheduler.advanceTimeBy(3, TimeUnit.SECONDS);
    source.test().assertResult();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 99 with TestScheduler

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

the class ReplayProcessorTest method timedSkipOld.

@Test
public void timedSkipOld() {
    TestScheduler scheduler = new TestScheduler();
    ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    rp.onNext(1);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    rp.test().assertEmpty();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 100 with TestScheduler

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

the class ReplayProcessorTest method reentrantDrain.

@Test
public void reentrantDrain() {
    TestScheduler scheduler = new TestScheduler();
    final ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onNext(Integer t) {
            if (t == 1) {
                rp.onNext(2);
            }
            super.onNext(t);
        }
    };
    rp.subscribe(ts);
    rp.onNext(1);
    rp.onComplete();
    ts.assertResult(1, 2);
}
Also used : TestSubscriber(io.reactivex.subscribers.TestSubscriber) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

TestScheduler (io.reactivex.schedulers.TestScheduler)110 Test (org.junit.Test)66 InOrder (org.mockito.InOrder)26 TestObserver (io.reactivex.observers.TestObserver)16 TestSubscriber (io.reactivex.subscribers.TestSubscriber)14 Disposable (io.reactivex.disposables.Disposable)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 TestException (io.reactivex.exceptions.TestException)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 Schedulers (io.reactivex.schedulers.Schedulers)9 TimeUnit (java.util.concurrent.TimeUnit)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 FlowableSingleDeferUntilRequest (org.davidmoten.rx.internal.FlowableSingleDeferUntilRequest)9 Flowable (io.reactivex.Flowable)8 Scheduler (io.reactivex.Scheduler)8 SingleObserver (io.reactivex.SingleObserver)8 UndeliverableException (io.reactivex.exceptions.UndeliverableException)8 Consumer (io.reactivex.functions.Consumer)8 RxJavaPlugins (io.reactivex.plugins.RxJavaPlugins)8