Search in sources :

Example 56 with TestScheduler

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

the class SchedulerWhenTest method syncMaxConcurrent.

@Test
public void syncMaxConcurrent() {
    TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = maxConcurrentScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    syncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    // since all the work is synchronous nothing is blocked and its all done
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : SchedulerWhen(io.reactivex.rxjava3.internal.schedulers.SchedulerWhen) Test(org.junit.Test)

Example 57 with TestScheduler

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

the class FlowableDelayTest method onErrorFinal.

@Test
public void onErrorFinal() {
    TestScheduler scheduler = new TestScheduler();
    Flowable.error(new TestException()).delay(1, TimeUnit.MILLISECONDS, scheduler).subscribe(new DisposableSubscriber<Object>() {

        @Override
        public void onNext(Object value) {
        }

        @Override
        public void onError(Throwable e) {
            throw new TestException();
        }

        @Override
        public void onComplete() {
        }
    });
    try {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        fail("Should have thrown");
    } catch (TestException ex) {
    // expected
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 58 with TestScheduler

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

the class FlowableBufferTest method timedSizeBufferAlreadyCleared.

@Test
public void timedSizeBufferAlreadyCleared() {
    TestScheduler sch = new TestScheduler();
    TestSubscriber<List<Integer>> ts = new TestSubscriber<>();
    BufferExactBoundedSubscriber<Integer, List<Integer>> sub = new BufferExactBoundedSubscriber<>(ts, Functions.justSupplier((List<Integer>) new ArrayList<Integer>()), 1, TimeUnit.SECONDS, 1, false, sch.createWorker());
    BooleanSubscription bs = new BooleanSubscription();
    sub.onSubscribe(bs);
    sub.producerIndex++;
    sub.run();
    assertFalse(sub.isDisposed());
    sub.enter();
    sub.onComplete();
    assertTrue(sub.isDisposed());
    sub.run();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 59 with TestScheduler

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

the class FlowableBufferTest method timedSkipCancelWhenSecondBuffer.

@Test
public void timedSkipCancelWhenSecondBuffer() {
    TestScheduler sch = new TestScheduler();
    final TestSubscriber<List<Integer>> ts = new TestSubscriber<>();
    BufferSkipBoundedSubscriber<Integer, List<Integer>> sub = new BufferSkipBoundedSubscriber<>(ts, new Supplier<List<Integer>>() {

        int calls;

        @Override
        public List<Integer> get() throws Exception {
            if (++calls == 2) {
                ts.cancel();
            }
            return new ArrayList<>();
        }
    }, 1, 1, TimeUnit.SECONDS, sch.createWorker());
    sub.onSubscribe(new BooleanSubscription());
    sub.run();
    assertTrue(ts.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) IOException(java.io.IOException)

Example 60 with TestScheduler

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

the class FlowableDebounceTest method timedLateEmit.

@Test
public void timedLateEmit() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    DebounceTimedSubscriber<Integer> sub = new DebounceTimedSubscriber<>(ts, 1, TimeUnit.SECONDS, new TestScheduler().createWorker());
    sub.onSubscribe(new BooleanSubscription());
    DebounceEmitter<Integer> de = new DebounceEmitter<>(1, 50, sub);
    de.emit();
    de.emit();
    ts.assertEmpty();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) 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