Search in sources :

Example 41 with TestScheduler

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

the class FlowableSkipTimedTest method skipTimedFinishBeforeTime.

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

Example 42 with TestScheduler

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

the class FlowableSkipTimedTest method skipTimed.

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

Example 43 with TestScheduler

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

the class CompletableTimeoutTest method errorTimeoutRace.

@Test
public void errorTimeoutRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final TestScheduler scheduler = new TestScheduler();
            final PublishSubject<Integer> ps = PublishSubject.create();
            TestObserverEx<Void> to = ps.ignoreElements().timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()).to(TestHelper.<Void>testConsumer());
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    ps.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
                }
            };
            TestHelper.race(r1, r2);
            to.assertTerminated();
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 44 with TestScheduler

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

the class BlockingFlowableLatestTest method hasNextThrows.

@Test(expected = RuntimeException.class)
public void hasNextThrows() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.<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.rxjava3.schedulers.TestScheduler)

Example 45 with TestScheduler

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

the class BlockingFlowableLatestTest method simple.

@Test
public void simple() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.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 < 9; i++) {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        Assert.assertTrue(it.hasNext());
        Assert.assertEquals(Long.valueOf(i), it.next());
    }
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    Assert.assertFalse(it.hasNext());
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Aggregations

TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)92 Test (org.junit.Test)84 TestException (io.reactivex.rxjava3.exceptions.TestException)38 InOrder (org.mockito.InOrder)30 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)7 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 TestObserver (io.reactivex.rxjava3.observers.TestObserver)6 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)6 Action (io.reactivex.rxjava3.functions.Action)5 SchedulerWhen (io.reactivex.rxjava3.internal.schedulers.SchedulerWhen)4 Observable (io.reactivex.rxjava3.core.Observable)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)2 BaseObserveOnSubscriber (io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber)1 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)1 IOException (java.io.IOException)1