Search in sources :

Example 61 with TestScheduler

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

the class FlowableDebounceTest method debounceWithTimeBackpressure.

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

Example 62 with TestScheduler

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

the class FlowableDebounceTest method before.

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

Example 63 with TestScheduler

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

the class ObservableWindowWithStartEndObservableTest method before.

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

Example 64 with TestScheduler

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

the class ObservableThrottleFirstTest method before.

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

Example 65 with TestScheduler

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

the class ObservableTimeoutTests method shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout.

@Test
public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() {
    PublishSubject<String> other = PublishSubject.create();
    Observable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
    Observer<String> observer = TestHelper.mockObserver();
    TestObserver<String> to = new TestObserver<>(observer);
    source.subscribe(to);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    underlyingSubject.onNext("One");
    testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
    underlyingSubject.onNext("Two");
    other.onNext("a");
    other.onNext("b");
    to.dispose();
    // The following messages should not be delivered.
    other.onNext("c");
    other.onNext("d");
    other.onComplete();
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onNext("One");
    inOrder.verify(observer, times(1)).onNext("a");
    inOrder.verify(observer, times(1)).onNext("b");
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) TestObserver(io.reactivex.rxjava3.observers.TestObserver)

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