本文整理汇总了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();
}