Search in sources :

Example 31 with TestScheduler

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

the class FlowableReplayTest method timedAndSizedTruncationError.

@Test
public void timedAndSizedTruncationError() {
    TestScheduler test = new TestScheduler();
    SizeAndTimeBoundReplayBuffer<Integer> buf = new SizeAndTimeBoundReplayBuffer<>(2, 2000, TimeUnit.MILLISECONDS, test, false);
    Assert.assertFalse(buf.hasCompleted());
    Assert.assertFalse(buf.hasError());
    List<Integer> values = new ArrayList<>();
    buf.next(1);
    test.advanceTimeBy(1, TimeUnit.SECONDS);
    buf.next(2);
    test.advanceTimeBy(1, TimeUnit.SECONDS);
    buf.collect(values);
    Assert.assertEquals(Arrays.asList(2), values);
    buf.next(3);
    buf.next(4);
    values.clear();
    buf.collect(values);
    Assert.assertEquals(Arrays.asList(3, 4), values);
    test.advanceTimeBy(2, TimeUnit.SECONDS);
    buf.next(5);
    values.clear();
    buf.collect(values);
    Assert.assertEquals(Arrays.asList(5), values);
    Assert.assertFalse(buf.hasCompleted());
    Assert.assertFalse(buf.hasError());
    test.advanceTimeBy(2, TimeUnit.SECONDS);
    buf.error(new TestException());
    values.clear();
    buf.collect(values);
    Assert.assertTrue(values.isEmpty());
    Assert.assertEquals(1, buf.size);
    Assert.assertFalse(buf.hasCompleted());
    Assert.assertTrue(buf.hasError());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 32 with TestScheduler

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

the class FlowableThrottleLatestTest method missingBackpressureExceptionFirst.

@Test
public void missingBackpressureExceptionFirst() throws Throwable {
    TestScheduler sch = new TestScheduler();
    Action onCancel = mock(Action.class);
    Flowable.just(1, 2).doOnCancel(onCancel).throttleLatest(1, TimeUnit.MINUTES, sch).test(0).assertFailure(MissingBackpressureException.class);
    verify(onCancel).run();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 33 with TestScheduler

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

the class FlowableThrottleLatestTest method missingBackpressureExceptionLatestComplete.

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

Example 34 with TestScheduler

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

the class FlowableThrottleLatestTest method reentrantComplete.

@Test
public void reentrantComplete() {
    TestScheduler sch = new TestScheduler();
    final PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            if (t == 1) {
                pp.onNext(2);
            }
            if (t == 2) {
                pp.onComplete();
            }
        }
    };
    pp.throttleLatest(1, TimeUnit.SECONDS, sch).subscribe(ts);
    pp.onNext(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertResult(1, 2);
}
Also used : TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 35 with TestScheduler

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

the class FlowableTimeoutTests method shouldSwitchToOtherIfOnCompletedNotWithinTimeout.

@Test
public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() {
    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.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.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