Java Code Examples for com.github.davidmoten.rx.Transformers#stateMachine()
The following examples show how to use
com.github.davidmoten.rx.Transformers#stateMachine() .
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: TransformerStateMachineTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
@Test public void testStateTransitionThrowsError() { final RuntimeException ex = new RuntimeException("boo"); Func0<Integer> initialState = Functions.constant0(1); Func3<Integer, Integer, Observer<Integer>, Integer> transition = new Func3<Integer, Integer, Observer<Integer>, Integer>() { @Override public Integer call(Integer collection, Integer t, Observer<Integer> observer) { throw ex; } }; Func2<Integer, Observer<Integer>, Boolean> completion = Functions.alwaysTrue2(); Transformer<Integer, Integer> transformer = Transformers.stateMachine(initialState, transition, completion); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Observable.just(1, 1, 1).compose(transformer).subscribe(ts); ts.awaitTerminalEvent(); ts.assertError(ex); }
Example 2
Source File: TransformerStateMachineTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
@Test public void testUnsubscriptionFromTransition() { Func0<Integer> initialState = Functions.constant0(1); Func3<Integer, Integer, Subscriber<Integer>, Integer> transition = new Func3<Integer, Integer, Subscriber<Integer>, Integer>() { @Override public Integer call(Integer collection, Integer t, Subscriber<Integer> subscriber) { subscriber.onNext(123); subscriber.unsubscribe(); return 1; } }; Func2<Integer, Observer<Integer>, Boolean> completion = Functions.alwaysTrue2(); Transformer<Integer, Integer> transformer = Transformers.stateMachine(initialState, transition, completion); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Observable.just(1, 1, 1).repeat().compose(transformer).subscribe(ts); ts.assertValue(123); ts.assertCompleted(); ts.assertUnsubscribed(); }
Example 3
Source File: TransformerStateMachineTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
@Test public void testForCompletionWithinStateMachine() { Func0<Integer> initialState = Functions.constant0(1); Func3<Integer, Integer, Subscriber<Integer>, Integer> transition = new Func3<Integer, Integer, Subscriber<Integer>, Integer>() { @Override public Integer call(Integer collection, Integer t, Subscriber<Integer> subscriber) { subscriber.onNext(123); // complete from within transition subscriber.onCompleted(); return 1; } }; Func2<? super Integer, ? super Subscriber<Integer>, Boolean> completion = Functions .alwaysTrue2(); Transformer<Integer, Integer> transformer = Transformers.stateMachine(initialState, transition, completion); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); final AtomicInteger count = new AtomicInteger(0); Observable.just(1, 2, 3).doOnNext(Actions.increment1(count)).compose(transformer) .subscribe(ts); ts.assertValues(123); ts.assertCompleted(); assertEquals(1, count.get()); }