Search in sources :

Example 1 with SpringPointCut

use of com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method testSpringPointcutEnabledDefaultDisabled.

@Test
public void testSpringPointcutEnabledDefaultDisabled() {
    Map<String, Object> configuration = new HashMap<>();
    configuration.put("class_transformer:instrumentation_default:enabled", false);
    configuration.put("enable_spring_tracing", true);
    configuration.put("app_name", "Unit Test");
    configuration = buildConfigMap(configuration);
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
    ServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
    assertTrue(springPointCut.isEnabled());
}
Also used : SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 2 with SpringPointCut

use of com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method testSpringPointcutEnabled.

@Test
public void testSpringPointcutEnabled() {
    Map<String, Object> configuration = new HashMap<>();
    configuration.put("lite_mode", true);
    configuration.put("class_transformer:instrumentation_default:enabled", true);
    configuration.put("enable_spring_tracing", true);
    configuration.put("app_name", "Unit Test");
    configuration = buildConfigMap(configuration);
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
    ServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
    assertTrue(springPointCut.isEnabled());
}
Also used : SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 3 with SpringPointCut

use of com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method testSpringPointcutDisabled.

@Test
public void testSpringPointcutDisabled() {
    Map<String, Object> classTransformerMap = new HashMap<>();
    Map<String, Object> defaultInstrumentationSettings = new HashMap<>();
    defaultInstrumentationSettings.put("enabled", false);
    classTransformerMap.put(ClassTransformerConfigImpl.DEFAULT_INSTRUMENTATION, defaultInstrumentationSettings);
    Map<String, Object> configSettings = new HashMap<>();
    configSettings.put(AgentConfigImpl.CLASS_TRANSFORMER, classTransformerMap);
    configSettings.put(AgentConfigImpl.APP_NAME, "Unit Test");
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configSettings);
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
    ServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
    assertFalse(springPointCut.isEnabled());
}
Also used : SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 4 with SpringPointCut

use of com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut in project newrelic-java-agent by newrelic.

the class ClassTransformerTest method test.

@Test
public void test() {
    PointCutClassTransformer classTransformer = ServiceFactory.getClassTransformerService().getClassTransformer();
    Collection<PointCut> pcs = new ArrayList<>();
    try {
        Method method = classTransformer.getClass().getDeclaredMethod("findEnabledPointCuts");
        method.setAccessible(true);
        pcs = (Collection<PointCut>) method.invoke(classTransformer);
    } catch (Exception e) {
        e.printStackTrace();
        fail("An exception occurred: " + e.getMessage());
    }
    List<? extends PointCut> manual = Arrays.asList(// struts
    new StrutsActionPointCut(classTransformer), new Struts2ActionPointCut(classTransformer), new StrutsActionConfigMatcherPointCut(classTransformer), new XWork2ResultPC(classTransformer), // Spring
    new SpringPointCut(classTransformer), // new SpringWildcardPathPointCut(classTransformer),
    new SpringDispatcherPointCut(classTransformer), new HandlerInterceptorPointCut(classTransformer), new HandlerMethodInvokerPointCut(classTransformer), new SpringExceptionHandlerPointCut(classTransformer), // Faces
    new LifecyclePointCut(classTransformer), // CXF
    new CXFPointCut(classTransformer), new CXFInvokerPointCut(classTransformer), new ClientProxyPointCut(classTransformer), // portlet
    new ProcessActionPortletPointCut(classTransformer), new RenderPortletPointCut(classTransformer), // Tomcat
    new JasperCompilerPointCut(classTransformer), new XmlRpcPointCut(classTransformer), // java concurrent
    new MathCSConcurrentPointCut(classTransformer));
    Set<String> manualNamesEnabled = new HashSet<>();
    Set<String> manualNamesDisabled = new HashSet<>();
    for (PointCut pc : manual) {
        if (pc.isEnabled()) {
            manualNamesEnabled.add(pc.getClass().getName());
        } else {
            manualNamesDisabled.add(pc.getClass().getName());
        }
    }
    Set<String> allNames = new HashSet<>();
    for (PointCut pc : pcs) {
        allNames.add(pc.getClass().getName());
    }
    Set<String> missing = new HashSet<>(manualNamesEnabled);
    missing.removeAll(allNames);
    // all of the enabled should be present
    Assert.assertTrue(missing.toString(), allNames.containsAll(manualNamesEnabled));
    // all of the disabled should not be present
    for (String disabled : manualNamesDisabled) {
        Assert.assertFalse(allNames.contains(disabled));
    }
}
Also used : SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) ProcessActionPortletPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.ProcessActionPortletPointCut) SpringExceptionHandlerPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringExceptionHandlerPointCut) SpringDispatcherPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringDispatcherPointCut) ArrayList(java.util.ArrayList) CXFPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.CXFPointCut) SpringExceptionHandlerPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringExceptionHandlerPointCut) JasperCompilerPointCut(com.newrelic.agent.instrumentation.pointcuts.container.JasperCompilerPointCut) CXFInvokerPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.CXFInvokerPointCut) LifecyclePointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.faces.LifecyclePointCut) HandlerInterceptorPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.HandlerInterceptorPointCut) SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) Struts2ActionPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.Struts2ActionPointCut) StrutsActionPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.StrutsActionPointCut) RenderPortletPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.RenderPortletPointCut) MathCSConcurrentPointCut(com.newrelic.agent.instrumentation.pointcuts.MathCSConcurrentPointCut) ProcessActionPortletPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.ProcessActionPortletPointCut) XmlRpcPointCut(com.newrelic.agent.instrumentation.pointcuts.XmlRpcPointCut) HandlerMethodInvokerPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.HandlerMethodInvokerPointCut) SpringDispatcherPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringDispatcherPointCut) ClientProxyPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.ClientProxyPointCut) StrutsActionConfigMatcherPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.StrutsActionConfigMatcherPointCut) CXFInvokerPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.CXFInvokerPointCut) CXFPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.CXFPointCut) StrutsActionPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.StrutsActionPointCut) XmlRpcPointCut(com.newrelic.agent.instrumentation.pointcuts.XmlRpcPointCut) MathCSConcurrentPointCut(com.newrelic.agent.instrumentation.pointcuts.MathCSConcurrentPointCut) LifecyclePointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.faces.LifecyclePointCut) HandlerInterceptorPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.HandlerInterceptorPointCut) JasperCompilerPointCut(com.newrelic.agent.instrumentation.pointcuts.container.JasperCompilerPointCut) HashSet(java.util.HashSet) RenderPortletPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.RenderPortletPointCut) Method(java.lang.reflect.Method) Struts2ActionPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.Struts2ActionPointCut) StrutsActionConfigMatcherPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.StrutsActionConfigMatcherPointCut) XWork2ResultPC(com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.XWork2ResultPC) HandlerMethodInvokerPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.HandlerMethodInvokerPointCut) ClientProxyPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.ClientProxyPointCut) Test(org.junit.Test)

Example 5 with SpringPointCut

use of com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method testSpringPointcutDisabledDefaultEnabled.

@Test
public void testSpringPointcutDisabledDefaultEnabled() {
    Map<String, Object> configuration = new HashMap<>();
    configuration.put("class_transformer:instrumentation_default:enabled", true);
    configuration.put("enable_spring_tracing", false);
    configuration.put("app_name", "Unit Test");
    configuration = buildConfigMap(configuration);
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
    ServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
    assertFalse(springPointCut.isEnabled());
}
Also used : SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Aggregations

SpringPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut)5 Test (org.junit.Test)5 MockServiceManager (com.newrelic.agent.MockServiceManager)4 ServiceManager (com.newrelic.agent.service.ServiceManager)4 HashMap (java.util.HashMap)4 MathCSConcurrentPointCut (com.newrelic.agent.instrumentation.pointcuts.MathCSConcurrentPointCut)1 XmlRpcPointCut (com.newrelic.agent.instrumentation.pointcuts.XmlRpcPointCut)1 JasperCompilerPointCut (com.newrelic.agent.instrumentation.pointcuts.container.JasperCompilerPointCut)1 ProcessActionPortletPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.ProcessActionPortletPointCut)1 RenderPortletPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.RenderPortletPointCut)1 CXFInvokerPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.CXFInvokerPointCut)1 CXFPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.CXFPointCut)1 ClientProxyPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.cxf.ClientProxyPointCut)1 LifecyclePointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.faces.LifecyclePointCut)1 HandlerInterceptorPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.HandlerInterceptorPointCut)1 HandlerMethodInvokerPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.HandlerMethodInvokerPointCut)1 SpringDispatcherPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringDispatcherPointCut)1 SpringExceptionHandlerPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringExceptionHandlerPointCut)1 Struts2ActionPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.Struts2ActionPointCut)1 StrutsActionConfigMatcherPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.struts.StrutsActionConfigMatcherPointCut)1