本文整理汇总了Java中rx.schedulers.TestScheduler类的典型用法代码示例。如果您正苦于以下问题:Java TestScheduler类的具体用法?Java TestScheduler怎么用?Java TestScheduler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TestScheduler类属于rx.schedulers包,在下文中一共展示了TestScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() {
TestScheduler testScheduler = new TestScheduler();
Observable<Integer> source = Observable.concat(Observable.<Integer> error(new TestException()), Observable.just(1));
@SuppressWarnings("unchecked")
Observer<Integer> o = mock(Observer.class);
InOrder inOrder = inOrder(o);
source.observeOn(testScheduler).subscribe(o);
inOrder.verify(o, never()).onError(any(TestException.class));
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
inOrder.verify(o).onError(any(TestException.class));
inOrder.verify(o, never()).onNext(anyInt());
inOrder.verify(o, never()).onComplete();
}
示例2: multipleLeftTerminalRightOtherThread
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void multipleLeftTerminalRightOtherThread() {
TestScheduler otherScheduler = Schedulers.test();
TestSubject<EventB> eventBSubject = TestSubject.create(otherScheduler);
Observable<Either<EventA, EventB>> either = RxEither.from(eventASubject, eventBSubject);
either.subscribe(subscriber);
eventASubject.onNext(eventA);
eventBSubject.onNext(eventB);
eventBSubject.onCompleted();
eventASubject.onNext(eventA);
testScheduler.triggerActions();
subscriber.assertNotCompleted();
otherScheduler.triggerActions();
subscriber.assertNoErrors();
subscriber.assertCompleted();
subscriber.assertUnsubscribed();
subscriber.assertValues(Either.<EventA, EventB>left(eventA),
Either.<EventA, EventB>left(eventA),
Either.<EventA, EventB>right(eventB));
}
示例3: basic
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void basic() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> subject = PublishSubject.create();
RecordingObserver<Integer> o = new RecordingObserver<>();
subject
.lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
.subscribe(o);
subject.onNext(0);
o.takeNext();
subject.onNext(1);
o.assertNoMoreEvents();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
o.takeNext();
subject.onCompleted();
o.assertOnCompleted();
}
示例4: completion
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void completion() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> subject = PublishSubject.create();
RecordingObserver<Integer> o = new RecordingObserver<>();
subject
.lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
.subscribe(o);
// First emits immediately
subject.onNext(0);
o.takeNext();
subject.onNext(1);
subject.onCompleted();
o.assertNoMoreEvents();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
o.takeNext();
o.assertOnCompleted();
}
示例5: error
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void error() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> subject = PublishSubject.create();
RecordingObserver<Integer> o = new RecordingObserver<>();
subject
.lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
.subscribe(o);
// First emits immediately
subject.onNext(0);
o.takeNext();
subject.onNext(1);
subject.onError(new RuntimeException("Blah"));
o.assertNoMoreEvents();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
o.takeNext();
assertThat(o.takeError()).isInstanceOf(RuntimeException.class);
}
示例6: unsubscription
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void unsubscription() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> subject = PublishSubject.create();
RecordingObserver<Integer> o = new RecordingObserver<>();
Subscription sub = subject
.lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
.subscribe(o);
// First emits immediately
subject.onNext(0);
o.takeNext();
subject.onNext(1);
o.assertNoMoreEvents();
sub.unsubscribe();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
o.assertNoMoreEvents();
}
示例7: overDelay_shouldEmitImmediately
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void overDelay_shouldEmitImmediately() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> subject = PublishSubject.create();
RecordingObserver<Integer> o = new RecordingObserver<>();
subject
.lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
.subscribe(o);
// First emits immediately
subject.onNext(0);
o.takeNext();
scheduler.advanceTimeBy(2, TimeUnit.SECONDS);
subject.onNext(1);
o.takeNext();
}
示例8: Should_transmit_events_from_the_target_client
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void Should_transmit_events_from_the_target_client() {
// given
TestScheduler scheduler = Schedulers.test();
PublishSubject<String> subject = PublishSubject.create();
EventStreamClient targetClient = mock(EventStreamClient.class);
when(targetClient.readServerSideEvents()).thenReturn(subject);
MulticastEventStreamClient multicastEventStreamClient = new MulticastEventStreamClient(targetClient, scheduler);
Observable<String> events = multicastEventStreamClient.readServerSideEvents();
// when
TestSubscriber<String> subscriber = new TestSubscriber<>();
events.subscribe(subscriber);
subject.onNext("Hello!");
// then
assertThat(subscriber.getOnNextEvents()).hasSize(1).contains("Hello!");
}
示例9: testExpectedReplayBehavior
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void testExpectedReplayBehavior() {
final TestScheduler scheduler = new TestScheduler();
final TestSubject<Integer> subject = TestSubject.create(scheduler);
final TestSubscriber<Integer> subscriber = new TestSubscriber<>();
final ConnectableObservable<Integer> sums = subject.scan((a, b) -> a + b).replay(1);
sums.connect();
subject.onNext(1);
subject.onNext(2);
subject.onNext(3);
scheduler.triggerActions();
sums.subscribe(subscriber);
subscriber.assertValueCount(1);
subscriber.assertValues(6);
}
示例10: testFlakyReplayBehavior
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void testFlakyReplayBehavior() {
final TestScheduler scheduler = new TestScheduler();
final TestSubject<Integer> subject = TestSubject.create(scheduler);
final TestSubscriber<Integer> subscriber = new TestSubscriber<>();
final ConnectableObservable<Integer> sums = subject.scan(1, (a, b) -> a + b).replay(1);
sums.connect();
subject.onNext(2);
subject.onNext(3);
scheduler.triggerActions();
sums.subscribe(subscriber);
// subscriber.assertValueCount(1);
subscriber.assertValues(6);
}
示例11: should_test_observable_interval
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_test_observable_interval() {
TestScheduler scheduler = new TestScheduler();
final List<Long> result = new ArrayList<>();
Observable.interval(1, TimeUnit.SECONDS, scheduler)
.take(5)
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
result.add(aLong);
}
});
assertTrue(result.isEmpty());
scheduler.advanceTimeBy(2, TimeUnit.SECONDS);
assertEquals(2, result.size());
scheduler.advanceTimeBy(10, TimeUnit.SECONDS);
assertEquals(5, result.size());
}
示例12: shouldEmitErrorAfterViewIsAttached
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void shouldEmitErrorAfterViewIsAttached() {
TestScheduler testScheduler = Schedulers.test();
BehaviorSubject<Boolean> view = BehaviorSubject.create();
view.onNext(true);
WaitViewReplayTransformer<Object> transformer = new WaitViewReplayTransformer<>(
view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
TestSubscriber<Object> testSubscriber = new TestSubscriber<>();
Observable.error(new RuntimeException())
.compose(transformer)
.subscribe(testSubscriber);
testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertError(RuntimeException.class);
}
示例13: shouldEmitValueAfterViewIsAttached
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void shouldEmitValueAfterViewIsAttached() {
TestScheduler testScheduler = Schedulers.test();
BehaviorSubject<Boolean> view = BehaviorSubject.create();
view.onNext(true);
WaitViewLatestTransformer<Integer> transformer =
new WaitViewLatestTransformer<>(view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
Observable.just(0)
.compose(transformer)
.subscribe(testSubscriber);
testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertValue(0);
testSubscriber.assertCompleted();
}
示例14: testSampleWindowIsConstantDuration
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void testSampleWindowIsConstantDuration() {
@SuppressWarnings("unchecked")
Observer<Integer> observer = mock(Observer.class);
TestScheduler s = new TestScheduler();
PublishSubject<Integer> o = PublishSubject.create();
o.compose(Transformers.<Integer> sampleFirst(1000, TimeUnit.MILLISECONDS, s))
.subscribe(observer);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
o.onNext(1);
s.advanceTimeTo(1200, TimeUnit.MILLISECONDS);
o.onNext(2);
s.advanceTimeTo(2100, TimeUnit.MILLISECONDS);
o.onNext(3);
o.onCompleted();
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onNext(1);
inOrder.verify(observer).onNext(2);
inOrder.verify(observer).onNext(3);
inOrder.verify(observer).onCompleted();
inOrder.verifyNoMoreInteractions();
}
示例15: testCachedScheduledReset
import rx.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void testCachedScheduledReset() {
TestScheduler scheduler = new TestScheduler();
Worker worker = scheduler.createWorker();
try {
final AtomicInteger count = new AtomicInteger(0);
Observable<Integer> source = Observable.defer(new Func0<Observable<Integer>>() {
@Override
public Observable<Integer> call() {
return Observable.just(count.incrementAndGet());
}
})
// cache
.compose(Transformers.<Integer> cache(5, TimeUnit.MINUTES, worker));
assertEquals(1, (int) source.toBlocking().single());
scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
assertEquals(1, (int) source.toBlocking().single());
scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
assertEquals(1, (int) source.toBlocking().single());
scheduler.advanceTimeBy(3, TimeUnit.MINUTES);
assertEquals(2, (int) source.toBlocking().single());
assertEquals(2, (int) source.toBlocking().single());
} finally {
worker.unsubscribe();
}
}