use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onDiscardCallbackErrorsLog.
@Test
public void onDiscardCallbackErrorsLog() {
Context context = Operators.enableOnDiscard(Context.empty(), t -> {
throw new RuntimeException("Boom");
});
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
Operators.onDiscard("Foo", context);
assertThat(testLogger.getErrContent()).contains("Error in discard hook - java.lang.RuntimeException: Boom");
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method discardStreamContinuesWhenElementFailsToBeDiscarded.
@Test
public void discardStreamContinuesWhenElementFailsToBeDiscarded() {
Stream<Integer> stream = Stream.of(1, 2, 3, 4, 5);
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(stream, hookContext);
assertThat(discardedCount).hasValue(4);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method discardQueueWithClearContinuesOnExtractionError.
@Test
public void discardQueueWithClearContinuesOnExtractionError() {
AtomicInteger discardedCount = new AtomicInteger();
Context hookContext = Operators.discardLocalAdapter(Integer.class, i -> {
if (i == 3)
throw new IllegalStateException("boom");
discardedCount.incrementAndGet();
}).apply(Context.empty());
Queue<List<Integer>> q = new ArrayBlockingQueue<>(5);
q.add(Collections.singletonList(1));
q.add(Collections.singletonList(2));
q.add(Arrays.asList(3, 30));
q.add(Collections.singletonList(4));
q.add(Collections.singletonList(5));
Operators.onDiscardQueueWithClear(q, hookContext, o -> {
List<Integer> l = o;
if (l.size() == 2)
throw new IllegalStateException("boom in extraction");
return l.stream();
});
assertThat(discardedCount).hasValue(4);
}
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");
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);
}
Aggregations