Search in sources :

Example 26 with Context

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);
}
Also used : Scannable(reactor.core.Scannable) BiFunction(java.util.function.BiFunction) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) Test(org.junit.Test) MultiSubscriptionSubscriber(reactor.core.publisher.Operators.MultiSubscriptionSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) CancelledSubscription(reactor.core.publisher.Operators.CancelledSubscription) Subscription(org.reactivestreams.Subscription) ScalarSubscription(reactor.core.publisher.Operators.ScalarSubscription) Exceptions(reactor.core.Exceptions) Nullable(javax.annotation.Nullable) MonoSubscriber(reactor.core.publisher.Operators.MonoSubscriber) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) EmptySubscription(reactor.core.publisher.Operators.EmptySubscription) RaceTestUtils(reactor.test.RaceTestUtils) Context(reactor.util.context.Context) Test(org.junit.Test)

Example 27 with Context

use of reactor.util.context.Context in project reactor-core by reactor.

the class OperatorsTest method onRejectedExecutionWithoutDataSignalDelegatesToErrorLocal.

@Test
public void onRejectedExecutionWithoutDataSignalDelegatesToErrorLocal() {
    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, null, c);
    assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("boom_null").hasNoSuppressedExceptions();
    assertThat(throwable.getCause()).isInstanceOf(RejectedExecutionException.class).hasMessage("Scheduler unavailable").hasCause(failure);
}
Also used : Scannable(reactor.core.Scannable) BiFunction(java.util.function.BiFunction) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) Test(org.junit.Test) MultiSubscriptionSubscriber(reactor.core.publisher.Operators.MultiSubscriptionSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) CancelledSubscription(reactor.core.publisher.Operators.CancelledSubscription) Subscription(org.reactivestreams.Subscription) ScalarSubscription(reactor.core.publisher.Operators.ScalarSubscription) Exceptions(reactor.core.Exceptions) Nullable(javax.annotation.Nullable) MonoSubscriber(reactor.core.publisher.Operators.MonoSubscriber) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) EmptySubscription(reactor.core.publisher.Operators.EmptySubscription) RaceTestUtils(reactor.test.RaceTestUtils) Context(reactor.util.context.Context) Test(org.junit.Test)

Example 28 with Context

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();
}
Also used : Context(reactor.util.context.Context) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) Test(org.junit.Test)

Example 29 with Context

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();
    }
}
Also used : Context(reactor.util.context.Context) ArrayList(java.util.ArrayList) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 30 with Context

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");
}
Also used : Context(reactor.util.context.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

Context (reactor.util.context.Context)35 Test (org.junit.Test)28 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 Consumer (java.util.function.Consumer)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 ArrayList (java.util.ArrayList)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Nullable (javax.annotation.Nullable)8 Scannable (reactor.core.Scannable)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 Function (java.util.function.Function)7 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)7 Flux (reactor.core.publisher.Flux)7 Mono (reactor.core.publisher.Mono)7 StepVerifier (reactor.test.StepVerifier)7 List (java.util.List)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Subscription (org.reactivestreams.Subscription)6 CoreSubscriber (reactor.core.CoreSubscriber)6 Exceptions (reactor.core.Exceptions)6