当前位置: 首页>>代码示例>>Java>>正文


Java Flowable.interval方法代码示例

本文整理汇总了Java中io.reactivex.Flowable.interval方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.interval方法的具体用法?Java Flowable.interval怎么用?Java Flowable.interval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Flowable的用法示例。


在下文中一共展示了Flowable.interval方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test2

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test2() {
    Flowable<Long> trigger = Flowable
            .merge(asList(delayed(500), delayed(3500), delayed(4500), delayed(6500), delayed(8500)));
    Flowable<Long> data = Flowable.interval(1000, MILLISECONDS);

    subscribeAndWait(data, trigger);

    assertThat(subscriber.values()).containsExactly(2L, 3L, 5L, 7L);
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:11,代码来源:CombineWithLatestStreamIdStreamTest.java

示例2: test1

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test1() {
    Flowable<Long> trigger = Flowable.interval(1000, MILLISECONDS).delay(500, MILLISECONDS).take(4);
    Flowable<Long> data = Flowable.interval(1000, MILLISECONDS);

    subscribeAndWait(data, trigger);

    assertThat(subscriber.values()).containsExactly(0L, 1L, 2L, 3L);
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:10,代码来源:CombineWithLatestStreamIdStreamTest.java

示例3: test4

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test4() {
    Flowable<Long> trigger = delayed(500);
    Flowable<Long> data = Flowable.interval(1000, MILLISECONDS);
    subscribeAndWait(data, trigger);
    assertThat(subscriber.values()).isEmpty();
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:8,代码来源:CombineWithLatestStreamIdStreamTest.java

示例4: zip

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void zip() throws Exception{
    Consumer<Object> consumer = v -> System.out.println("[" + System.currentTimeMillis() / 100 + "] " + v);
    Flowable<Long> f1 = Flowable.interval(100, TimeUnit.MILLISECONDS);
    Flowable<Long> f2 = Flowable.interval(200, TimeUnit.MILLISECONDS);

    Flowable<Long> f3 = Flowable.zip(f1, f2, (x, y) -> x * 10000 + y);
    f3.subscribe(consumer);
}
 
开发者ID:RXTeams,项目名称:RxjavaExample,代码行数:10,代码来源:ExampleUnitTest.java

示例5: testBufferWithInterval

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * This test ensures that the first element of the source stream is not ignored, and that the correct amount of
 * values are buffered.
 */
@Test
public void testBufferWithInterval() {
    TestScheduler testScheduler = new TestScheduler();
    Flowable<Long> source = Flowable.interval(0, 2, SECONDS, testScheduler);
    Flowable<Long> start = Flowable.interval(0, 20, SECONDS, testScheduler);
    Flowable<Long> end = start.delay(11, SECONDS, testScheduler);

    DiscoveryService discoveryService = Mockito.mock(DiscoveryService.class);
    StreamId<Long> sourceId = Mockito.mock(StreamId.class);
    StreamId<Long> startStreamId = Mockito.mock(StreamId.class);
    StreamId<Long> endStreamId = Mockito.mock(StreamId.class);
    EndStreamMatcher<?, ?> endStreamMatcher = EndStreamMatcher.endingOnEvery(endStreamId);
    BufferSpecification bufferSpecification = ofStartEnd(startStreamId, singleton(endStreamMatcher));
    OverlapBufferStreamId<?> streamId = OverlapBufferStreamId.of(sourceId, bufferSpecification);

    when(discoveryService.discover(sourceId)).thenReturn(source);
    when(discoveryService.discover(startStreamId)).thenReturn(start);
    when(discoveryService.discover(endStreamId)).thenReturn(end);

    Flowable<Object> data = fromPublisher(overlapBufferStreamFactory.create(streamId, discoveryService).data());
    TestSubscriber<Object> testSubscriber = data.test();

    List<Long> firstExpectedResult = Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L);
    List<Long> secondExpectedResult = Arrays.asList(10L, 11L, 12L, 13L, 14L, 15L);
    List<Long> thirdExpectedResult = Arrays.asList(20L, 21L, 22L, 23L, 24L, 25L);

    testScheduler.advanceTimeBy(11, SECONDS);
    testSubscriber.assertValueCount(1);
    testSubscriber.assertValueAt(0, firstExpectedResult::equals);

    testScheduler.advanceTimeBy(21, SECONDS);
    testSubscriber.assertValueCount(2);
    testSubscriber.assertValueAt(1, secondExpectedResult::equals);

    testScheduler.advanceTimeBy(10, SECONDS);
    testSubscriber.assertValueCount(2);
    testScheduler.advanceTimeBy(11, SECONDS);

    testSubscriber.assertValueCount(3);
    testSubscriber.assertValueAt(2, thirdExpectedResult::equals);
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:46,代码来源:OverlapBufferStreamFactoryTest.java


注:本文中的io.reactivex.Flowable.interval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。