3838import org .apache .skywalking .apm .agent .bytebuddy .SWAuxiliaryTypeNamingStrategy ;
3939import org .apache .skywalking .apm .agent .bytebuddy .SWClassFileLocator ;
4040import org .apache .skywalking .apm .agent .bytebuddy .biz .BizFoo ;
41+ import org .apache .skywalking .apm .agent .bytebuddy .biz .ChildBar ;
4142import org .apache .skywalking .apm .agent .core .plugin .interceptor .enhance .EnhancedInstance ;
4243import org .junit .Assert ;
4344import org .junit .BeforeClass ;
@@ -63,6 +64,8 @@ public class AbstractInterceptTest {
6364 public static final String BIZ_FOO_CLASS_NAME = "org.apache.skywalking.apm.agent.bytebuddy.biz.BizFoo" ;
6465 public static final String PROJECT_SERVICE_CLASS_NAME = "org.apache.skywalking.apm.agent.bytebuddy.biz.ProjectService" ;
6566 public static final String DOC_SERVICE_CLASS_NAME = "org.apache.skywalking.apm.agent.bytebuddy.biz.DocService" ;
67+ public static final String PARENT_BAR_CLASS_NAME = "org.apache.skywalking.apm.agent.bytebuddy.biz.ParentBar" ;
68+ public static final String CHILD_BAR_CLASS_NAME = "org.apache.skywalking.apm.agent.bytebuddy.biz.ChildBar" ;
6669 public static final String SAY_HELLO_METHOD = "sayHello" ;
6770 public static final int BASE_INT_VALUE = 100 ;
6871 public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "constructorInterceptorClass" ;
@@ -85,6 +88,20 @@ protected void failed(Throwable e, Description description) {
8588 }
8689 };
8790
91+ protected static void callBar (int round ) {
92+ Log .info ("-------------" );
93+ Log .info ("callChildBar: " + round );
94+ // load target class
95+ String strResultChild = new ChildBar ().sayHelloChild ();
96+ Log .info ("result: " + strResultChild );
97+
98+ String strResultParent = new ChildBar ().sayHelloParent ();
99+ Log .info ("result: " + strResultParent );
100+
101+ Assert .assertEquals ("String value is unexpected" , "John" , strResultChild );
102+ Assert .assertEquals ("String value is unexpected" , "John" , strResultParent );
103+ }
104+
88105 protected static void callBizFoo (int round ) {
89106 Log .info ("-------------" );
90107 Log .info ("callBizFoo: " + round );
@@ -115,7 +132,7 @@ protected static void checkConstructorInterceptor(String className, int round) {
115132
116133 protected static void checkInterface (Class testClass , Class interfaceCls ) {
117134 Assert .assertTrue ("Check interface failure, the test class: " + testClass + " does not implement the expected interface: " + interfaceCls ,
118- EnhancedInstance .class .isAssignableFrom (BizFoo . class ));
135+ EnhancedInstance .class .isAssignableFrom (testClass ));
119136 }
120137
121138 protected static void checkErrors () {
@@ -139,8 +156,7 @@ protected void installMethodInterceptorWithMethodDelegation(String className, St
139156 return builder
140157 .method (ElementMatchers .nameContainsIgnoreCase (methodName ))
141158 .intercept (MethodDelegation .withDefaultConfiguration ()
142- .to (new InstMethodsInter (interceptorClassName , classLoader ), fieldName ))
143- ;
159+ .to (new InstMethodsInter (interceptorClassName , classLoader ), fieldName ));
144160 }
145161 )
146162 .with (getListener (interceptorClassName ))
@@ -223,7 +239,7 @@ protected void installTraceClassTransformer(String msg) {
223239 ClassFileTransformer classFileTransformer = new ClassFileTransformer () {
224240 @ Override
225241 public byte [] transform (ClassLoader loader , String className , Class <?> classBeingRedefined , ProtectionDomain protectionDomain , byte [] classfileBuffer ) throws IllegalClassFormatException {
226- if (className .endsWith ("BizFoo" ) || className .endsWith ("ProjectService" ) || className .endsWith ("DocService" )) {
242+ if (className .endsWith ("BizFoo" ) || className .endsWith ("ProjectService" ) || className .endsWith ("DocService" ) || className . endsWith ( "ChildBar" ) || className . endsWith ( "ParentBar" ) ) {
227243 Log .error (msg + className );
228244 ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
229245 ClassReader cr = new ClassReader (classfileBuffer );
0 commit comments