Search in sources :

Example 1 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class BlockingFlowableLatestTest method onError.

@SuppressWarnings("unchecked")
@Test
public void onError() {
    Iterator<Object> it = Flowable.never().blockingLatest().iterator();
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        ((Subscriber<Object>) it).onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) Subscriber(org.reactivestreams.Subscriber)

Example 2 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class MaybeDelaySubscriptionTest method withPublisherCallAfterTerminalEvent.

@Test
public void withPublisherCallAfterTerminalEvent() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable<Integer> f = new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onNext(1);
                observer.onError(new TestException());
                observer.onComplete();
                observer.onNext(2);
            }
        };
        Maybe.just(1).delaySubscription(f).test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 3 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class ParallelJoinTest method overflowSlowpath.

@Test
public void overflowSlowpath() {
    @SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            subs[0].onNext(2);
            subs[0].onNext(3);
        }
    };
    new ParallelFlowable<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer>[] subscribers) {
            subs[0] = subscribers[0];
            subscribers[0].onSubscribe(new BooleanSubscription());
            subscribers[0].onNext(1);
        }

        @Override
        public int parallelism() {
            return 1;
        }
    }.sequential(1).subscribe(ts);
    ts.assertFailure(MissingBackpressureException.class, 1);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 4 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class ParallelJoinTest method overflowSlowpathDelayError.

@Test
public void overflowSlowpathDelayError() {
    @SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            if (t == 1) {
                subs[0].onNext(2);
                subs[0].onNext(3);
            }
        }
    };
    new ParallelFlowable<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer>[] subscribers) {
            subs[0] = subscribers[0];
            subscribers[0].onSubscribe(new BooleanSubscription());
            subscribers[0].onNext(1);
        }

        @Override
        public int parallelism() {
            return 1;
        }
    }.sequentialDelayError(1).subscribe(ts);
    ts.request(1);
    ts.assertFailure(MissingBackpressureException.class, 1, 2);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 5 with Subscriber

use of org.reactivestreams.Subscriber in project camel by apache.

the class CamelPublisher method publish.

public void publish(StreamPayload<Exchange> data) {
    // freeze the subscriptions
    List<CamelSubscription> subs = new LinkedList<>(subscriptions);
    DispatchCallback<Exchange> originalCallback = data.getCallback();
    if (originalCallback != null && subs.size() > 0) {
        // When multiple subscribers have an active subscription,
        // we aknowledge the exchange once it has been delivered to every
        // subscriber (or their subscription is cancelled)
        AtomicInteger counter = new AtomicInteger(subs.size());
        // Use just the first exception in the callback when multiple exceptions are thrown
        AtomicReference<Throwable> thrown = new AtomicReference<>(null);
        data = new StreamPayload<>(data.getItem(), (ex, error) -> {
            thrown.compareAndSet(null, error);
            if (counter.decrementAndGet() == 0) {
                originalCallback.processed(ex, thrown.get());
            }
        });
    }
    if (subs.size() > 0) {
        LOG.debug("Exchange published to {} subscriptions for the stream {}: {}", subs.size(), name, data.getItem());
        // at least one subscriber
        for (CamelSubscription sub : subs) {
            sub.publish(data);
        }
    } else {
        data.getCallback().processed(data.getItem(), new IllegalStateException("The stream has no active subscriptions"));
    }
}
Also used : Exchange(org.apache.camel.Exchange) CamelContext(org.apache.camel.CamelContext) ReactiveStreamsBackpressureStrategy(org.apache.camel.component.reactive.streams.ReactiveStreamsBackpressureStrategy) Logger(org.slf4j.Logger) Publisher(org.reactivestreams.Publisher) ReactiveStreamsProducer(org.apache.camel.component.reactive.streams.ReactiveStreamsProducer) LoggerFactory(org.slf4j.LoggerFactory) Exchange(org.apache.camel.Exchange) DispatchCallback(org.apache.camel.component.reactive.streams.api.DispatchCallback) AtomicReference(java.util.concurrent.atomic.AtomicReference) Objects(java.util.Objects) ReactiveStreamsEndpoint(org.apache.camel.component.reactive.streams.ReactiveStreamsEndpoint) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReactiveStreamsComponent(org.apache.camel.component.reactive.streams.ReactiveStreamsComponent) LinkedList(java.util.LinkedList) Subscriber(org.reactivestreams.Subscriber) ExecutorService(java.util.concurrent.ExecutorService) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) LinkedList(java.util.LinkedList)

Aggregations

Subscriber (org.reactivestreams.Subscriber)104 Subscription (org.reactivestreams.Subscription)67 Test (org.junit.Test)56 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)29 List (java.util.List)26 Publisher (org.reactivestreams.Publisher)23 ProtonClient (io.vertx.proton.ProtonClient)22 ProtonConnection (io.vertx.proton.ProtonConnection)22 Message (org.apache.qpid.proton.message.Message)20 Arrays (java.util.Arrays)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)18 ArrayList (java.util.ArrayList)17 Handler (io.vertx.core.Handler)16 Logger (io.vertx.core.impl.logging.Logger)16 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)16 ProtonStreams (io.vertx.proton.streams.ProtonStreams)16 ExecutionException (java.util.concurrent.ExecutionException)16 Symbol (org.apache.qpid.proton.amqp.Symbol)16