-
Notifications
You must be signed in to change notification settings - Fork 1k
make javaagent-tooling and testing-common indy-ready #15133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
1d8900b
6c4c934
49b6dc2
2a2b04f
2a7b0e3
340c519
723b3f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import net.bytebuddy.agent.ByteBuddyAgent; | ||
| import net.bytebuddy.agent.builder.AgentBuilder; | ||
| import net.bytebuddy.agent.builder.ResettableClassFileTransformer; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.dynamic.ClassFileLocator; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
|
|
@@ -34,20 +35,24 @@ class ExceptionHandlerTest { | |
|
|
||
| @BeforeAll | ||
| static void setUp() { | ||
| Advice.WithCustomMapping customMapping = | ||
| Advice.withCustomMapping() | ||
| // required for AssignReturned annotation and throwable suppression | ||
| .with(new Advice.AssignReturned.Factory().withSuppressed(Throwable.class)); | ||
| AgentBuilder builder = | ||
| new AgentBuilder.Default() | ||
| .disableClassFormatChanges() | ||
| .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION) | ||
| .type(named(ExceptionHandlerTest.class.getName() + "$SomeClass")) | ||
| .transform( | ||
| new AgentBuilder.Transformer.ForAdvice() | ||
| new AgentBuilder.Transformer.ForAdvice(customMapping) | ||
| .with( | ||
| new AgentBuilder.LocationStrategy.Simple( | ||
| ClassFileLocator.ForClassLoader.of(BadAdvice.class.getClassLoader()))) | ||
| .withExceptionHandler(ExceptionHandlers.defaultExceptionHandler()) | ||
| .advice(isMethod().and(named("isInstrumented")), BadAdvice.class.getName())) | ||
| .transform( | ||
| new AgentBuilder.Transformer.ForAdvice() | ||
| new AgentBuilder.Transformer.ForAdvice(customMapping) | ||
| .with( | ||
| new AgentBuilder.LocationStrategy.Simple( | ||
| ClassFileLocator.ForClassLoader.of(BadAdvice.class.getClassLoader()))) | ||
|
|
@@ -80,7 +85,10 @@ void exceptionHandlerInvoked() { | |
| int initLogEvents = testHandler.getRecords().size(); | ||
|
|
||
| // Triggers classload and instrumentation | ||
| assertThat(SomeClass.isInstrumented()).isTrue(); | ||
| assertThat(SomeClass.isInstrumented()) | ||
| .describedAs("method return value should be preserved when exception is thrown in advice") | ||
| .isFalse(); | ||
|
Comment on lines
+88
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] in the past the method return value could be modified when advice throws an unexpected exception, now that the return value is modified through the advice method return value this is no longer possible, and thus we always get the original method return value here (and this is very probably a good thing). |
||
|
|
||
| assertThat(testHandler.getRecords()) | ||
| .hasSize(initLogEvents + 1) | ||
| .last() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package context; | ||
|
|
||
| import io.opentelemetry.instrumentation.api.util.VirtualField; | ||
| import library.KeyClass; | ||
| import library.KeyInterface; | ||
|
|
||
| public class ContextTestSingletons { | ||
|
|
||
| public static final VirtualField<KeyClass, Context> CONTEXT = | ||
| VirtualField.find(KeyClass.class, Context.class); | ||
| public static final VirtualField<KeyClass, Integer> INTEGER = | ||
| VirtualField.find(KeyClass.class, Integer.class); | ||
| public static final VirtualField<KeyInterface, Integer> INTERFACE_INTEGER = | ||
| VirtualField.find(KeyInterface.class, Integer.class); | ||
|
|
||
| private ContextTestSingletons() {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] with the original syntax, the method return value is altered even when the advice throws an exception, this is no longer the case with this syntax.