Skip to content

Commit

Permalink
polish test code
Browse files Browse the repository at this point in the history
  • Loading branch information
kylixs committed Jun 11, 2023
1 parent 20de941 commit e4c3703
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.lang.instrument.UnmodifiableClassException;
import java.security.ProtectionDomain;

public class MultipleInterceptorTest extends AbstractRetransformTest {
public class MultipleTransformersTest extends AbstractRetransformTest {

String dumpFolder = "target/class-dump";

Expand All @@ -48,15 +48,16 @@ public void test1() throws UnmodifiableClassException {
String className = BIZ_FOO_CLASS_NAME;
String nameTrait = getNameTrait(1);
deleteDuplicatedFields = true;
String methodName = SAY_HELLO_METHOD;

enableClassDump();
//enableClassDump();

AgentBuilder.Transformer transformer1 = new AgentBuilder.Transformer() {
AgentBuilder.Transformer instance = this;

@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) {
int round = 1;
String methodName = SAY_HELLO_METHOD;
String interceptorClassName = METHOD_INTERCEPTOR_CLASS + "$" + methodName + "$" + round;
String fieldName = nameTrait + "_delegate$" + methodName + round;
SWTransformThreadLocals.setTransformer(instance);
Expand All @@ -72,11 +73,7 @@ public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDesc
))
.method(ElementMatchers.nameContainsIgnoreCase(methodName))
.intercept(MethodDelegation.withDefaultConfiguration()
.to(new InstMethodsInter(interceptorClassName, classLoader), fieldName))
// .method(ElementMatchers.is(methodName))
// .intercept(MethodDelegation.withDefaultConfiguration()
// .to(new InstMethodsInter(interceptorClassName + "2", classLoader), fieldName + "2"))
;
.to(new InstMethodsInter(interceptorClassName, classLoader), fieldName));
}
};

Expand All @@ -86,8 +83,6 @@ public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDesc
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) {
int round = 2;
String methodName = SAY_HELLO_METHOD;
// String methodName = GREETING_METHOD;
String interceptorClassName = METHOD_INTERCEPTOR_CLASS + "$" + methodName + "$" + round;
String fieldName = nameTrait + "_delegate$" + methodName + round;
SWTransformThreadLocals.setTransformer(instance);
Expand All @@ -103,13 +98,13 @@ public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDesc
))
.method(ElementMatchers.nameContainsIgnoreCase(methodName))
.intercept(MethodDelegation.withDefaultConfiguration()
.to(new InstMethodsInter(interceptorClassName, classLoader), fieldName))
;
.to(new InstMethodsInter(interceptorClassName, classLoader), fieldName));
}
};

// new AgentBuilder.Default()
Instrumentation instrumentation = ByteBuddyAgent.install();

// new AgentBuilder.Default()
newAgentBuilder(nameTrait)
.type(ElementMatchers.named(className))
.transform(transformer1)
Expand Down

0 comments on commit e4c3703

Please sign in to comment.