use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onRejectedExecutionWithDataSignalDelegatesToErrorLocal.
@Test
public void onRejectedExecutionWithDataSignalDelegatesToErrorLocal() {
BiFunction<Throwable, Object, Throwable> localHook = (e, v) -> new IllegalStateException("boom_" + v, e);
Context c = Context.of(Hooks.KEY_ON_OPERATOR_ERROR, localHook);
IllegalArgumentException failure = new IllegalArgumentException("foo");
final Throwable throwable = Operators.onRejectedExecution(failure, null, null, "bar", c);
assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("boom_bar").hasNoSuppressedExceptions();
assertThat(throwable.getCause()).isInstanceOf(RejectedExecutionException.class).hasMessage("Scheduler unavailable").hasCause(failure);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onOperatorErrorLocal.
@Test
public void onOperatorErrorLocal() {
BiFunction<Throwable, Object, Throwable> localHook = (e, v) -> new IllegalStateException("boom_" + v, e);
Context c = Context.of(Hooks.KEY_ON_OPERATOR_ERROR, localHook);
IllegalArgumentException failure = new IllegalArgumentException("foo");
final Throwable throwable = Operators.onOperatorError(null, failure, "foo", c);
assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("boom_foo").hasCause(failure);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method discardCollectionStopsOnIsEmptyError.
@Test
public void discardCollectionStopsOnIsEmptyError() {
@SuppressWarnings("unchecked") List<Integer> mock = Mockito.mock(List.class);
Mockito.when(mock.isEmpty()).thenThrow(new IllegalStateException("isEmpty boom"));
AtomicInteger discardedCount = new AtomicInteger();
Context hookContext = Operators.discardLocalAdapter(Integer.class, i -> discardedCount.incrementAndGet()).apply(Context.empty());
Operators.onDiscardMultiple(mock, hookContext);
assertThat(discardedCount).hasValue(0);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method discardIteratorStopsOnIterationError.
@Test
public void discardIteratorStopsOnIterationError() {
List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5);
Iterator<Integer> trueIterator = elements.iterator();
Iterator<Integer> failingIterator = new Iterator<Integer>() {
@Override
public boolean hasNext() {
return trueIterator.hasNext();
}
@Override
public Integer next() {
Integer n = trueIterator.next();
if (n >= 3)
throw new IllegalStateException("Iterator boom");
return n;
}
};
AtomicInteger discardedCount = new AtomicInteger();
Context hookContext = Operators.discardLocalAdapter(Integer.class, i -> {
if (i == 3)
throw new IllegalStateException("boom");
discardedCount.incrementAndGet();
}).apply(Context.empty());
Operators.onDiscardMultiple(failingIterator, true, hookContext);
assertThat(discardedCount).hasValue(2);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class MonoCollectListTest method discardCancelCompleteRace.
@Test
@Tag("slow")
public void discardCancelCompleteRace() {
AtomicInteger doubleDiscardCounter = new AtomicInteger();
Context discardingContext = Operators.enableOnDiscard(null, o -> {
AtomicBoolean ab = (AtomicBoolean) o;
if (ab.getAndSet(true)) {
doubleDiscardCounter.incrementAndGet();
}
});
for (int i = 0; i < 100_000; i++) {
AssertSubscriber<List<AtomicBoolean>> testSubscriber = new AssertSubscriber<>(discardingContext);
MonoCollectListSubscriber<AtomicBoolean> subscriber = new MonoCollectListSubscriber<>(testSubscriber);
subscriber.onSubscribe(Operators.emptySubscription());
AtomicBoolean resource = new AtomicBoolean(false);
subscriber.onNext(resource);
RaceTestUtils.race(subscriber::cancel, subscriber::onComplete);
if (testSubscriber.values().isEmpty()) {
assertThat(resource).as("not completed and released %d", i).isTrue();
}
}
LOGGER.info("{} discarded twice or more in discardCancelCompleteRace", doubleDiscardCounter.get());
}
Aggregations