Search in sources :

Example 66 with TestScheduler

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

the class BlockingObservableLatestTest method testHasNextThrows.

@Test(/* timeout = 1000, */
expected = RuntimeException.class)
public void testHasNextThrows() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Long> source = Observable.<Long>error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    it.hasNext();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 67 with TestScheduler

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

the class MaybeDelayTest method disposeDuringDelay.

@Test
public void disposeDuringDelay() {
    TestScheduler scheduler = new TestScheduler();
    TestObserver<Integer> ts = Maybe.just(1).delay(100, TimeUnit.MILLISECONDS, scheduler).test();
    ts.cancel();
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertEmpty();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 68 with TestScheduler

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

the class BlockingObservableLatestTest method testSimpleJustNext.

@Test(timeout = 1000, expected = NoSuchElementException.class)
public void testSimpleJustNext() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    // which onComplete will overwrite the previous value
    for (int i = 0; i < 10; i++) {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        Assert.assertEquals(Long.valueOf(i), it.next());
    }
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 69 with TestScheduler

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

the class ObservableThrottleFirstTest method before.

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

Example 70 with TestScheduler

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

the class ObservableThrottleFirstTest method testThrottle.

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

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