use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionServiceTest method testXMLWithNoNameOrVersion2.
/**
* The first file should not be read in because it does not have a name or version.
*/
@Test
public void testXMLWithNoNameOrVersion2() throws Exception {
setupFiles(true, XML_NO_NAME_OR_VERSION, XML_FILE_PATH_1);
List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
assertNotNull(pcs);
assertEquals(3, pcs.size());
List<String> classNames = new ArrayList<>();
List<MethodMatcher> mms = new ArrayList<>();
for (ExtensionClassAndMethodMatcher pc : pcs) {
classNames.addAll(pc.getClassMatcher().getClassNames());
mms.add(pc.getMethodMatcher());
}
// verify that classes
assertEquals(3, classNames.size());
assertTrue(classNames.contains("test/CustomExtensionTest$1"));
assertTrue(classNames.contains("test/AbstractCustomExtensionTest"));
assertTrue(classNames.contains("test/CustomExtensionTest"));
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionServiceTest method testXMLExtensionCaptureMethodParams.
@Test
public void testXMLExtensionCaptureMethodParams() throws Exception {
setupFiles(true, XML_CAPTURE_METHOD_PARAMS);
List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
assertNotNull(pcs);
assertEquals(1, pcs.size());
List<String> classNames = new ArrayList<>();
List<MethodMatcher> mms = new ArrayList<>();
for (ExtensionClassAndMethodMatcher pc : pcs) {
classNames.addAll(pc.getClassMatcher().getClassNames());
mms.add(pc.getMethodMatcher());
}
// verify classes
assertEquals(1, classNames.size());
assertTrue(classNames.contains("com/nr/Client/impl/OkClient"));
// verify the methods
assertEquals(1, mms.size());
verifyMatch("myMethod", "(Ljava/lang/String;J)V", mms);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionServiceTest method testXMLExtensionDifferentVersions.
/**
* Tests that only the xml with the higher version gets read in.
*/
@Test
public void testXMLExtensionDifferentVersions() throws Exception {
setupFiles(true, XML_FILE_PATH_1, XML_FILE_PATH_1_1);
List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
assertNotNull(pcs);
assertEquals(3, pcs.size());
List<String> classNames = new ArrayList<>();
List<MethodMatcher> mms = new ArrayList<>();
for (ExtensionClassAndMethodMatcher pc : pcs) {
classNames.addAll(pc.getClassMatcher().getClassNames());
mms.add(pc.getMethodMatcher());
}
// verify that classes
assertEquals(3, classNames.size());
assertTrue(classNames.contains("test/CustomExtensionTest$1"));
assertTrue(classNames.contains("test/AbstractCustomExtensionTest1"));
assertTrue(classNames.contains("test/CustomExtensionTest1"));
// verify methods
assertEquals(3, mms.size());
verifyMatch("run", "()V", mms);
verifyMatch("abstractTest11", "()V", mms);
verifyMatch("abstractTest21", "()V", mms);
verifyMatch("test2", "(Ljava/lang/String;I)V", mms);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionDomParserTest method testInterfacePointCut.
@Test
public void testInterfacePointCut() throws Exception {
Extension ext = ExtensionDomParser.readFile(getFile(INTERFACE_FILE_PATH));
Instrumentation inst = ext.getInstrumentation();
List<Pointcut> thePcs = inst.getPointcut();
Assert.assertEquals(1, thePcs.size());
Pointcut pc = thePcs.get(0);
Assert.assertNull(pc.getClassName());
Assert.assertEquals("javax.servlet.Filter", pc.getInterfaceName());
// Assert.assertEquals(ClassType.INTERFACE_NAME, pc.getClassType());
List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
Assert.assertNotNull(pcs);
Assert.assertEquals(1, pcs.size());
ExtensionClassAndMethodMatcher actual = pcs.get(0);
Assert.assertTrue(actual.getClassMatcher() instanceof InterfaceMatcher);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionDomParserTest method testDomOnePointCut.
@Test
public void testDomOnePointCut() throws Exception {
Extension ext = ExtensionDomParser.readFile(getFile(FILE_PATH_1));
// ext attributes
Assert.assertEquals("test1", ext.getName());
Assert.assertEquals(1.0, ext.getVersion(), .001);
Assert.assertTrue(ext.isEnabled());
Instrumentation inst = ext.getInstrumentation();
Assert.assertEquals("PREFIX", inst.getMetricPrefix());
List<Pointcut> thePcs = inst.getPointcut();
Assert.assertEquals(1, thePcs.size());
Pointcut pc = thePcs.get(0);
Assert.assertTrue(pc.isTransactionStartPoint());
Assert.assertFalse(pc.isIgnoreTransaction());
Assert.assertFalse(pc.isExcludeFromTransactionTrace());
Assert.assertFalse(pc.isLeaf());
Assert.assertNull(pc.getMetricNameFormat());
Assert.assertEquals("test.CustomExampleTest", pc.getClassName().getValue());
List<Method> methods = pc.getMethod();
Assert.assertEquals(2, methods.size());
Assert.assertEquals("run", methods.get(0).getName());
Assert.assertEquals("finish", methods.get(1).getName());
Assert.assertEquals("(Ljava/lang/String;Ljava/lang/String;)", MethodParameters.getDescriptor(methods.get(0).getParameters()));
Assert.assertEquals("(F)", MethodParameters.getDescriptor(methods.get(1).getParameters()));
List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
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]);
}
Aggregations