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


Java Schedulers.test方法代码示例

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


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

示例1: testUnsubscribeOnCancel

import rx.schedulers.Schedulers; //导入方法依赖的package包/类
@Test
public void testUnsubscribeOnCancel() throws Exception {
    final TestScheduler ticker = Schedulers.test();

    final Ctx ctx = Ctx.empty();

    final AtomicBoolean failed = new AtomicBoolean(false);
    final AtomicBoolean completed = new AtomicBoolean(false);
    final AtomicInteger counter = new AtomicInteger();

    final Observable os = Observable.interval(10, TimeUnit.MILLISECONDS, ticker);

    final Subscription s = os.subscribe((i) -> counter.getAndIncrement(),
                                        (e) -> failed.set(true),
                                        () -> completed.set(true));

    // unsubscribe when currentExchange is cancelled
    ctx.onCancel(s::unsubscribe);

    // receive first event
    ticker.advanceTimeBy(10, TimeUnit.MILLISECONDS);
    ticker.triggerActions();
    assertThat(counter.get()).isEqualTo(1);

    // receive second event
    ticker.advanceTimeBy(10, TimeUnit.MILLISECONDS);
    ticker.triggerActions();
    assertThat(counter.get()).isEqualTo(2);

    // should led to unsubscribe, not receive future elements
    ctx.cancel();

    // advance time enough to trigger third event, but we should not get it
    ticker.advanceTimeBy(10, TimeUnit.MILLISECONDS);
    ticker.triggerActions();
    assertThat(counter.get()).isEqualTo(2);

    // verify it was not completed or failed
    assertThat(completed.get()).isFalse();
    assertThat(failed.get()).isFalse();
}
 
开发者ID:groupon,项目名称:jtier-ctx,代码行数:42,代码来源:RxJavaExample.java


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