mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-18 01:06:03 +10:00
[#49] Created arcus plugin project
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleAfterInterceptor extends Interceptor {
|
||||
void after(Object target, Object[] args, Object result, Throwable throwable);
|
||||
}
|
||||
+1
-4
@@ -3,9 +3,6 @@ package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleAroundInterceptor extends Interceptor {
|
||||
public interface SimpleAroundInterceptor extends SimpleBeforeInterceptor, SimpleAfterInterceptor {
|
||||
|
||||
void before(Object target, Object[] args);
|
||||
|
||||
void after(Object target, Object[] args, Object result, Throwable throwable);
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
public interface SimpleBeforeInterceptor extends Interceptor {
|
||||
void before(Object target, Object[] args);
|
||||
}
|
||||
+4
-19
@@ -1,33 +1,23 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.List;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
|
||||
public class BasicClassEditor implements DedicatedClassEditor {
|
||||
private final ByteCodeInstrumentor instrumentor;
|
||||
|
||||
private final String targetClassName;
|
||||
|
||||
public class BasicClassEditor implements ClassEditor {
|
||||
private final List<MetadataInjector> metadataInjectors;
|
||||
private final List<InterceptorInjector> interceptorInjectors;
|
||||
|
||||
|
||||
public BasicClassEditor(ByteCodeInstrumentor instrumentor, String targetClassName, List<MetadataInjector> metadataInjectors, List<InterceptorInjector> interceptorInjectors) {
|
||||
this.instrumentor = instrumentor;
|
||||
this.targetClassName = targetClassName;
|
||||
public BasicClassEditor(List<MetadataInjector> metadataInjectors, List<InterceptorInjector> interceptorInjectors) {
|
||||
this.metadataInjectors = metadataInjectors;
|
||||
this.interceptorInjectors = interceptorInjectors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] edit(ClassLoader classLoader, String className, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
public byte[] edit(ClassLoader classLoader, InstrumentClass target) {
|
||||
try {
|
||||
InstrumentClass target = instrumentor.getClass(classLoader, className, classFileBuffer);
|
||||
|
||||
for (MetadataInjector injector : metadataInjectors) {
|
||||
injector.inject(classLoader, target);
|
||||
}
|
||||
@@ -38,12 +28,7 @@ public class BasicClassEditor implements DedicatedClassEditor {
|
||||
|
||||
return target.toBytecode();
|
||||
} catch (Throwable t) {
|
||||
throw new PinpointException("Fail to edit class: " + targetClassName, t);
|
||||
throw new PinpointException("Fail to edit class", t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClassName() {
|
||||
return targetClassName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
|
||||
public interface ClassEditor {
|
||||
public byte[] edit(ClassLoader classLoader, String className, ProtectionDomain protectionDomain, byte[] classFileBuffer);
|
||||
public byte[] edit(ClassLoader classLoader, InstrumentClass target);
|
||||
}
|
||||
|
||||
+47
-22
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.MethodFilter;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.TraceValue;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.MetadataInitializationStrategy.ByConstructor;
|
||||
|
||||
@@ -13,18 +14,22 @@ public class ClassEditorBuilder {
|
||||
private final ByteCodeInstrumentor instrumentor;
|
||||
private final TraceContext traceContext;
|
||||
|
||||
private final String targetClassName;
|
||||
|
||||
private final List<InterceptorBuilder> interceptorBuilders = new ArrayList<InterceptorBuilder>();
|
||||
private final List<MetadataBuilder> metadataBuilders = new ArrayList<MetadataBuilder>();
|
||||
|
||||
public ClassEditorBuilder(ByteCodeInstrumentor instrumentor, TraceContext traceContext, String targetClassName) {
|
||||
private Condition condition;
|
||||
|
||||
public ClassEditorBuilder(ByteCodeInstrumentor instrumentor, TraceContext traceContext) {
|
||||
this.instrumentor = instrumentor;
|
||||
this.traceContext = traceContext;
|
||||
this.targetClassName = targetClassName;
|
||||
}
|
||||
|
||||
public ClassEditorBuilder editWhen(Condition condition) {
|
||||
this.condition = condition;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InterceptorBuilder intercept(String methodName, String... parameterTypes) {
|
||||
public InterceptorBuilder intercept(String methodName, Class<?>... parameterTypes) {
|
||||
InterceptorBuilder interceptorBuilder = new InterceptorBuilder(methodName, parameterTypes, null);
|
||||
interceptorBuilders.add(interceptorBuilder);
|
||||
return interceptorBuilder;
|
||||
@@ -36,14 +41,14 @@ public class ClassEditorBuilder {
|
||||
return interceptorBuilder;
|
||||
}
|
||||
|
||||
public InterceptorBuilder interceptConstructor(String... parameterTypes) {
|
||||
public InterceptorBuilder interceptConstructor(Class<?>... parameterTypes) {
|
||||
InterceptorBuilder interceptorBuilder = new InterceptorBuilder(null, parameterTypes, null);
|
||||
interceptorBuilders.add(interceptorBuilder);
|
||||
return interceptorBuilder;
|
||||
}
|
||||
|
||||
public MetadataBuilder inject(Class<? extends TraceValue> metadataAccessor) {
|
||||
MetadataBuilder metadataBuilder = new MetadataBuilder(metadataAccessor);
|
||||
public MetadataBuilder inject(Class<? extends TraceValue> metadataType) {
|
||||
MetadataBuilder metadataBuilder = new MetadataBuilder(metadataType);
|
||||
metadataBuilders.add(metadataBuilder);
|
||||
return metadataBuilder;
|
||||
}
|
||||
@@ -61,7 +66,13 @@ public class ClassEditorBuilder {
|
||||
interceptorInjectors.add(builder.build());
|
||||
}
|
||||
|
||||
return new BasicClassEditor(instrumentor, targetClassName, metadataInjectors, interceptorInjectors);
|
||||
ClassEditor editor = new BasicClassEditor(metadataInjectors, interceptorInjectors);
|
||||
|
||||
if (condition != null) {
|
||||
editor = new ConditionalClassEditor(condition, editor);
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
public class InterceptorBuilder {
|
||||
@@ -69,15 +80,16 @@ public class ClassEditorBuilder {
|
||||
private final String[] parameterTypes;
|
||||
private final MethodFilter filter;
|
||||
|
||||
private String interceptorClassName;
|
||||
private Class<? extends Interceptor> interceptorClass;
|
||||
private Condition condition;
|
||||
private String scopeName;
|
||||
private Object[] constructorArguments;
|
||||
private ParameterExtractorFactory parameterExtractorFactory;
|
||||
private boolean singleton;
|
||||
|
||||
public InterceptorBuilder(String methodName, String[] parameterTypes, MethodFilter filter) {
|
||||
public InterceptorBuilder(String methodName, Class<?>[] parameterTypes, MethodFilter filter) {
|
||||
this.methodName = methodName;
|
||||
this.parameterTypes = parameterTypes;
|
||||
this.parameterTypes = TypeUtils.toClassNames(parameterTypes);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@@ -86,8 +98,8 @@ public class ClassEditorBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public InterceptorBuilder with(String interceptorClassName) {
|
||||
this.interceptorClassName = interceptorClassName;
|
||||
public InterceptorBuilder with(Class<? extends Interceptor> interceptorClass) {
|
||||
this.interceptorClass = interceptorClass;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -106,25 +118,38 @@ public class ClassEditorBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public InterceptorBuilder when(Condition condition) {
|
||||
this.condition = condition;
|
||||
return this;
|
||||
}
|
||||
|
||||
private InterceptorInjector build() {
|
||||
InterceptorFactory interceptorFactory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, constructorArguments, parameterExtractorFactory, scopeName);
|
||||
InterceptorFactory interceptorFactory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClass, constructorArguments, parameterExtractorFactory, scopeName);
|
||||
|
||||
InterceptorInjector injector;
|
||||
|
||||
if (filter != null) {
|
||||
return new FilteringInterceptorInjector(filter, interceptorFactory, singleton);
|
||||
injector = new FilteringInterceptorInjector(filter, interceptorFactory, singleton);
|
||||
} else if (methodName != null) {
|
||||
return new DedicatedInterceptorInjector(methodName, parameterTypes, interceptorFactory);
|
||||
injector = new DedicatedInterceptorInjector(methodName, parameterTypes, interceptorFactory);
|
||||
} else {
|
||||
return new ConstructorInterceptorInjector(parameterTypes, interceptorFactory);
|
||||
injector = new ConstructorInterceptorInjector(parameterTypes, interceptorFactory);
|
||||
}
|
||||
|
||||
if (condition != null) {
|
||||
injector = new ConditionalInterceptorInjector(condition, injector);
|
||||
}
|
||||
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
public class MetadataBuilder {
|
||||
private final Class<? extends TraceValue> metadataAccessor;
|
||||
private final Class<? extends TraceValue> metadataType;
|
||||
private MetadataInitializationStrategy initializationStrategy;
|
||||
|
||||
public MetadataBuilder(Class<? extends TraceValue> metadataAccessor) {
|
||||
this.metadataAccessor = metadataAccessor;
|
||||
public MetadataBuilder(Class<? extends TraceValue> metadataType) {
|
||||
this.metadataType = metadataType;
|
||||
}
|
||||
|
||||
public MetadataBuilder initializeWithDefaultConstructorOf(String className) {
|
||||
@@ -133,7 +158,7 @@ public class ClassEditorBuilder {
|
||||
}
|
||||
|
||||
private MetadataInjector build() {
|
||||
return new DefaultMetadataInjector(metadataAccessor, initializationStrategy);
|
||||
return new DefaultMetadataInjector(metadataType, initializationStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
public interface ClassEditorFactory {
|
||||
public ClassEditor get(ProfilerPluginContext context);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
public class ClassEditorFactoryMapping {
|
||||
private final String targetClassName;
|
||||
private final String editorFactoryClassName;
|
||||
|
||||
public ClassEditorFactoryMapping(String targetClassName, String editorFactoryClassName) {
|
||||
this.targetClassName = targetClassName;
|
||||
this.editorFactoryClassName = editorFactoryClassName;
|
||||
}
|
||||
|
||||
public String getTargetClassName() {
|
||||
return targetClassName;
|
||||
}
|
||||
|
||||
public String getEditorFactoryClassName() {
|
||||
return editorFactoryClassName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
|
||||
public interface Condition {
|
||||
public boolean check(InstrumentClass target);
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
|
||||
public class ConditionalClassEditor implements ClassEditor {
|
||||
private final Condition condition;
|
||||
private final ClassEditor delegate;
|
||||
|
||||
public ConditionalClassEditor(Condition condition, ClassEditor delegate) {
|
||||
this.condition = condition;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] edit(ClassLoader classLoader, InstrumentClass target) {
|
||||
if (condition.check(target)) {
|
||||
return delegate.edit(classLoader, target);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentException;
|
||||
|
||||
public class ConditionalInterceptorInjector implements InterceptorInjector {
|
||||
private final Condition condition;
|
||||
private final InterceptorInjector delegate;
|
||||
|
||||
public ConditionalInterceptorInjector(Condition condition, InterceptorInjector delegate) {
|
||||
this.condition = condition;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(ClassLoader classLoader, InstrumentClass target) throws InstrumentException {
|
||||
if (condition.check(target)) {
|
||||
delegate.inject(classLoader, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-15
@@ -22,17 +22,17 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
|
||||
private final ByteCodeInstrumentor instrumentor;
|
||||
private final TraceContext traceContext;
|
||||
|
||||
private final String interceptorClassName;
|
||||
private final Class<? extends Interceptor> interceptorClass;
|
||||
private final Object[] providedArguments;
|
||||
|
||||
private final ParameterExtractorFactory parameterExtractorFactory;
|
||||
private final String scopeName;
|
||||
|
||||
|
||||
public DefaultInterceptorFactory(ByteCodeInstrumentor instrumentor, TraceContext traceContext, String interceptorClassName, Object[] providedArguments, ParameterExtractorFactory parameterExtractorFactory, String scopeName) {
|
||||
public DefaultInterceptorFactory(ByteCodeInstrumentor instrumentor, TraceContext traceContext, Class<? extends Interceptor> interceptorClass, Object[] providedArguments, ParameterExtractorFactory parameterExtractorFactory, String scopeName) {
|
||||
this.instrumentor = instrumentor;
|
||||
this.traceContext = traceContext;
|
||||
this.interceptorClassName = interceptorClassName;
|
||||
this.interceptorClass = interceptorClass;
|
||||
this.providedArguments = providedArguments == null ? NO_ARGS : providedArguments;
|
||||
this.parameterExtractorFactory = parameterExtractorFactory;
|
||||
this.scopeName = scopeName;
|
||||
@@ -50,17 +50,6 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
|
||||
}
|
||||
|
||||
private Interceptor createInstance(TraceContext traceContext, ClassLoader classLoader, InstrumentClass target, MethodInfo targetMethod) {
|
||||
Class<?> interceptorClass;
|
||||
try {
|
||||
interceptorClass = classLoader.loadClass(interceptorClassName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new PinpointException("Cannot find interceptor class: " + interceptorClassName, e);
|
||||
}
|
||||
|
||||
if (!Interceptor.class.isAssignableFrom(interceptorClass)) {
|
||||
throw new PinpointException("Given class " + interceptorClassName + " is not implementing Interceptor");
|
||||
}
|
||||
|
||||
Constructor<?>[] constructors = interceptorClass.getConstructors();
|
||||
Arrays.sort(constructors, CONSTRUCTOR_COMPARATOR);
|
||||
|
||||
@@ -73,7 +62,7 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
|
||||
}
|
||||
}
|
||||
|
||||
throw new PinpointException("Cannot find suitable constructor for " + interceptorClassName);
|
||||
throw new PinpointException("Cannot find suitable constructor for " + interceptorClass.getName());
|
||||
}
|
||||
|
||||
private Object invokeConstructor(Constructor<?> constructor, Object[] arguments) {
|
||||
|
||||
+5
-5
@@ -7,22 +7,22 @@ import com.nhn.pinpoint.bootstrap.plugin.MetadataInitializationStrategy.ByConstr
|
||||
|
||||
public class DefaultMetadataInjector implements MetadataInjector {
|
||||
|
||||
private final Class<? extends TraceValue> metadataAccessorType;
|
||||
private final Class<? extends TraceValue> metadataType;
|
||||
private final MetadataInitializationStrategy strategy;
|
||||
|
||||
public DefaultMetadataInjector(Class<? extends TraceValue> metadataAccessorType, MetadataInitializationStrategy strategy) {
|
||||
this.metadataAccessorType = metadataAccessorType;
|
||||
public DefaultMetadataInjector(Class<? extends TraceValue> metadataType, MetadataInitializationStrategy strategy) {
|
||||
this.metadataType = metadataType;
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(ClassLoader classLoader, InstrumentClass target) throws InstrumentException {
|
||||
if (strategy == null) {
|
||||
target.addTraceValue(metadataAccessorType);
|
||||
target.addTraceValue(metadataType);
|
||||
} else {
|
||||
if (strategy instanceof ByConstructor) {
|
||||
String javaExpression = "new " + ((ByConstructor)strategy).getClassName() + "();";
|
||||
target.addTraceValue(metadataAccessorType, javaExpression);
|
||||
target.addTraceValue(metadataType, javaExpression);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported strategy: " + strategy);
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PluginClassLoaderFactory {
|
||||
private final URL[] pluginJars;
|
||||
private final ConcurrentHashMap<ClassLoader, ClassLoader> cache = new ConcurrentHashMap<ClassLoader, ClassLoader>();
|
||||
|
||||
public PluginClassLoaderFactory(URL[] pluginJars) {
|
||||
this.pluginJars = pluginJars;
|
||||
}
|
||||
|
||||
public ClassLoader get(ClassLoader loader) {
|
||||
ClassLoader forPlugin = cache.get(loader);
|
||||
|
||||
if (forPlugin != null) {
|
||||
return forPlugin;
|
||||
}
|
||||
|
||||
ClassLoader newInstance = new URLClassLoader(pluginJars, loader);
|
||||
ClassLoader inCache = cache.putIfAbsent(loader, newInstance);
|
||||
|
||||
return inCache == null ? newInstance : inCache;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,5 +3,5 @@ package com.nhn.pinpoint.bootstrap.plugin;
|
||||
import java.util.List;
|
||||
|
||||
public interface ProfilerPlugin {
|
||||
public List<ClassEditor> getClassEditors(ProfilerPluginContext context);
|
||||
public List<ClassEditorFactoryMapping> getClassEditorMappings(ProfilerPluginContext context);
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,6 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
|
||||
@@ -12,8 +13,12 @@ public class ProfilerPluginContext {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
public ClassEditorBuilder getClassEditorBuilderFor(String targetClassName) {
|
||||
return new ClassEditorBuilder(instrumentor, traceContext, targetClassName);
|
||||
public ClassEditorBuilder newClassEditorBuilder() {
|
||||
return new ClassEditorBuilder(instrumentor, traceContext);
|
||||
}
|
||||
|
||||
public ProfilerConfig getConfig() {
|
||||
return traceContext.getProfilerConfig();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,15 @@ public abstract class TypeUtils {
|
||||
|
||||
throw new IllegalArgumentException("Unexpected argument: " + primitive);
|
||||
}
|
||||
|
||||
public static String[] toClassNames(Class<?>... classes) {
|
||||
int length = classes.length;
|
||||
String[] result = new String[length];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
result[i] = classes[i].getName();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-11
@@ -26,27 +26,25 @@ public class ClassEditorBuilderTest {
|
||||
Scope aScope = mock(Scope.class);
|
||||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String targetClassName = "com.nhn.pinpoint.bootstrap.plugin.Foo";
|
||||
String methodName = "someMethod";
|
||||
String[] parameterTypes = new String[] { "java.lang.String" };
|
||||
Class<?>[] parameterTypes = new Class<?>[] { String.class };
|
||||
String[] parameterTypeNames = TypeUtils.toClassNames(parameterTypes);
|
||||
String scopeName = "test";
|
||||
byte[] classFileBuffer = BytecodeUtils.getClassFile(classLoader, targetClassName);
|
||||
|
||||
when(instrumentor.getClass(classLoader, targetClassName, classFileBuffer)).thenReturn(aClass);
|
||||
|
||||
when(instrumentor.getScope(scopeName)).thenReturn(aScope);
|
||||
when(aClass.getDeclaredMethod(methodName, parameterTypes)).thenReturn(aMethod);
|
||||
when(aClass.getDeclaredMethod(methodName, parameterTypeNames)).thenReturn(aMethod);
|
||||
when(aMethod.getName()).thenReturn(methodName);
|
||||
when(aMethod.getParameterTypes()).thenReturn(parameterTypes);
|
||||
when(aClass.addInterceptor(eq(methodName), eq(parameterTypes), isA(Interceptor.class))).thenReturn(0);
|
||||
when(aMethod.getParameterTypes()).thenReturn(parameterTypeNames);
|
||||
when(aClass.addInterceptor(eq(methodName), eq(parameterTypeNames), isA(Interceptor.class))).thenReturn(0);
|
||||
|
||||
|
||||
ProfilerPluginContext helper = new ProfilerPluginContext(instrumentor, traceContext);
|
||||
ClassEditorBuilder builder = helper.getClassEditorBuilderFor(targetClassName);
|
||||
builder.intercept(methodName, parameterTypes).with("com.nhn.pinpoint.bootstrap.plugin.TestInterceptor").constructedWith("provided").in(scopeName);
|
||||
ClassEditorBuilder builder = helper.newClassEditorBuilder();
|
||||
builder.intercept(methodName, parameterTypes).with(TestInterceptor.class).constructedWith("provided").in(scopeName);
|
||||
builder.inject(TestMetadata.class).initializeWithDefaultConstructorOf("java.util.HashMap");
|
||||
ClassEditor editor = builder.build();
|
||||
|
||||
editor.edit(classLoader, targetClassName, null, classFileBuffer);
|
||||
editor.edit(classLoader, aClass);
|
||||
|
||||
verify(aClass).addInterceptor(eq(methodName), isA(String[].class), isA(Interceptor.class));
|
||||
verify(aClass).addTraceValue(TestMetadata.class, "new java.util.HashMap();");
|
||||
|
||||
+28
-43
@@ -16,6 +16,9 @@ import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TestInterceptors.TestInterceptor0;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TestInterceptors.TestInterceptor1;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TestInterceptors.TestInterceptor2;
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
|
||||
public class DefaultInterceptorFactoryTest {
|
||||
@@ -36,44 +39,39 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test0() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor0.class, null, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor0.class, interceptor.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0";
|
||||
Object[] args = new Object[] { "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor0.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor0.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
}
|
||||
|
||||
@Test(expected = PinpointException.class)
|
||||
public void test2() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0";
|
||||
Object[] args = new Object[] { 1 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor0.class, args, null, null);
|
||||
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { "arg0", (byte)1, (short)2, (float)3.0 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(args[2], getField(interceptor, "field2"));
|
||||
@@ -82,13 +80,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test4() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (byte)1, (short)2, (float)3.0, "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[3], getField(interceptor, "field0"));
|
||||
assertEquals(args[0], getField(interceptor, "field1"));
|
||||
assertEquals(args[1], getField(interceptor, "field2"));
|
||||
@@ -97,13 +94,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test5() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (short)2, (float)3.0, "arg0", (byte)1 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[2], getField(interceptor, "field0"));
|
||||
assertEquals(args[3], getField(interceptor, "field1"));
|
||||
assertEquals(args[0], getField(interceptor, "field2"));
|
||||
@@ -112,13 +108,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test6() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (float)3.0, (short)2, (byte)1, "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[3], getField(interceptor, "field0"));
|
||||
assertEquals(args[2], getField(interceptor, "field1"));
|
||||
assertEquals(args[1], getField(interceptor, "field2"));
|
||||
@@ -127,30 +122,26 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test(expected=PinpointException.class)
|
||||
public void test7() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (double)3.0, (short)2, (byte)1, "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
}
|
||||
|
||||
@Test(expected=PinpointException.class)
|
||||
public void test8() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, null, null, null);
|
||||
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test9() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
Object[] args = new Object[] { "arg0", 1, 2.0, true, 3L };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, args, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(args[2], getField(interceptor, "field2"));
|
||||
@@ -163,13 +154,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test10() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
Object[] args = new Object[] { "arg0", 1, 2.0 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, args, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(args[2], getField(interceptor, "field2"));
|
||||
@@ -182,13 +172,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test11() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
Object[] args = new Object[] { "arg0", 1 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, args, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(0.0, getField(interceptor, "field2"));
|
||||
@@ -201,12 +190,10 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test12() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, null, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(null, getField(interceptor, "field0"));
|
||||
assertEquals(0, getField(interceptor, "field1"));
|
||||
assertEquals(0.0, getField(interceptor, "field2"));
|
||||
@@ -219,12 +206,10 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test13() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, null, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(null, getField(interceptor, "field0"));
|
||||
assertEquals(0, getField(interceptor, "field1"));
|
||||
assertEquals(0.0, getField(interceptor, "field2"));
|
||||
|
||||
Reference in New Issue
Block a user