use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onNextFailureWithStrategyNotMatchingDoesCancel.
@Test
public void onNextFailureWithStrategyNotMatchingDoesCancel() {
Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, new OnNextFailureStrategy() {
@Override
public boolean test(Throwable error, @Nullable Object value) {
return false;
}
@Override
public Throwable process(Throwable error, @Nullable Object value, Context context) {
return error;
}
});
Operators.DeferredSubscription s = new Operators.DeferredSubscription();
Throwable t = Operators.onNextError("foo", new NullPointerException("bar"), context, s);
assertThat(t).as("exception processed").isNotNull().isInstanceOf(NullPointerException.class).hasNoSuppressedExceptions().hasNoCause();
assertThat(s.isCancelled()).as("subscription cancelled").isTrue();
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method pollErrorModeLocalStrategy.
@Test
public void pollErrorModeLocalStrategy() {
List<Object> nextDropped = new ArrayList<>();
List<Object> errorDropped = new ArrayList<>();
Hooks.onNextDropped(nextDropped::add);
Hooks.onErrorDropped(errorDropped::add);
Context c = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.RESUME_DROP);
Exception error = new IllegalStateException("boom");
try {
assertThat(Hooks.onNextErrorHook).as("no global hook").isNull();
RuntimeException e = Operators.onNextPollError("foo", error, c);
assertThat(e).isNull();
assertThat(nextDropped).containsExactly("foo");
assertThat(errorDropped).containsExactly(error);
} finally {
Hooks.resetOnNextDropped();
Hooks.resetOnErrorDropped();
}
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onErrorDroppedLocal.
@Test
public void onErrorDroppedLocal() {
AtomicReference<Throwable> hookState = new AtomicReference<>();
Consumer<Throwable> localHook = hookState::set;
Context c = Context.of(Hooks.KEY_ON_ERROR_DROPPED, localHook);
Operators.onErrorDropped(new IllegalArgumentException("boom"), c);
assertThat(hookState.get()).isInstanceOf(IllegalArgumentException.class).hasMessage("boom");
}
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 SignalTest method completeWithContextCreatesNewInstances.
@Test
public void completeWithContextCreatesNewInstances() {
Context context = Context.of("foo", "bar");
assertThat(Signal.complete(context)).isNotSameAs(Signal.complete(context)).isNotSameAs(Signal.complete()).isEqualTo(Signal.complete()).isEqualTo(Signal.complete(context));
}
Aggregations