use of org.reactivestreams.Subscriber in project resilience4j by resilience4j.
the class RateLimiterSubscriberTest method shouldHonorCancelledWhenCallingOnNext.
@Test
public void shouldHonorCancelledWhenCallingOnNext() throws Exception {
// Given
Subscription subscription = mock(Subscription.class);
Subscriber childSubscriber = mock(Subscriber.class);
Subscriber decoratedSubscriber = RateLimiterOperator.of(rateLimiter).apply(childSubscriber);
decoratedSubscriber.onSubscribe(subscription);
// When
((Subscription) decoratedSubscriber).cancel();
decoratedSubscriber.onNext(1);
// Then
verify(childSubscriber, never()).onNext(any());
assertSinglePermitUsed();
}
use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class FlowableCollectWithCollectorTest method collectorAccumulatorDropSignalsToFlowable.
@Test
public void collectorAccumulatorDropSignalsToFlowable() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Flowable<Integer> source = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
};
source.collect(new Collector<Integer, Integer, Integer>() {
@Override
public Supplier<Integer> supplier() {
return () -> 1;
}
@Override
public BiConsumer<Integer, Integer> accumulator() {
return (a, b) -> {
throw new TestException();
};
}
@Override
public BinaryOperator<Integer> combiner() {
return (a, b) -> a + b;
}
@Override
public Function<Integer, Integer> finisher() {
return a -> a;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
}).toFlowable().test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
});
}
use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class FlowableMapOptionalTest method crashDropsOnNexts.
@Test
public void crashDropsOnNexts() {
Flowable<Integer> source = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
}
};
source.mapOptional(v -> {
throw new TestException();
}).test().assertFailure(TestException.class);
}
use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class FlowableMapOptionalTest method crashDropsOnNextsConditional.
@Test
public void crashDropsOnNextsConditional() {
Flowable<Integer> source = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
}
};
source.mapOptional(v -> {
throw new TestException();
}).filter(v -> true).test().assertFailure(TestException.class);
}
use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class ParallelJoinTest method onNextMissingBackpressureRace.
@Test
public void onNextMissingBackpressureRace() throws Throwable {
TestHelper.withErrorTracking(errors -> {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
AtomicReference<Subscriber<? super Integer>> ref1 = new AtomicReference<>();
AtomicReference<Subscriber<? super Integer>> ref2 = new AtomicReference<>();
Flowable<Integer> f1 = new Flowable<Integer>() {
@Override
public void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
ref1.set(s);
}
};
Flowable<Integer> f2 = new Flowable<Integer>() {
@Override
public void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
ref2.set(s);
}
};
ParallelFlowable.fromArray(f1, f2).sequential(1).test(0);
TestHelper.race(() -> {
ref1.get().onNext(1);
ref1.get().onNext(2);
}, () -> {
ref2.get().onNext(3);
ref2.get().onNext(4);
});
errors.clear();
}
});
}
Aggregations