Search in sources :

Example 51 with TestScheduler

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

the class BlockingObservableLatestTest method hasNextThrows.

@Test(expected = RuntimeException.class)
public void hasNextThrows() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Long> source = Observable.<Long>error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    it.hasNext();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest)

Example 52 with TestScheduler

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

the class BlockingObservableLatestTest method nextThrows.

@Test(expected = RuntimeException.class)
public void nextThrows() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Long> source = Observable.<Long>error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    it.next();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest)

Example 53 with TestScheduler

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

the class BlockingObservableLatestTest method sameSourceMultipleIterators.

@Test
public void sameSourceMultipleIterators() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
    Iterable<Long> iter = source.blockingLatest();
    for (int j = 0; j < 3; j++) {
        Iterator<Long> it = iter.iterator();
        // which onComplete will overwrite the previous value
        for (int i = 0; i < 9; i++) {
            scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
            Assert.assertTrue(it.hasNext());
            Assert.assertEquals(Long.valueOf(i), it.next());
        }
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        Assert.assertFalse(it.hasNext());
    }
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest)

Example 54 with TestScheduler

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

the class SchedulerWhenTest method syncDelaySubscription.

@Test
public void syncDelaySubscription() {
    final TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = throttleScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    syncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    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 55 with TestScheduler

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

the class SchedulerWhenTest method asyncDelaySubscription.

@Test
public void asyncDelaySubscription() {
    final TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = throttleScheduler(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(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    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)

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