Search in sources :

Example 86 with TestScheduler

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

the class FlowableThrottleLatestTest method normalEmitLast.

@Test
public void normalEmitLast() {
    TestScheduler sch = new TestScheduler();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = pp.throttleLatest(1, TimeUnit.SECONDS, sch, true).test();
    pp.onNext(1);
    ts.assertValuesOnly(1);
    pp.onNext(2);
    ts.assertValuesOnly(1);
    pp.onNext(3);
    ts.assertValuesOnly(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3);
    pp.onNext(4);
    ts.assertValuesOnly(1, 3);
    pp.onNext(5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    pp.onNext(6);
    ts.assertValuesOnly(1, 3, 5, 6);
    pp.onNext(7);
    pp.onComplete();
    ts.assertResult(1, 3, 5, 6, 7);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertResult(1, 3, 5, 6, 7);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 87 with TestScheduler

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

the class FlowableThrottleLatestTest method normal.

@Test
public void normal() {
    TestScheduler sch = new TestScheduler();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = pp.throttleLatest(1, TimeUnit.SECONDS, sch).test();
    pp.onNext(1);
    ts.assertValuesOnly(1);
    pp.onNext(2);
    ts.assertValuesOnly(1);
    pp.onNext(3);
    ts.assertValuesOnly(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3);
    pp.onNext(4);
    ts.assertValuesOnly(1, 3);
    pp.onNext(5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    pp.onNext(6);
    ts.assertValuesOnly(1, 3, 5, 6);
    pp.onNext(7);
    pp.onComplete();
    ts.assertResult(1, 3, 5, 6);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertResult(1, 3, 5, 6);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 88 with TestScheduler

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

the class FlowableThrottleLatestTest method missingBackpressureExceptionLatest.

@Test
public void missingBackpressureExceptionLatest() throws Throwable {
    TestScheduler sch = new TestScheduler();
    Action onCancel = mock(Action.class);
    TestSubscriber<Integer> ts = Flowable.just(1, 2).concatWith(Flowable.<Integer>never()).doOnCancel(onCancel).throttleLatest(1, TimeUnit.SECONDS, sch, true).test(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertFailure(MissingBackpressureException.class, 1);
    verify(onCancel).run();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 89 with TestScheduler

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

the class FlowableTimeoutTests method shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout.

@Test
public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() {
    PublishProcessor<String> other = PublishProcessor.create();
    Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    TestSubscriber<String> ts = new TestSubscriber<>(subscriber);
    source.subscribe(ts);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    underlyingSubject.onNext("One");
    testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
    underlyingSubject.onNext("Two");
    other.onNext("a");
    other.onNext("b");
    ts.cancel();
    // The following messages should not be delivered.
    other.onNext("c");
    other.onNext("d");
    other.onComplete();
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber, times(1)).onNext("One");
    inOrder.verify(subscriber, times(1)).onNext("a");
    inOrder.verify(subscriber, times(1)).onNext("b");
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber)

Example 90 with TestScheduler

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

the class FlowableTimeoutTests method shouldSwitchToOtherIfOnErrorNotWithinTimeout.

@Test
public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() {
    Flowable<String> other = Flowable.just("a", "b", "c");
    Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    TestSubscriber<String> ts = new TestSubscriber<>(subscriber);
    source.subscribe(ts);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    underlyingSubject.onNext("One");
    testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
    underlyingSubject.onError(new UnsupportedOperationException());
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber, times(1)).onNext("One");
    inOrder.verify(subscriber, times(1)).onNext("a");
    inOrder.verify(subscriber, times(1)).onNext("b");
    inOrder.verify(subscriber, times(1)).onNext("c");
    inOrder.verify(subscriber, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
    ts.cancel();
}
Also used : InOrder(org.mockito.InOrder) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber)

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