use of org.reactivestreams.Subscription in project jersey by jersey.
the class RxFlowableTest method testInvoker.
private void testInvoker(final RxFlowableInvoker rx, final int expectedStatus, final boolean testDedicatedThread) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Response> responseRef = new AtomicReference<>();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
rx.get().subscribe(new Subscriber<Response>() {
@Override
public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE);
}
@Override
public void onComplete() {
latch.countDown();
}
@Override
public void onError(final Throwable e) {
errorRef.set(e);
latch.countDown();
}
@Override
public void onNext(final Response response) {
responseRef.set(response);
}
});
latch.await();
if (errorRef.get() == null) {
testResponse(responseRef.get(), expectedStatus, testDedicatedThread);
} else {
throw (Exception) errorRef.get();
}
}
use of org.reactivestreams.Subscription in project RxJava by ReactiveX.
the class FutureSubscriber method onError.
@Override
public void onError(Throwable t) {
for (; ; ) {
Subscription a = s.get();
if (a == this || a == SubscriptionHelper.CANCELLED) {
RxJavaPlugins.onError(t);
return;
}
error = t;
if (s.compareAndSet(a, this)) {
countDown();
return;
}
}
}
use of org.reactivestreams.Subscription in project RxJava by ReactiveX.
the class SubscriptionArbiter method request.
@Override
public final void request(long n) {
if (SubscriptionHelper.validate(n)) {
if (unbounded) {
return;
}
if (get() == 0 && compareAndSet(0, 1)) {
long r = requested;
if (r != Long.MAX_VALUE) {
r = BackpressureHelper.addCap(r, n);
requested = r;
if (r == Long.MAX_VALUE) {
unbounded = true;
}
}
Subscription a = actual;
if (decrementAndGet() != 0) {
drainLoop();
}
if (a != null) {
a.request(n);
}
return;
}
BackpressureHelper.add(missedRequested, n);
drain();
}
}
use of org.reactivestreams.Subscription in project RxJava by ReactiveX.
the class FlowableDelaySubscriptionOtherTest method testNoSubscriptionIfOtherErrors.
@Test
public void testNoSubscriptionIfOtherErrors() {
PublishProcessor<Object> other = PublishProcessor.create();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Flowable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription s) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(ts);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onError(new TestException());
Assert.assertEquals("Premature subscription", 0, subscribed.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of org.reactivestreams.Subscription in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextViaFunctionTest method testFunctionThrowsError.
/**
* Test that when a function throws an exception this is propagated through onError.
*/
@Test
public void testFunctionThrowsError() {
Subscription s = mock(Subscription.class);
TestObservable w = new TestObservable(s, "one");
Function<Throwable, Observable<String>> resume = new Function<Throwable, Observable<String>>() {
@Override
public Observable<String> apply(Throwable t1) {
throw new RuntimeException("exception from function");
}
};
Observable<String> o = Observable.unsafeCreate(w).onErrorResumeNext(resume);
@SuppressWarnings("unchecked") DefaultObserver<String> observer = mock(DefaultObserver.class);
o.subscribe(observer);
try {
w.t.join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
// we should get the "one" value before the error
verify(observer, times(1)).onNext("one");
// we should have received an onError call on the Observer since the resume function threw an exception
verify(observer, times(1)).onError(any(Throwable.class));
verify(observer, times(0)).onComplete();
}
Aggregations