Search in sources :

Example 1 with Context

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

the class FluxReceive method onInboundError.

final void onInboundError(Throwable err) {
    if (isCancelled() || inboundDone) {
        Context c = receiver == null ? Context.empty() : receiver.currentContext();
        Operators.onErrorDropped(err, c);
        return;
    }
    CoreSubscriber<?> receiver = this.receiver;
    this.inboundError = err;
    this.inboundDone = true;
    if (channel.isActive()) {
        channel.close();
    }
    if (receiverFastpath && receiver != null) {
        parent.context.fireContextError(err);
        receiver.onError(err);
    } else {
        drainReceiver();
    }
}
Also used : Context(reactor.util.context.Context)

Example 2 with Context

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

the class MonoSubscriberContext method subscribe.

@Override
public void subscribe(CoreSubscriber<? super T> actual) {
    Context c;
    try {
        c = doOnContext.apply(actual.currentContext());
    } catch (Throwable t) {
        Operators.error(actual, Operators.onOperatorError(t, actual.currentContext()));
        return;
    }
    source.subscribe(new FluxContextStart.ContextStartSubscriber<>(actual, c));
}
Also used : Context(reactor.util.context.Context)

Example 3 with Context

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

the class MonoCurrentContext method subscribe.

@SuppressWarnings("unchecked")
public void subscribe(CoreSubscriber<? super Context> actual) {
    Context ctx = actual.currentContext();
    actual.onSubscribe(Operators.scalarSubscription(actual, ctx));
}
Also used : Context(reactor.util.context.Context)

Example 4 with Context

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

the class DefaultContextExpectationsTest method notContainsOnlyOfContextContent.

@Test
public void notContainsOnlyOfContextContent() throws Exception {
    Context expected = Context.of("foo", "bar", "other", "stuff");
    assertContextExpectationFails(s -> s.subscriberContext(Context.of("foo", "bar", "foobar", "baz")), e -> e.containsOnly(expected)).withMessage("Expected Context Context2{foo=bar, foobar=baz} to contain " + "same values as Context2{foo=bar, other=stuff}, but they differ in content");
}
Also used : Context(reactor.util.context.Context) ThrowableAssertAlternative(org.assertj.core.api.ThrowableAssertAlternative) Step(reactor.test.StepVerifier.Step) Context(reactor.util.context.Context) HashMap(java.util.HashMap) Test(org.junit.Test) DefaultContextExpectations(reactor.test.DefaultStepVerifierBuilder.DefaultContextExpectations) Function(java.util.function.Function) Objects(java.util.Objects) Flux(reactor.core.publisher.Flux) ContextExpectations(reactor.test.StepVerifier.ContextExpectations) Map(java.util.Map) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Assertions(org.assertj.core.api.Assertions) Collections(java.util.Collections) Test(org.junit.Test)

Example 5 with Context

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

the class DefaultStepVerifierBuilder method expectNoAccessibleContext.

@Override
public DefaultStepVerifierBuilder<T> expectNoAccessibleContext() {
    return consumeSubscriptionWith(sub -> {
        Scannable lowest = Scannable.from(sub);
        Scannable verifierSubscriber = Scannable.from(lowest.scan(Scannable.Attr.ACTUAL));
        Context c = Flux.fromStream(verifierSubscriber.parents()).ofType(CoreSubscriber.class).map(CoreSubscriber::currentContext).blockLast();
        if (c != null) {
            throw errorFormatter.assertionError("Expected no accessible Context, got " + c);
        }
    });
}
Also used : Context(reactor.util.context.Context) Scannable(reactor.core.Scannable)

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