Search in sources :

Example 96 with TestScheduler

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

the class SingleDelayTest method delayOnError.

@Test
public void delayOnError() {
    final TestScheduler scheduler = new TestScheduler();
    final TestObserver<?> observer = Single.error(new TestException()).delay(5, TimeUnit.SECONDS, scheduler).test();
    scheduler.triggerActions();
    observer.assertError(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 97 with TestScheduler

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

the class SchedulerWhenTest method asyncMaxConcurrent.

@Test
public void asyncMaxConcurrent() {
    TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = maxConcurrentScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    asyncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : SchedulerWhen(io.reactivex.rxjava3.internal.schedulers.SchedulerWhen) Test(org.junit.Test)

Example 98 with TestScheduler

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

the class FlowableWindowTests method timeSizeWindowAlternatingBounds.

@Test
public void timeSizeWindowAlternatingBounds() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<List<Integer>> ts = pp.window(5, TimeUnit.SECONDS, scheduler, 2).flatMapSingle(new Function<Flowable<Integer>, SingleSource<List<Integer>>>() {

        @Override
        public SingleSource<List<Integer>> apply(Flowable<Integer> v) throws Throwable {
            return v.toList();
        }
    }).test();
    pp.onNext(1);
    pp.onNext(2);
    // size bound hit
    ts.assertValueCount(1);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    pp.onNext(3);
    scheduler.advanceTimeBy(6, TimeUnit.SECONDS);
    // time bound hit
    ts.assertValueCount(2);
    pp.onNext(4);
    pp.onNext(5);
    // size bound hit again
    ts.assertValueCount(3);
    pp.onNext(4);
    scheduler.advanceTimeBy(6, TimeUnit.SECONDS);
    ts.assertValueCount(4).assertNoErrors().assertNotComplete();
    ts.cancel();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 99 with TestScheduler

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

the class CompletableTimerTest method timer.

@Test
public void timer() {
    final TestScheduler testScheduler = new TestScheduler();
    final AtomicLong atomicLong = new AtomicLong();
    Completable.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Action() {

        @Override
        public void run() throws Exception {
            atomicLong.incrementAndGet();
        }
    });
    assertEquals(0, atomicLong.get());
    testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    assertEquals(0, atomicLong.get());
    testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    assertEquals(1, atomicLong.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Action(io.reactivex.rxjava3.functions.Action) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 100 with TestScheduler

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

the class ObservableSkipLastTimedTest method skipLastTimedErrorBeforeTimeDelayError.

@Test
public void skipLastTimedErrorBeforeTimeDelayError() {
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<Integer> source = PublishSubject.create();
    Observable<Integer> result = source.skipLast(1, TimeUnit.SECONDS, scheduler, true);
    Observer<Object> o = TestHelper.mockObserver();
    result.subscribe(o);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onError(new TestException());
    scheduler.advanceTimeBy(1050, TimeUnit.MILLISECONDS);
    verify(o).onError(any(TestException.class));
    verify(o, never()).onComplete();
    verify(o, never()).onNext(any());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

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