Search in sources :

Example 86 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 87 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 88 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)

Example 89 with TestScheduler

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

the class ObservableThrottleLastTests method testThrottle.

@Test
public void testThrottle() {
    Observer<Integer> observer = TestHelper.mockObserver();
    TestScheduler s = new TestScheduler();
    PublishSubject<Integer> o = PublishSubject.create();
    o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(observer);
    // send events with simulated time increments
    s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
    // skip
    o.onNext(1);
    // deliver
    o.onNext(2);
    s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
    // skip
    o.onNext(3);
    s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
    // skip
    o.onNext(4);
    s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
    // skip
    o.onNext(5);
    // deliver
    o.onNext(6);
    s.advanceTimeTo(1001, TimeUnit.MILLISECONDS);
    // deliver
    o.onNext(7);
    s.advanceTimeTo(1501, TimeUnit.MILLISECONDS);
    o.onComplete();
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer).onNext(2);
    inOrder.verify(observer).onNext(6);
    inOrder.verify(observer).onNext(7);
    inOrder.verify(observer).onComplete();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 90 with TestScheduler

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

the class TestSchedulerTest method timedRunnableToString.

@Test
public void timedRunnableToString() {
    TimedRunnable r = new TimedRunnable((TestWorker) new TestScheduler().createWorker(), 5, new Runnable() {

        @Override
        public void run() {
        // TODO Auto-generated method stub
        }

        @Override
        public String toString() {
            return "Runnable";
        }
    }, 1);
    assertEquals("TimedRunnable(time = 5, run = Runnable)", r.toString());
}
Also used : 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