本文整理汇总了Java中io.reactivex.schedulers.TestScheduler.advanceTimeBy方法的典型用法代码示例。如果您正苦于以下问题:Java TestScheduler.advanceTimeBy方法的具体用法?Java TestScheduler.advanceTimeBy怎么用?Java TestScheduler.advanceTimeBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.schedulers.TestScheduler
的用法示例。
在下文中一共展示了TestScheduler.advanceTimeBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_interval
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void test_interval()
{
TestScheduler testScheduler=new TestScheduler();
Observable<Long>observable=Observable.interval(1, TimeUnit.SECONDS,testScheduler).take(5);
TestObserver<Long> testObserver=new TestObserver<>();
observable.subscribeOn(testScheduler).subscribe(testObserver);
testObserver.assertNoValues();
testObserver.assertNotComplete();
testObserver.assertNoErrors();
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
testObserver.assertValueCount(1);
testObserver.assertValues(0l);
testScheduler.advanceTimeTo(6, TimeUnit.SECONDS);
testObserver.assertValueCount(5);
testObserver.assertValues(0l,1l,2l,3l,4l);
}
示例2: testATestScheduler
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void testATestScheduler() throws Exception {
TestSubscriber<Long> testSubscriber = new TestSubscriber<>();
TestScheduler testScheduler = new TestScheduler();
Flowable.interval(5, TimeUnit.MILLISECONDS, testScheduler)
.map(x -> x + 1)
.filter(x -> x % 2 == 0)
.subscribe(testSubscriber);
testScheduler.advanceTimeBy(10, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors();
testSubscriber.assertValues(2L);
testScheduler.advanceTimeBy(10, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors();
testSubscriber.assertValues(2L, 4L);
}
示例3: testBufferingWithNoUpdates
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void testBufferingWithNoUpdates() throws InterruptedException
{
TestScheduler testScheduler = new TestScheduler();
SimpleFlowableList<Integer> list = new SimpleFlowableList<>();
FlowableList<Integer> bufferedList = list.buffer(50, TimeUnit.MILLISECONDS, testScheduler);
TestSubscriber testSubscriber = new TestSubscriber();
bufferedList.updates().subscribe(testSubscriber);
testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
testScheduler.triggerActions();
testSubscriber.awaitCount(1);
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
testScheduler.triggerActions();
testSubscriber.awaitCount(1);
testSubscriber.dispose();
}
示例4: testWithScheduler
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void testWithScheduler() {
Exception ex = new IllegalArgumentException("boo");
TestSubscriber<Integer> ts = TestSubscriber.create();
TestScheduler scheduler = new TestScheduler();
Flowable.just(1, 2)
// force error after 3 emissions
.concatWith(Flowable.<Integer>error(ex))
// retry with backoff
.retryWhen(RetryWhen.maxRetries(2).action(log).exponentialBackoff(1, TimeUnit.MINUTES)
.scheduler(scheduler).build())
// go
.subscribe(ts);
ts.assertValues(1, 2);
ts.assertNotComplete();
scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
ts.assertValues(1, 2, 1, 2);
ts.assertNotComplete();
// next wait is 2 seconds so advancing by 1 should do nothing
scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
ts.assertValues(1, 2, 1, 2);
ts.assertNotComplete();
scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
ts.assertValues(1, 2, 1, 2, 1, 2);
ts.assertError(ex);
}
示例5: should_not_send_notification_occurring_after_unsubscribe
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_not_send_notification_occurring_after_unsubscribe() {
// given
TestScheduler scheduler = new TestScheduler();
Recorded<String> event = new Recorded<>(10, Notification.createOnNext("Hello world!"));
final HotObservable<String> hotObservable = HotObservable.create(scheduler, event);
// when
final TestObserver<String> observer = new TestObserver<>();
hotObservable.subscribe(observer);
scheduler.createWorker().schedule(new Runnable() {
@Override
public void run() {
observer.dispose();
}
}, 5, TimeUnit.MILLISECONDS);
// then
scheduler.advanceTimeBy(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
observer.assertNoValues();
}
示例6: should_keep_track_of_subscriptions
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_keep_track_of_subscriptions() {
// given
TestScheduler scheduler = new TestScheduler();
final HotObservable<String> hotObservable = HotObservable.create(scheduler);
// when
final TestObserver<String> observer = new TestObserver<>();
scheduler.createWorker().schedule(new Runnable() {
@Override
public void run() {
hotObservable.subscribe(observer);
}
}, 42, TimeUnit.MILLISECONDS);
// then
scheduler.advanceTimeBy(42, TimeUnit.MILLISECONDS);
assertThat(hotObservable.getSubscriptions())
.containsExactly(
new SubscriptionLog(42, Long.MAX_VALUE)
);
}
示例7: should_keep_track_of_unsubscriptions
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_keep_track_of_unsubscriptions() {
// given
TestScheduler scheduler = new TestScheduler();
final HotObservable<String> hotObservable = HotObservable.create(scheduler);
// when
final TestObserver<String> observer = new TestObserver<>();
hotObservable.subscribe(observer);
scheduler.createWorker().schedule(new Runnable() {
@Override
public void run() {
observer.dispose();
}
}, 42, TimeUnit.MILLISECONDS);
// then
scheduler.advanceTimeBy(42, TimeUnit.MILLISECONDS);
assertThat(hotObservable.getSubscriptions())
.containsExactly(
new SubscriptionLog(0, 42)
);
}
示例8: search_withNonEmptyQuery_triggersAfterDelay
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void search_withNonEmptyQuery_triggersAfterDelay() {
TestScheduler testScheduler = new TestScheduler();
Act act = new ArrangeBuilder()
.withTimeScheduler(testScheduler, SEARCH_DEBOUNCE_TAG)
.act()
.bind();
act.search(DUMMY_QUERY);
verify(searchDataModel).querySearch(searchTermCaptor.capture(),
searchDelayCaptor.capture());
assertThat(searchTermCaptor.getValue()).isEqualTo(DUMMY_QUERY);
TestObserver<Void> testObserver = searchDelayCaptor.getValue().test();
testScheduler.advanceTimeBy(SEARCH_DEBOUNCE_TIME_SECONDS,
TimeUnit.SECONDS);
testObserver.assertComplete();
}
示例9: should_send_notification_on_subscribe_using_offset
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_send_notification_on_subscribe_using_offset() {
// given
TestScheduler scheduler = new TestScheduler();
long offset = 10;
Recorded<String> event = new Recorded<>(offset, Notification.createOnNext("Hello world!"));
ColdObservable<String> coldObservable = ColdObservable.create(scheduler, event);
// when
TestObserver<String> observer = new TestObserver<>();
coldObservable.subscribe(observer);
// then
scheduler.advanceTimeBy(9, TimeUnit.MILLISECONDS);
observer.assertNoValues();
scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
observer.assertValue("Hello world!");
}
示例10: should_not_send_notification_after_unsubscribe
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_not_send_notification_after_unsubscribe() {
// given
TestScheduler scheduler = new TestScheduler();
long offset = 10;
Recorded<String> event = new Recorded<>(offset, Notification.createOnNext("Hello world!"));
ColdObservable<String> coldObservable = ColdObservable.create(scheduler, event);
final TestObserver<String> observer = new TestObserver<>();
coldObservable.subscribe(observer);
// when
scheduler.createWorker().schedule(new Runnable() {
@Override
public void run() {
observer.dispose();
}
}, 5, TimeUnit.MILLISECONDS);
// then
scheduler.advanceTimeBy(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
observer.assertNoValues();
}
示例11: should_be_cold_and_send_notification_at_subscribe_time
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_be_cold_and_send_notification_at_subscribe_time() {
// given
TestScheduler scheduler = new TestScheduler();
Recorded<String> event = new Recorded<>(0, Notification.createOnNext("Hello world!"));
final ColdObservable<String> coldObservable = ColdObservable.create(scheduler, event);
// when
final TestObserver<String> observer = new TestObserver<>();
scheduler.createWorker().schedule(new Runnable() {
@Override
public void run() {
coldObservable.subscribe(observer);
}
}, 42, TimeUnit.SECONDS);
// then
scheduler.advanceTimeBy(42, TimeUnit.SECONDS);
observer.assertValue("Hello world!");
}
示例12: should_keep_track_of_subscriptions
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_keep_track_of_subscriptions() {
// given
TestScheduler scheduler = new TestScheduler();
final ColdObservable<String> coldObservable = ColdObservable.create(scheduler);
// when
final TestObserver<String> observer = new TestObserver<>();
scheduler.createWorker().schedule(new Runnable() {
@Override
public void run() {
coldObservable.subscribe(observer);
}
}, 42, TimeUnit.MILLISECONDS);
// then
scheduler.advanceTimeBy(42, TimeUnit.MILLISECONDS);
assertThat(coldObservable.getSubscriptions())
.containsExactly(
new SubscriptionLog(42, Long.MAX_VALUE)
);
}
示例13: should_keep_track_of_unsubscriptions
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void should_keep_track_of_unsubscriptions() {
// given
TestScheduler scheduler = new TestScheduler();
final ColdObservable<String> coldObservable = ColdObservable.create(scheduler);
// when
final TestObserver<String> observer = new TestObserver<>();
coldObservable.subscribe(observer);
scheduler.createWorker().schedule(new Runnable() {
@Override
public void run() {
observer.dispose();
}
}, 42, TimeUnit.MILLISECONDS);
// then
scheduler.advanceTimeBy(42, TimeUnit.MILLISECONDS);
assertThat(coldObservable.getSubscriptions())
.containsExactly(
new SubscriptionLog(0, 42)
);
}
示例14: getTimePositionMsOnceAndStream_reportsProgressValue_whenPlaying_onEachUpdatePeriod
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void getTimePositionMsOnceAndStream_reportsProgressValue_whenPlaying_onEachUpdatePeriod() {
TestScheduler testScheduler = new TestScheduler();
ArrangeBuilder arrangeBuilder = new ArrangeBuilder()
.withTimeScheduler(testScheduler)
.withPlayingExoPlayer()
.withProgress(500L);
TestObserver<Long> testObserver = defaultObservableExoPlayer
.getTimePositionMsOnceAndStream(100L, TimeUnit.SECONDS)
.test();
testScheduler.advanceTimeBy(50L, TimeUnit.SECONDS);
arrangeBuilder.withProgress(1000L);
testObserver.assertValues(500L, 1000L);
}
示例15: shouldEmitValueAfterViewIsAttached
import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void shouldEmitValueAfterViewIsAttached() {
TestScheduler testScheduler = new TestScheduler();
BehaviorSubject<Boolean> view = BehaviorSubject.create();
view.onNext(true);
WaitViewReplayTransformer<Integer> transformer = new WaitViewReplayTransformer<>(
view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
TestObserver<Integer> testObserver = Observable.just(0)
.compose(transformer)
.test();
testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
testObserver.awaitTerminalEvent();
testObserver.assertValue(0);
testObserver.assertComplete();
}