Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
308 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
profiler/src/test/java/com/navercorp/pinpoint/profiler/DynamicTransformServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* * | ||
* * Copyright 2014 NAVER Corp. | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * http://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.navercorp.pinpoint.profiler; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.invocation.InvocationOnMock; | ||
import org.mockito.stubbing.Answer; | ||
|
||
import java.lang.instrument.ClassFileTransformer; | ||
import java.lang.instrument.Instrumentation; | ||
import java.lang.instrument.UnmodifiableClassException; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public class DynamicTransformServiceTest { | ||
|
||
@Test() | ||
public void testRetransform_Fail_memoryleak_prevent() throws Exception { | ||
final Instrumentation instrumentation = mock(Instrumentation.class); | ||
when(instrumentation.isModifiableClass(any(Class.class))).thenReturn(true); | ||
doAnswer(new Answer<Void>() { | ||
@Override | ||
public Void answer(InvocationOnMock invocation) throws Throwable { | ||
throw new UnmodifiableClassException(); | ||
} | ||
}).when(instrumentation).retransformClasses(any(Class.class)); | ||
|
||
|
||
DefaultDynamicTransformerRegistry listener = new DefaultDynamicTransformerRegistry(); | ||
|
||
final ClassFileTransformer classFileTransformer = mock(ClassFileTransformer.class); | ||
|
||
DynamicTransformService dynamicTransformService = new DynamicTransformService(instrumentation, listener); | ||
|
||
try { | ||
dynamicTransformService.retransform(String.class, classFileTransformer); | ||
Assert.fail("expected retransform fail"); | ||
} catch (Exception e) { | ||
} | ||
Assert.assertEquals(listener.size(), 0); | ||
} | ||
|
||
// @Test | ||
// public void testAddClassFileTransformer() throws Exception { | ||
// | ||
// } | ||
} |
87 changes: 87 additions & 0 deletions
87
...iler/src/test/java/com/navercorp/pinpoint/profiler/instrument/JavassistClassPoolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* * | ||
* * Copyright 2014 NAVER Corp. | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * http://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.navercorp.pinpoint.profiler.instrument; | ||
|
||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass; | ||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder; | ||
import com.navercorp.pinpoint.test.TestInterceptorRegistryBinder; | ||
import com.navercorp.pinpoint.test.util.BytecodeUtils; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import javassist.CtMethod; | ||
import javassist.bytecode.ConstPool; | ||
import javassist.bytecode.MethodInfo; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public class JavassistClassPoolTest { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
private final String mock = "com.navercorp.pinpoint.profiler.instrument.JavassistClassPoolTestMock"; | ||
|
||
@Test | ||
public void testGetClass_original() throws Exception { | ||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder(); | ||
JavassistClassPool pool = new JavassistClassPool(binder, null); | ||
|
||
|
||
final byte[] originalByteCode = BytecodeUtils.getClassFile(null, mock); | ||
final InstrumentClass transformClass = pool.getClass(null, mock, originalByteCode); | ||
|
||
Assert.assertNotNull(transformClass.getDeclaredMethod("test")); | ||
Assert.assertNull("transform method", transformClass.getDeclaredMethod("transformMethod")); | ||
|
||
} | ||
|
||
@Test | ||
public void testGetClass_transform() throws Exception { | ||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder(); | ||
JavassistClassPool pool = new JavassistClassPool(binder, null); | ||
|
||
|
||
final byte[] transformByteCode = getTransformByteCode(); | ||
final InstrumentClass transformClass = pool.getClass(null, mock, transformByteCode); | ||
|
||
Assert.assertNotNull(transformClass.getDeclaredMethod("test")); | ||
Assert.assertNotNull("transform method", transformClass.getDeclaredMethod("transformMethod")); | ||
} | ||
|
||
public byte[] getTransformByteCode() { | ||
try { | ||
final ClassPool pool = new ClassPool(true); | ||
|
||
final CtClass ctClass = pool.get(mock); | ||
|
||
final ConstPool constPool = ctClass.getClassFile2().getConstPool(); | ||
|
||
MethodInfo info = new MethodInfo(constPool, "transformMethod", "()V"); | ||
final CtMethod newMethod = CtMethod.make(info, ctClass); | ||
ctClass.addMethod(newMethod); | ||
return ctClass.toBytecode(); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex.getMessage(), ex); | ||
} | ||
} | ||
|
||
} | ||
|
26 changes: 26 additions & 0 deletions
26
.../src/test/java/com/navercorp/pinpoint/profiler/instrument/JavassistClassPoolTestMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* * | ||
* * Copyright 2014 NAVER Corp. | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * http://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.navercorp.pinpoint.profiler.instrument; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public class JavassistClassPoolTestMock { | ||
public void test() { | ||
} | ||
} |
Oops, something went wrong.