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();
}
}
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();
}
}
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);
}
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);
}
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"));
}
}
Aggregations