Upgrade to Micrometer context-propagation snapshots

Closes gh-477
This commit is contained in:
rstoyanchev
2022-09-06 12:33:56 +01:00
parent 2b829dbe07
commit 973fc567f3
16 changed files with 20 additions and 20 deletions

View File

@@ -23,7 +23,7 @@ dependencies {
constraints {
api("com.graphql-java:graphql-java:${graphQlJavaVersion}")
api("io.micrometer:context-propagation:1.0.0-M4")
api("io.micrometer:context-propagation:1.0.0-SNAPSHOT")
api("jakarta.annotation:jakarta.annotation-api:2.0.0")
api("jakarta.servlet:jakarta.servlet-api:5.0.0")

View File

@@ -114,7 +114,7 @@ public abstract class InvocableHandlerMethodSupport extends HandlerMethod {
return CompletableFuture.supplyAsync(
() -> {
try {
return ContextSnapshot.capture(graphQLContext).wrap((Callable<?>) result).call();
return ContextSnapshot.captureFrom(graphQLContext).wrap((Callable<?>) result).call();
}
catch (Exception ex) {
throw new IllegalStateException(

View File

@@ -70,7 +70,7 @@ final class ContextDataFetcherDecorator implements DataFetcher<Object> {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
ContextSnapshot snapshot = ContextSnapshot.capture(environment.getGraphQlContext());
ContextSnapshot snapshot = ContextSnapshot.captureFrom(environment.getGraphQlContext());
Object value = snapshot.wrap(() -> this.delegate.get(environment)).call();
if (this.subscription) {

View File

@@ -98,7 +98,7 @@ public abstract class DataFetcherExceptionResolverAdapter implements DataFetcher
return resolveToMultipleErrors(exception, env);
}
try {
return ContextSnapshot.capture(env.getGraphQlContext())
return ContextSnapshot.captureFrom(env.getGraphQlContext())
.wrap(() -> resolveToMultipleErrors(exception, env))
.call();
}

View File

@@ -190,7 +190,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry {
@Override
public CompletionStage<List<V>> load(List<K> keys, BatchLoaderEnvironment environment) {
GraphQLContext graphQLContext = environment.getContext();
ContextSnapshot snapshot = ContextSnapshot.capture(graphQLContext);
ContextSnapshot snapshot = ContextSnapshot.captureFrom(graphQLContext);
try {
return snapshot.wrap(() ->
this.loader.apply(keys, environment)
@@ -245,7 +245,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry {
@Override
public CompletionStage<Map<K, V>> load(Set<K> keys, BatchLoaderEnvironment environment) {
GraphQLContext graphQLContext = environment.getContext();
ContextSnapshot snapshot = ContextSnapshot.capture(graphQLContext);
ContextSnapshot snapshot = ContextSnapshot.captureFrom(graphQLContext);
try {
return snapshot.wrap(() ->
this.loader.apply(keys, environment)

View File

@@ -77,7 +77,7 @@ public class DefaultExecutionGraphQlService implements ExecutionGraphQlService {
request.configureExecutionInput(RESET_EXECUTION_ID_CONFIGURER);
}
ExecutionInput executionInput = request.toExecutionInput();
ContextSnapshot.capture(contextView).updateContext(executionInput.getGraphQLContext());
ContextSnapshot.captureFrom(contextView).updateContext(executionInput.getGraphQLContext());
ExecutionInput updatedExecutionInput = registerDataLoaders(executionInput);
return Mono.fromFuture(this.graphQlSource.graphQl().executeAsync(updatedExecutionInput))
.map(result -> new DefaultExecutionGraphQlResponse(updatedExecutionInput, result));

View File

@@ -70,7 +70,7 @@ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler
public CompletableFuture<DataFetcherExceptionHandlerResult> handleException(DataFetcherExceptionHandlerParameters params) {
Throwable exception = unwrapException(params);
DataFetchingEnvironment env = params.getDataFetchingEnvironment();
ContextSnapshot snapshot = ContextSnapshot.capture(env.getGraphQlContext());
ContextSnapshot snapshot = ContextSnapshot.captureFrom(env.getGraphQlContext());
try {
return Flux.fromIterable(this.resolvers)
.flatMap(resolver -> resolver.resolveException(exception, env))

View File

@@ -83,7 +83,7 @@ public abstract class SubscriptionExceptionResolverAdapter implements Subscripti
public final Mono<List<GraphQLError>> resolveException(Throwable exception) {
if (this.threadLocalContextAware) {
return Mono.deferContextual(contextView -> {
ContextSnapshot snapshot = ContextSnapshot.capture(contextView);
ContextSnapshot snapshot = ContextSnapshot.captureFrom(contextView);
try {
List<GraphQLError> errors = snapshot.wrap(() -> resolveToMultipleErrors(exception)).call();
return Mono.justOrEmpty(errors);

View File

@@ -87,7 +87,7 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder {
@Override
public Mono<WebGraphQlResponse> handleRequest(WebGraphQlRequest request) {
ContextSnapshot snapshot = ContextSnapshot.capture();
ContextSnapshot snapshot = ContextSnapshot.captureAll();
return executionChain.next(request).contextWrite(snapshot::updateContext);
}
};

View File

@@ -360,7 +360,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub
ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler,
Map<String, Object> attributes) {
attributes.put(KEY, ContextSnapshot.capture());
attributes.put(KEY, ContextSnapshot.captureAll());
return true;
}
@@ -373,7 +373,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub
public static AutoCloseable setThreadLocals(WebSocketSession session) {
ContextSnapshot snapshot = (ContextSnapshot) session.getAttributes().get(KEY);
Assert.notNull(snapshot, "Expected ContextSnapshot in WebSocketSession attributes");
return snapshot.setThreadLocalValues();
return snapshot.setThreadLocals();
}
}

View File

@@ -60,7 +60,7 @@ public class BatchMappingPrincipalMethodArgumentResolverTests extends BatchMappi
ReactiveSecurityContextHolder.withAuthentication(this.authentication);
private final Function<Context, Context> threadLocalContextWriter = context ->
ContextSnapshot.capture().updateContext(context);
ContextSnapshot.captureAll().updateContext(context);
private static Stream<Arguments> controllers() {

View File

@@ -65,7 +65,7 @@ public class SchemaMappingPrincipalMethodArgumentResolverTests {
ReactiveSecurityContextHolder.withAuthentication(this.authentication);
private final Function<Context, Context> threadLocalContextWriter = context ->
ContextSnapshot.capture().updateContext(context);
ContextSnapshot.captureAll().updateContext(context);
private final GreetingController greetingController = new GreetingController();
@@ -206,4 +206,4 @@ public class SchemaMappingPrincipalMethodArgumentResolverTests {
}
}
}

View File

@@ -108,7 +108,7 @@ public class CompositeSubscriptionExceptionResolverTests {
.toGraphQl();
ExecutionInput input = ExecutionInput.newExecutionInput(query).build();
ContextSnapshot.capture().updateContext(input.getGraphQLContext());
ContextSnapshot.captureAll().updateContext(input.getGraphQLContext());
Flux<ResponseHelper> flux = Mono.defer(() -> Mono.fromFuture(graphQL.executeAsync(input)))
.map(ResponseHelper::forSubscription)

View File

@@ -163,7 +163,7 @@ public class ContextDataFetcherDecoratorTests {
.toGraphQl();
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
ContextSnapshot.capture().updateContext(input.getGraphQLContext());
ContextSnapshot.captureAll().updateContext(input.getGraphQLContext());
Mono<ExecutionResult> resultMono = Mono.delay(Duration.ofMillis(10))
.flatMap((aLong) -> Mono.fromFuture(graphQl.executeAsync(input)));

View File

@@ -101,7 +101,7 @@ public class ExceptionResolversExceptionHandlerTests {
.build());
resolver.setThreadLocalContextAware(true);
ContextSnapshot.capture().updateContext(this.input.getGraphQLContext());
ContextSnapshot.captureAll().updateContext(this.input.getGraphQLContext());
Mono<ExecutionResult> result = Mono.delay(Duration.ofMillis(10)).flatMap((aLong) ->
Mono.fromFuture(this.graphQlSetup.exceptionResolver(resolver).toGraphQl().executeAsync(this.input)));

View File

@@ -379,7 +379,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport {
GraphQlWebSocketHandler handler = initWebSocketHandler(threadLocalInterceptor);
// Ensure ContextSnapshot is present in WebSocketSession attributes
this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.capture());
this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.captureAll());
// Context should propagate, if message is handled on different thread
Thread thread = new Thread(() -> {
@@ -411,7 +411,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport {
if (!this.session.getAttributes().containsKey(ContextSnapshot.class.getName())) {
// Ensure ContextSnapshot is present in WebSocketSession attributes
this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.capture());
this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.captureAll());
}
for (TextMessage message : textMessages) {