Java Code Examples for io.reactivex.rxjava3.schedulers.TestScheduler#advanceTimeBy()

The following examples show how to use io.reactivex.rxjava3.schedulers.TestScheduler#advanceTimeBy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example 2
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 6 votes vote down vote up
@Test
public void timeAndSizeRemoveCorrectNumberOfOld() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);

    rs.accept(1);
    rs.accept(2);
    rs.accept(3); // remove 1 due to maxSize, size == 2

    scheduler.advanceTimeBy(2, TimeUnit.SECONDS);

    rs.accept(4); // remove 2 due to maxSize, remove 3 due to age, size == 1
    rs.accept(5); // size == 2

    rs.test().assertValuesOnly(4, 5);
}
 
Example 3
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example 4
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 6 votes vote down vote up
@Test
public void timeAndSizeRemoveCorrectNumberOfOld() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);

    rs.accept(1);
    rs.accept(2);
    rs.accept(3); // remove 1 due to maxSize, size == 2

    scheduler.advanceTimeBy(2, TimeUnit.SECONDS);

    rs.accept(4); // remove 2 due to maxSize, remove 3 due to age, size == 1
    rs.accept(5); // size == 2

    rs.test().assertValuesOnly(4, 5);
}
 
Example 5
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 6
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 7
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 3 votes vote down vote up
@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();
}
 
Example 8
Source File: ReplayRelayTest.java    From RxRelay with Apache License 2.0 3 votes vote down vote up
@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();
}