Search in sources :

Example 76 with TestScheduler

use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method testSizeAndHasAnyValueTimeBounded.

@Test
public void testSizeAndHasAnyValueTimeBounded() {
    TestScheduler ts = new TestScheduler();
    ReplayRelay<Object> rs = ReplayRelay.createWithTime(1, TimeUnit.SECONDS, ts);
    assertEquals(0, rs.size());
    assertFalse(rs.hasValue());
    for (int i = 0; i < 1000; i++) {
        rs.accept(i);
        assertEquals(1, rs.size());
        assertTrue(rs.hasValue());
        ts.advanceTimeBy(2, TimeUnit.SECONDS);
        assertEquals(0, rs.size());
        assertFalse(rs.hasValue());
    }
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 77 with TestScheduler

use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method reentrantDrain.

@Test
public void reentrantDrain() {
    TestScheduler scheduler = new TestScheduler();
    final ReplayRelay<Integer> rp = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    TestObserver<Integer> ts = new TestObserver<Integer>() {

        @Override
        public void onNext(Integer t) {
            if (t == 1) {
                rp.accept(2);
            }
            super.onNext(t);
        }
    };
    rp.subscribe(ts);
    rp.accept(1);
    ts.assertValues(1, 2);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 78 with TestScheduler

use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method timeAndSizeRemoveCorrectNumberOfOld.

@Test
public void timeAndSizeRemoveCorrectNumberOfOld() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    rs.accept(1);
    rs.accept(2);
    // remove 1 due to maxSize, size == 2
    rs.accept(3);
    scheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    // remove 2 due to maxSize, remove 3 due to age, size == 1
    rs.accept(4);
    // size == 2
    rs.accept(5);
    rs.test().assertValuesOnly(4, 5);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 79 with TestScheduler

use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method timedSkipOld.

@Test
public void timedSkipOld() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> rp = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    rp.accept(1);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    rp.test().assertEmpty();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 80 with TestScheduler

use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method testReplayTimestampedDirectly.

@Test
public void testReplayTimestampedDirectly() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> source = ReplayRelay.createWithTime(1, TimeUnit.SECONDS, scheduler);
    source.accept(1);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    Observer<Integer> o = TestHelper.mockObserver();
    source.subscribe(o);
    source.accept(2);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    source.accept(3);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    // source.onComplete();
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    verify(o, never()).onError(any(Throwable.class));
    verify(o, never()).onNext(1);
    verify(o).onNext(2);
    verify(o).onNext(3);
// verify(o).onComplete();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) 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