Search in sources :

Example 31 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionDomParserTest method testSuperclassPointCut.

@Test
public void testSuperclassPointCut() throws Exception {
    Extension ext = ExtensionDomParser.readFile(getFile(SUPERCLASS_FILE_PATH));
    Instrumentation inst = ext.getInstrumentation();
    List<Pointcut> thePcs = inst.getPointcut();
    Assert.assertEquals(2, thePcs.size());
    Pointcut pc = thePcs.get(0);
    Assert.assertNotNull(pc.getClassName());
    Assert.assertEquals("test.SuperTest", pc.getClassName().getValue());
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(2, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    Assert.assertTrue(actual.getClassMatcher() instanceof ChildClassMatcher);
    ExtensionClassAndMethodMatcher returnMatcher = pcs.get(1);
    Assert.assertTrue(returnMatcher.getClassMatcher() instanceof ChildClassMatcher);
    Assert.assertTrue(returnMatcher.getMethodMatcher() instanceof ExactReturnTypeMethodMatcher);
    Assert.assertTrue(returnMatcher.getMethodMatcher().matches(Opcodes.ACC_PUBLIC, "bogus", "()Lcom/framework/Result;", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(returnMatcher.getMethodMatcher().matches(Opcodes.ACC_PUBLIC, "test", "()[Lcom/framework/Result;", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(returnMatcher.getMethodMatcher().matches(Opcodes.ACC_PUBLIC, "dude", "(Lcom/framework/Result;)V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExactReturnTypeMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation) ChildClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher) Test(org.junit.Test)

Example 32 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionDomParserTest method testClassInterface.

@Test
public void testClassInterface() throws Exception {
    Extension ext = ExtensionDomParser.readFile(getFile(FILE_PATH_7_INTERFACE_CLASS));
    // ext attributes
    Assert.assertEquals("test1", ext.getName());
    Assert.assertEquals(1.0, ext.getVersion(), .001);
    Assert.assertTrue(ext.isEnabled());
    Instrumentation inst = ext.getInstrumentation();
    List<Pointcut> thePcs = inst.getPointcut();
    Assert.assertEquals(2, thePcs.size());
    Pointcut pc = thePcs.get(0);
    Assert.assertTrue(pc.isTransactionStartPoint());
    Assert.assertEquals("com.newrelic.agent.extension.beans.Extension", pc.getClassName().getValue());
    Assert.assertNull(pc.getInterfaceName());
    List<Method> methods = pc.getMethod();
    Assert.assertEquals(1, methods.size());
    pc = thePcs.get(1);
    Assert.assertTrue(pc.isTransactionStartPoint());
    Assert.assertEquals("com.newrelic.agent.Agent", pc.getInterfaceName());
    Assert.assertNull(pc.getClassName());
    methods = pc.getMethod();
    Assert.assertEquals(2, methods.size());
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(2, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    Assert.assertEquals(ExactClassMatcher.class, actual.getClassMatcher().getClass());
    actual = pcs.get(1);
    Assert.assertEquals(InterfaceMatcher.class, actual.getClassMatcher().getClass());
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation) Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) Test(org.junit.Test)

Example 33 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionConversionUtilityTest method testExtensionConversionUtilityAttributes.

@Test
public void testExtensionConversionUtilityAttributes() throws Exception {
    File file = getFile(FILE_PATH_ATTS);
    Extension extension = ExtensionDomParser.readFile(file);
    Assert.assertNotNull(extension);
    // default is to include atts
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.RemoteCustomXml);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(1, pcs.size());
    List<ParameterAttributeName> actualAtts = pcs.get(0).getTraceDetails().getParameterAttributeNames();
    verifyAttNames(actualAtts, Arrays.asList("param1", "param2", "reportMe"));
    pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.RemoteCustomXml, true);
    actualAtts = pcs.get(0).getTraceDetails().getParameterAttributeNames();
    verifyAttNames(actualAtts, Arrays.asList("param1", "param2", "reportMe"));
    pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.RemoteCustomXml, false);
    actualAtts = pcs.get(0).getTraceDetails().getParameterAttributeNames();
    Assert.assertEquals(0, actualAtts.size());
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) ParameterAttributeName(com.newrelic.agent.instrumentation.tracing.ParameterAttributeName) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AgentHelper.getFile(com.newrelic.agent.AgentHelper.getFile) File(java.io.File) Test(org.junit.Test)

Example 34 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionConversionUtilityTest method testExtensionConversionUtilityTest6.

/**
 * This tests multiple classes and methods.
 */
@Test
public void testExtensionConversionUtilityTest6() throws Exception {
    File file = getFile(FILE_PATH_6_MULTIPLES);
    Extension extension = ExtensionDomParser.readFile(file);
    Assert.assertNotNull(extension);
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.RemoteCustomXml);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(1, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    // test method matching
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(B)V", com.google.common.collect.ImmutableSet.<String>of()));
    // test class matching
    Assert.assertEquals(1, actual.getClassMatcher().getClassNames().size());
    Assert.assertEquals("test/CustomExampleTest", actual.getClassMatcher().getClassNames().toArray()[0]);
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AgentHelper.getFile(com.newrelic.agent.AgentHelper.getFile) File(java.io.File) Test(org.junit.Test)

Example 35 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class PointCutConfigTest method invalidMethodDescriptor.

@Test
public void invalidMethodDescriptor() throws Exception {
    PointCutConfig config = new PointCutConfig(new ByteArrayInputStream("pre:\n  class_matcher: !exact_class_matcher 'java/lang/String'\n  method_matcher: !exact_method_matcher [ 'concat', '(java/lang/String;)Ljava/lang/String;' ]\n".getBytes(StandardCharsets.UTF_8)));
    List<ExtensionClassAndMethodMatcher> pcs = config.getPointCuts();
    Assert.assertEquals(1, pcs.size());
    ExtensionClassAndMethodMatcher pc = config.getPointCuts().get(0);
    Assert.assertNotNull(pc);
    MethodMatcher methodMatcher = pc.getMethodMatcher();
    Assert.assertTrue(methodMatcher instanceof NoMethodsMatcher);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) NoMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.NoMethodsMatcher) ByteArrayInputStream(java.io.ByteArrayInputStream) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) Test(org.junit.Test)

Aggregations

ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)36 Test (org.junit.Test)26 Extension (com.newrelic.agent.extension.beans.Extension)11 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)10 ArrayList (java.util.ArrayList)10 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)9 Instrumentation (com.newrelic.agent.extension.beans.Extension.Instrumentation)8 File (java.io.File)6 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LinkedList (java.util.LinkedList)5 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)4 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)3 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)3 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)3 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)2 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1