Skip to content

Commit

Permalink
GH-77 - Upgrade to Spring Boot 3.0.
Browse files Browse the repository at this point in the history
Adapt to API changes in Micrometer and Spring Boot's test context loader API now exposing a checked ContextLoadException to signal failures during ApplicationContext bootstraps.
  • Loading branch information
odrotbohm committed Nov 24, 2022
1 parent 065db76 commit b402f00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-asciidoctor-backends.version>0.0.4-SNAPSHOT</spring-asciidoctor-backends.version>
<spring-boot.version>3.0.0-RC1</spring-boot.version>
<spring-boot.version>3.0.0</spring-boot.version>

</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.modulith.observability;

import io.micrometer.tracing.BaggageInScope;
import io.micrometer.tracing.Baggage;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.Tracer;
import io.micrometer.tracing.Tracer.SpanInScope;
Expand Down Expand Up @@ -59,7 +59,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {

if (currentSpan != null) {

BaggageInScope currentBaggage = tracer.getBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY);
Baggage currentBaggage = tracer.getBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY);

if (currentBaggage != null && moduleName.equals(currentBaggage.get())) {
return invocation.proceed();
Expand All @@ -76,10 +76,9 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
.tag(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY, moduleName)
.start();

try (
SpanInScope ws = tracer.withSpan(span); //
BaggageInScope baggage = tracer.createBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY, moduleName); //
) {
tracer.createBaggage(ModuleTracingBeanPostProcessor.MODULE_BAGGAGE_KEY, moduleName);

try (SpanInScope ws = tracer.withSpan(span)) {

return invocation.proceed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.BootstrapContext;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.ContextLoadException;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate;
import org.springframework.test.context.support.DefaultBootstrapContext;
Expand Down Expand Up @@ -52,13 +53,10 @@ public static void assertDependencyMissing(Class<?> testClass, Class<?> expected

return (ConfigurableApplicationContext) loader.loadContext(configuration);

} catch (Exception e) {

if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}

throw new RuntimeException(e);
} catch (ContextLoadException o_O) {
throw asRuntimeException(o_O.getCause());
} catch (Exception o_O) {
throw asRuntimeException(o_O);
}
});

Expand All @@ -70,4 +68,8 @@ public static void assertDependencyMissing(Class<?> testClass, Class<?> expected
});
});
}

private static RuntimeException asRuntimeException(Throwable o_O) {
return o_O instanceof RuntimeException ? (RuntimeException) o_O : new RuntimeException(o_O);
}
}

0 comments on commit b402f00

Please sign in to comment.