Java Code Examples for rx.schedulers.TestScheduler#triggerActions()

The following examples show how to use rx.schedulers.TestScheduler#triggerActions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwsObservableExtTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void asyncActionCompletable() throws Exception {
    AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP;
    final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response");
    final Completable completable = AwsObservableExt.asyncActionCompletable(factory -> client.someAsyncOperation(factory.handler(
            (req, resp) -> {
                assertEquals(someRequest, req);
                assertEquals("some response", resp);
            },
            (t) -> {
                throw new IllegalStateException("Should never be here");
            }
    )));

    TestScheduler testScheduler = Schedulers.test();
    final AssertableSubscriber<Void> subscriber = completable.subscribeOn(testScheduler).test();

    testScheduler.triggerActions();
    subscriber.assertNotCompleted();

    client.run();
    testScheduler.triggerActions();
    subscriber.assertCompleted();
}
 
Example 2
Source File: AwsObservableExtTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void asyncActionSingle() throws Exception {
    AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP;
    final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response");
    Single<String> single = AwsObservableExt.asyncActionSingle(supplier -> client.someAsyncOperation(supplier.handler()));

    TestScheduler testScheduler = Schedulers.test();
    final AssertableSubscriber<String> subscriber = single.subscribeOn(testScheduler).test();

    testScheduler.triggerActions();
    subscriber.assertNoValues();
    subscriber.assertNotCompleted();

    client.run();
    testScheduler.triggerActions();
    subscriber.assertValueCount(1);
    subscriber.assertValue("some response");
    subscriber.assertCompleted();
}
 
Example 3
Source File: ScanReplay.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: ScanReplay.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
@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);
    }
 
Example 5
Source File: TransformersTest.java    From mobius with Apache License 2.0 5 votes vote down vote up
@Test
public void effectPerformerInvokesFunctionWithReceivedEffectAndEmitsReturnedEvents() {
  PublishSubject<String> upstream = PublishSubject.create();
  TestScheduler scheduler = new TestScheduler();
  Function<String, Integer> function = s -> s.length();
  AssertableSubscriber<Integer> observer =
      upstream.compose(Transformers.fromFunction(function, scheduler)).test();

  upstream.onNext("Hello");
  scheduler.triggerActions();
  observer.assertValue(5);
}
 
Example 6
Source File: TransformersTest.java    From mobius with Apache License 2.0 5 votes vote down vote up
@Test
public void effectPerformerInvokesFunctionWithReceivedEffectAndErrorsForUnhandledExceptions() {
  PublishSubject<String> upstream = PublishSubject.create();
  TestScheduler scheduler = new TestScheduler();
  Function<String, Integer> function =
      s -> {
        throw new RuntimeException("Something bad happened");
      };
  AssertableSubscriber<Integer> observer =
      upstream.compose(Transformers.fromFunction(function, scheduler)).test();

  upstream.onNext("Hello");
  scheduler.triggerActions();
  observer.assertError(RuntimeException.class);
}
 
Example 7
Source File: AwsObservableExtTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncActionCompletableErrors() {
    AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP;
    final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response");
    RuntimeException exception = new RuntimeException("error when initiating an async operation");
    final Completable completable = AwsObservableExt.asyncActionCompletable(factory -> client.throwException(exception));

    TestScheduler testScheduler = Schedulers.test();
    final AssertableSubscriber<Void> subscriber = completable.subscribeOn(testScheduler).test();

    testScheduler.triggerActions();
    subscriber.assertError(exception);
}
 
Example 8
Source File: AwsObservableExtTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncActionSingleErrors() {
    AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP;
    final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response");
    RuntimeException exception = new RuntimeException("error when initiating an async operation");
    final Single<String> completable = AwsObservableExt.asyncActionSingle(supplier -> client.throwException(exception));

    TestScheduler testScheduler = Schedulers.test();
    final AssertableSubscriber<String> subscriber = completable.subscribeOn(testScheduler).test();

    testScheduler.triggerActions();
    subscriber.assertError(exception);
}