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


Java TestScheduler类代码示例

本文整理汇总了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();
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:21,代码来源:OperatorObserveOnTest.java

示例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));
}
 
开发者ID:eleventigers,项目名称:rxeither,代码行数:25,代码来源:RxEitherTest.java

示例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();
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:22,代码来源:OperatorNormalizeTest.java

示例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();
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:22,代码来源:OperatorNormalizeTest.java

示例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);
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:22,代码来源:OperatorNormalizeTest.java

示例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();
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:22,代码来源:OperatorNormalizeTest.java

示例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();
}
 
开发者ID:hzsweers,项目名称:RxNormalize,代码行数:18,代码来源:OperatorNormalizeTest.java

示例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!");
}
 
开发者ID:RxHandsOn,项目名称:MarketData,代码行数:17,代码来源:MulticastEventStreamClientTest.java

示例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);
}
 
开发者ID:akarnokd,项目名称:akarnokd-misc,代码行数:20,代码来源:ScanReplay.java

示例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);
    }
 
开发者ID:akarnokd,项目名称:akarnokd-misc,代码行数:19,代码来源:ScanReplay.java

示例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());
}
 
开发者ID:colintheshots,项目名称:AnDevCon-RxPatterns,代码行数:19,代码来源:Example16Test.java

示例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);
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:16,代码来源:WaitViewReplayTransformerTest.java

示例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();
}
 
开发者ID:alapshin,项目名称:arctor,代码行数:17,代码来源:WaitViewLatestTransformerTest.java

示例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();
}
 
开发者ID:davidmoten,项目名称:rxjava-extras,代码行数:26,代码来源:OperatorSampleFirstTest.java

示例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();
    }
}
 
开发者ID:davidmoten,项目名称:rxjava-extras,代码行数:27,代码来源:ObsTest.java


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