Search in sources :

Example 46 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 47 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 48 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)

Example 49 with Context

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);
}
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 50 with Context

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

Aggregations

Context (reactor.util.context.Context)66 Test (org.junit.jupiter.api.Test)29 Test (org.junit.Test)28 Mono (reactor.core.publisher.Mono)25 Authentication (org.springframework.security.core.Authentication)23 SecurityContext (org.springframework.security.core.context.SecurityContext)23 MethodParameter (org.springframework.core.MethodParameter)17 CurrentSecurityContext (org.springframework.security.core.annotation.CurrentSecurityContext)17 BindingContext (org.springframework.web.reactive.BindingContext)17 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 ArrayList (java.util.ArrayList)13 Consumer (java.util.function.Consumer)13 List (java.util.List)11 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)9 Collections (java.util.Collections)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Nullable (javax.annotation.Nullable)8 Flux (reactor.core.publisher.Flux)8 StepVerifier (reactor.test.StepVerifier)8