Search in sources :

Example 61 with TestScheduler

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

the class FlowableTakeTimedTest method testTakeTimedErrorBeforeTime.

@Test
public void testTakeTimedErrorBeforeTime() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> o = TestHelper.mockSubscriber();
    result.subscribe(o);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onError(new TestException());
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    source.onNext(4);
    InOrder inOrder = inOrder(o);
    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onNext(2);
    inOrder.verify(o).onNext(3);
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onComplete();
    verify(o, never()).onNext(4);
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 62 with TestScheduler

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

the class FlowableWindowWithStartEndFlowableTest method before.

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

Example 63 with TestScheduler

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

the class ObservableDebounceTest method debounceWithTimeBackpressure.

@Test
public void debounceWithTimeBackpressure() throws InterruptedException {
    TestScheduler scheduler = new TestScheduler();
    TestObserver<Integer> observer = new TestObserver<Integer>();
    Observable.merge(Observable.just(1), Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler)).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(observer);
    scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS);
    observer.assertValue(2);
    observer.assertTerminated();
    observer.assertNoErrors();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) TestObserver(io.reactivex.observers.TestObserver)

Example 64 with TestScheduler

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

the class ObservableDebounceTest method before.

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

Example 65 with TestScheduler

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

the class ObservableDebounceTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposables.empty());
                observer.onComplete();
                observer.onNext(1);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.debounce(1, TimeUnit.SECONDS, new TestScheduler()).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) 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