Search in sources :

Example 81 with TestScheduler

use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method takeSizeAndTime.

@Test
public void takeSizeAndTime() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> rp = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    rp.accept(1);
    rp.accept(2);
    rp.accept(3);
    rp.take(1).test().assertResult(2);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 82 with TestScheduler

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

the class FlowableTakeLastTimedTest method takeLastTimedThrowingSource.

@Test
public void takeLastTimedThrowingSource() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Object> source = PublishProcessor.create();
    Flowable<Object> result = source.takeLast(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(subscriber);
    result.subscribe(subscriber);
    // T: 0ms
    source.onNext(1);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 250ms
    source.onNext(2);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 500ms
    source.onNext(3);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 750ms
    source.onNext(4);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 1000ms
    source.onNext(5);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 1250ms
    source.onError(new TestException());
    inOrder.verify(subscriber, times(1)).onError(any(TestException.class));
    verify(subscriber, never()).onNext(any());
    verify(subscriber, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 83 with TestScheduler

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

the class FlowableTakeTimedTest method takeTimedErrorAfterTime.

@Test
public void takeTimedErrorAfterTime() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.take(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.onError(new TestException());
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber).onNext(1);
    inOrder.verify(subscriber).onNext(2);
    inOrder.verify(subscriber).onNext(3);
    inOrder.verify(subscriber).onComplete();
    inOrder.verifyNoMoreInteractions();
    verify(subscriber, never()).onNext(4);
    verify(subscriber, never()).onError(any(TestException.class));
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 84 with TestScheduler

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

the class FlowableTakeTimedTest method takeTimedErrorBeforeTime.

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

Example 85 with TestScheduler

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

the class FlowableThrottleFirstTest method throttle.

@Test
public void throttle() {
    Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
    TestScheduler s = new TestScheduler();
    PublishProcessor<Integer> o = PublishProcessor.create();
    o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber);
    // 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(subscriber);
    inOrder.verify(subscriber).onNext(1);
    inOrder.verify(subscriber).onNext(3);
    inOrder.verify(subscriber).onNext(7);
    inOrder.verify(subscriber).onComplete();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) 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