use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtilityTest method testExtensionConversionUtilityValid.
@Test
public void testExtensionConversionUtilityValid() throws Exception {
File file = getFile(FILE_PATH_VALID);
Extension extension = ExtensionDomParser.readFileCatchException(file);
Assert.assertNotNull(extension);
List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.LocalCustomXml);
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/util/List;DI)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "timer", "([[Ljava/util/List;DI)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "timer", "(Ljava/util/List;)Ljava/lang/String", 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.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "noParamMethod", "()V", com.google.common.collect.ImmutableSet.<String>of()));
// test class matching
Assert.assertEquals(1, actual.getClassMatcher().getClassNames().size());
Collection<String> classes = actual.getClassMatcher().getClassNames();
Assert.assertTrue(classes.contains("test/network/TestViewer"));
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtilityTest method testExtensionConversionUtilityTest1.
@Test
public void testExtensionConversionUtilityTest1() throws Exception {
File file = getFile(FILE_PATH_1);
Extension extension = ExtensionDomParser.readFile(file);
Assert.assertNotNull(extension);
List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.LocalCustomXml);
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]);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method childClassMatcher.
@Test
public void childClassMatcher() throws Exception {
final String yaml = "kiddie:\n class_matcher: !or_class_matcher [ !child_class_matcher 'com/newrelic/agent/instrumentation/DefaultPointCut', !exact_class_matcher 'com/newrelic/agent/instrumentation/DefaultPointCut' ]\n method_matcher: !exact_method_matcher [ 'getTracerFactoryClassName', '()Ljava/lang/String;' ]";
PointCutConfig config = new PointCutConfig(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
Assert.assertEquals(1, config.getPointCuts().size());
Assert.assertNotNull(config.getPointCuts().get(0));
ExtensionClassAndMethodMatcher pointCut = config.getPointCuts().get(0);
MethodMatcher methodMatcher = pointCut.getMethodMatcher();
Assert.assertTrue(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getTracerFactoryClassName", "()Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getTracerFactoryClassName", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method metricPrefix.
@Test
public void metricPrefix() 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', '(Ljava/lang/String;)Ljava/lang/String;' ]\n metric_name_format: !class_method_metric_name_format 'ImportantMetricCategory'".getBytes(StandardCharsets.UTF_8)));
List<ExtensionClassAndMethodMatcher> pcs = config.getPointCuts();
Assert.assertEquals(1, pcs.size());
Assert.assertNotNull(config.getPointCuts().get(0));
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method defaultMetricPrefix.
@Test
public void defaultMetricPrefix() 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', '(Ljava/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);
// metric name prefix should be "Custom"
}
Aggregations