Search in sources :

Example 1 with ApplicationContext

use of com.navercorp.pinpoint.profiler.context.module.ApplicationContext in project pinpoint by naver.

the class DefaultClassEditorBuilderTest method test.

@Test
public void test() throws Exception {
    InstrumentEngine instrumentEngine = mock(InstrumentEngine.class);
    TraceContext traceContext = mock(TraceContext.class);
    InstrumentClass aClass = mock(InstrumentClass.class);
    InstrumentMethod aMethod = mock(InstrumentMethod.class);
    MethodDescriptor aDescriptor = mock(MethodDescriptor.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    InstrumentContext context = mock(InstrumentContext.class);
    ClassLoader classLoader = getClass().getClassLoader();
    String className = "someClass";
    String methodName = "someMethod";
    byte[] classFileBuffer = new byte[0];
    Class<?>[] parameterTypes = new Class<?>[] { String.class };
    String[] parameterTypeNames = TypeUtils.toClassNames(parameterTypes);
    when(applicationContext.getInstrumentEngine()).thenReturn(instrumentEngine);
    when(applicationContext.getTraceContext()).thenReturn(traceContext);
    when(instrumentEngine.getClass(context, classLoader, className, classFileBuffer)).thenReturn(aClass);
    when(aClass.getDeclaredMethod(methodName, parameterTypeNames)).thenReturn(aMethod);
    when(aMethod.getName()).thenReturn(methodName);
    when(aMethod.getParameterTypes()).thenReturn(parameterTypeNames);
    when(aMethod.getDescriptor()).thenReturn(aDescriptor);
    when(aClass.addInterceptor(eq(methodName), va(eq(parameterTypeNames)))).thenReturn(0);
//        DefaultClassFileTransformerBuilder builder = new DefaultClassFileTransformerBuilder(context, "TargetClass");
//        builder.injectField("some.accessor.Type", "java.util.HashMap");
//        builder.injectGetter("some.getter.Type", "someField");
//
//        MethodTransformerBuilder ib = builder.editMethod(methodName, parameterTypeNames);
//        ib.injectInterceptor("com.navercorp.pinpoint.profiler.plugin.TestInterceptor", "provided");
//
//        ClassFileTransformer transformer = builder.build();
//
//        transformer.transform(classLoader, className, null, null, classFileBuffer);
//
//        verify(aMethod).addScopedInterceptor(eq("com.navercorp.pinpoint.profiler.plugin.TestInterceptor"), eq(va("provided")), (InterceptorScope)isNull(), (ExecutionPolicy)isNull());
//        verify(aClass).addField("some.accessor.Type", "new java.util.HashMap();");
//        verify(aClass).addGetter("some.getter.Type", "someField");
}
Also used : InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) ApplicationContext(com.navercorp.pinpoint.profiler.context.module.ApplicationContext) InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine) Test(org.junit.Test)

Example 2 with ApplicationContext

use of com.navercorp.pinpoint.profiler.context.module.ApplicationContext in project pinpoint by naver.

the class MockApplicationContextModuleTest method test.

@Test
public void test() {
    ProfilerConfig profilerConfig = new DefaultProfilerConfig();
    AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(), "mockAgent", "mockApplicationName", profilerConfig, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
    final PluginApplicationContextModule pluginApplicationContextModule = new PluginApplicationContextModule();
    PluginTestAgent pluginTestAgent = new PluginTestAgent(agentOption) {

        @Override
        protected ApplicationContext newApplicationContext(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
            ApplicationContext applicationContext = new DefaultApplicationContext(agentOption, interceptorRegistryBinder) {

                @Override
                protected Module newApplicationContextModule(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
                    Module applicationContextModule = super.newApplicationContextModule(agentOption, interceptorRegistryBinder);
                    //                        PluginApplicationContextModule pluginApplicationContextModule = new PluginApplicationContextModule();
                    return Modules.override(applicationContextModule).with(pluginApplicationContextModule);
                }
            };
            return applicationContext;
        }
    };
    try {
        pluginTestAgent.start();
    } finally {
        pluginTestAgent.stop(true);
    }
}
Also used : InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) ApplicationContext(com.navercorp.pinpoint.profiler.context.module.ApplicationContext) DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) DefaultServiceTypeRegistryService(com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) AgentOption(com.navercorp.pinpoint.bootstrap.AgentOption) DefaultAnnotationKeyRegistryService(com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService) Module(com.google.inject.Module) Test(org.junit.Test)

Example 3 with ApplicationContext

use of com.navercorp.pinpoint.profiler.context.module.ApplicationContext in project pinpoint by naver.

the class PluginTestAgent method verifyServerType.

@Override
public void verifyServerType(String serviceTypeName) {
    final ApplicationContext applicationContext = getApplicationContext();
    ServiceType expectedType = findServiceType(serviceTypeName);
    ServiceType actualType = applicationContext.getAgentInformation().getServerType();
    if (!expectedType.equals(actualType)) {
        throw new AssertionError("ResolvedExpectedTrace server type: " + expectedType.getName() + "[" + expectedType.getCode() + "] but was " + actualType + "[" + actualType.getCode() + "]");
    }
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) ApplicationContext(com.navercorp.pinpoint.profiler.context.module.ApplicationContext) ServiceType(com.navercorp.pinpoint.common.trace.ServiceType)

Example 4 with ApplicationContext

use of com.navercorp.pinpoint.profiler.context.module.ApplicationContext in project pinpoint by naver.

the class PluginTestAgent method newApplicationContext.

@Override
protected ApplicationContext newApplicationContext(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
    this.pluginApplicationContextModule = new PluginApplicationContextModule();
    ApplicationContext applicationContext = new DefaultApplicationContext(agentOption, interceptorRegistryBinder) {

        @Override
        protected Module newApplicationContextModule(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
            Module applicationContextModule = super.newApplicationContextModule(agentOption, interceptorRegistryBinder);
            return Modules.override(applicationContextModule).with(pluginApplicationContextModule);
        }
    };
    return applicationContext;
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) ApplicationContext(com.navercorp.pinpoint.profiler.context.module.ApplicationContext) InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) DefaultInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder) AgentOption(com.navercorp.pinpoint.bootstrap.AgentOption) Module(com.google.inject.Module)

Aggregations

ApplicationContext (com.navercorp.pinpoint.profiler.context.module.ApplicationContext)4 DefaultApplicationContext (com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext)3 Module (com.google.inject.Module)2 AgentOption (com.navercorp.pinpoint.bootstrap.AgentOption)2 InterceptorRegistryBinder (com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder)2 Test (org.junit.Test)2 DefaultAgentOption (com.navercorp.pinpoint.bootstrap.DefaultAgentOption)1 DefaultProfilerConfig (com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig)1 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)1 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)1 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)1 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)1 DefaultAnnotationKeyRegistryService (com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService)1 DefaultServiceTypeRegistryService (com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService)1 ServiceType (com.navercorp.pinpoint.common.trace.ServiceType)1 InstrumentEngine (com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)1 DefaultInterceptorRegistryBinder (com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder)1