Search in sources :

Example 46 with TestScheduler

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

the class BlockingFlowableLatestTest method simpleJustNext.

@Test(expected = NoSuchElementException.class)
public void simpleJustNext() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    // which onComplete will overwrite the previous value
    for (int i = 0; i < 10; i++) {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        Assert.assertEquals(Long.valueOf(i), it.next());
    }
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 47 with TestScheduler

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

the class CompletableDelaySubscriptionTest method timestep.

@Test
public void timestep() {
    TestScheduler scheduler = new TestScheduler();
    final AtomicInteger counter = new AtomicInteger();
    Completable result = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            counter.incrementAndGet();
        }
    }).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
    TestObserver<Void> to = result.test();
    scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
    to.assertEmpty();
    scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
    to.assertResult();
    assertEquals(1, counter.get());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 48 with TestScheduler

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

the class CompletableDelaySubscriptionTest method disposeMain.

@Test
public void disposeMain() {
    CompletableSubject cs = CompletableSubject.create();
    TestScheduler scheduler = new TestScheduler();
    TestObserver<Void> to = cs.delaySubscription(1, TimeUnit.SECONDS, scheduler).test();
    assertFalse(cs.hasObservers());
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    assertTrue(cs.hasObservers());
    to.dispose();
    assertFalse(cs.hasObservers());
}
Also used : CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 49 with TestScheduler

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

the class BlockingFlowableMostRecentTest method singleSourceManyIterators.

@Test
public void singleSourceManyIterators() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
    Iterable<Long> iter = source.blockingMostRecent(-1L);
    for (int j = 0; j < 3; j++) {
        Iterator<Long> it = iter.iterator();
        Assert.assertEquals(Long.valueOf(-1), it.next());
        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)

Example 50 with TestScheduler

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

the class CompletableDisposeOnTest method error.

@Test
public void error() {
    TestScheduler scheduler = new TestScheduler();
    final int[] call = { 0 };
    Completable.error(new TestException()).doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            call[0]++;
        }
    }).unsubscribeOn(scheduler).test().assertFailure(TestException.class);
    scheduler.triggerActions();
    assertEquals(0, call[0]);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) 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