Search in sources :

Example 16 with Action2

use of rx.functions.Action2 in project nucleus by konmik.

the class DeliverFirstTest method testOnce.

@Test
public void testOnce() throws Exception {
    PublishSubject<Object> view = PublishSubject.create();
    final TestSubscriber<Delivery<Object, Integer>> testSubscriber = new TestSubscriber<>();
    ArrayList<Delivery<Object, Integer>> deliveries = new ArrayList<>();
    final PublishSubject<Integer> subject = PublishSubject.create();
    DeliverFirst<Object, Integer> restartable = new DeliverFirst<>(view);
    Subscription subscription = restartable.call(subject).subscribe(new Action1<Delivery<Object, Integer>>() {

        @Override
        public void call(Delivery<Object, Integer> delivery) {
            delivery.split(new Action2<Object, Integer>() {

                @Override
                public void call(Object o, Integer integer) {
                    testSubscriber.onNext(new Delivery<>(o, Notification.createOnNext(integer)));
                }
            }, new Action2<Object, Throwable>() {

                @Override
                public void call(Object o, Throwable throwable) {
                    testSubscriber.onNext(new Delivery<>(o, Notification.<Integer>createOnError(throwable)));
                }
            });
        }
    });
    // only first value is delivered
    subject.onNext(1);
    subject.onNext(2);
    subject.onNext(3);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertNoValues();
    view.onNext(100);
    deliveries.add(new Delivery<Object, Integer>(100, Notification.createOnNext(1)));
    testSubscriber.assertValueCount(1);
    // no values delivered if a view has been detached
    view.onNext(null);
    testSubscriber.assertValueCount(1);
    // the latest value will not be delivered to the new view
    view.onNext(101);
    testSubscriber.assertValueCount(1);
    // successive values will be ignored
    subject.onNext(4);
    testSubscriber.assertValueCount(1);
    // final checks
    testSubscriber.assertReceivedOnNext(deliveries);
    subscription.unsubscribe();
    assertFalse(subject.hasObservers());
    assertFalse(view.hasObservers());
}
Also used : Action2(rx.functions.Action2) ArrayList(java.util.ArrayList) TestSubscriber(rx.observers.TestSubscriber) Subscription(rx.Subscription) Test(org.junit.Test)

Example 17 with Action2

use of rx.functions.Action2 in project nucleus by konmik.

the class DeliveryTest method testWithOnNextOnError.

private void testWithOnNextOnError(Action2<Action2, Action2> test) {
    Action2 onNext = mock(Action2.class);
    Action2 onError = mock(Action2.class);
    test.call(onNext, onError);
    verifyNoMoreInteractions(onNext);
    verifyNoMoreInteractions(onError);
}
Also used : Action2(rx.functions.Action2)

Aggregations

Action2 (rx.functions.Action2)17 Test (org.junit.Test)15 Subscription (rx.Subscription)15 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)11 HttpMethod (io.netty.handler.codec.http.HttpMethod)11 URI (java.net.URI)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 DefaultHttpClient (org.jocean.http.client.impl.DefaultHttpClient)11 TestChannelCreator (org.jocean.http.client.impl.TestChannelCreator)11 TestChannelPool (org.jocean.http.client.impl.TestChannelPool)11 DefaultSignalClient (org.jocean.http.rosa.impl.DefaultSignalClient)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 SignalClient (org.jocean.http.rosa.SignalClient)5 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)4 TestSubscriber (rx.observers.TestSubscriber)4 HttpObject (io.netty.handler.codec.http.HttpObject)3 POST (javax.ws.rs.POST)3 FileUpload (io.netty.handler.codec.http.multipart.FileUpload)1