use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher 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.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method orMethodMatcherConcise2.
/*
* @Test public void orMethodMatcherConcise() throws Exception { String yaml =
* "- class_matcher: 'java/lang/Foo'\n method_matcher:\n - 'getFoo'\n - 'getBar'"; PointCutConfig config = new
* PointCutConfig(new ByteArrayInputStream(yaml.getBytes("UTF-8"))); Assert.assertEquals(1,
* config.getPointCuts().size()); Assert.assertNotNull(config.getPointCuts().get(0)); }
*/
@Test
public void orMethodMatcherConcise2() throws Exception {
String yaml = "- class_matcher: 'java/lang/Foo'\n method_matcher: [ [ 'getFoo', '()V' ], [ 'getBar', '()I' ] ]";
PointCutConfig config = new PointCutConfig(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
Assert.assertEquals(1, config.getPointCuts().size());
Assert.assertNotNull(config.getPointCuts().get(0));
MethodMatcher excludes = config.getPointCuts().get(0).getMethodMatcher();
Assert.assertTrue(excludes.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getFoo", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(excludes.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getBar", "()I", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(excludes.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getBar", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(excludes.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getFoo", "()I", com.google.common.collect.ImmutableSet.<String>of()));
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method exactMethodMatcherConcise.
/*
* @Test public void noName() throws Exception { final String yaml =
* "- class_matcher: !exact_class_matcher 'java/lang/String'\n method_matcher: !name_method_matcher 'getBytes'";
* PointCutConfig config = new PointCutConfig(new ByteArrayInputStream(yaml.getBytes("UTF-8")));
* Assert.assertEquals(1, config.getPointCuts().size()); Assert.assertNotNull(config.getPointCuts().get(0)); }
*
* @Test public void nameMethodMatcher() throws Exception { final String yaml =
* "namen:\n class_matcher: !exact_class_matcher 'java/lang/String'\n method_matcher: !name_method_matcher 'getBytes'"
* ; PointCutConfig config = new PointCutConfig(new ByteArrayInputStream(yaml.getBytes("UTF-8")));
* Assert.assertEquals(1, config.getPointCuts().size()); Assert.assertNotNull(config.getPointCuts().get(0)); }
*/
@Test
public void exactMethodMatcherConcise() throws Exception {
final String yaml = "oder:\n class_matcher: 'java/lang/String'\n method_matcher: [ 'concat', '(Ljava/lang/String;)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));
MethodMatcher methodMatcher = config.getPointCuts().get(0).getMethodMatcher();
Assert.assertTrue(methodMatcher instanceof ExactMethodMatcher);
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method exactMethodMatcherEvenMoreConcise.
@Test
public void exactMethodMatcherEvenMoreConcise() throws Exception {
final String yaml = "oder:\n class_matcher: java/lang/String\n method_matcher: concat(Ljava/lang/String;)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));
MethodMatcher methodMatcher = config.getPointCuts().get(0).getMethodMatcher();
Assert.assertTrue(config.getPointCuts().get(0).getClassMatcher() instanceof ExactClassMatcher);
Assert.assertTrue(methodMatcher instanceof ExactMethodMatcher);
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method staticMethodMatcher.
@Test
public void staticMethodMatcher() throws Exception {
final String yaml = "oder:\n class_matcher: java/lang/String\n method_matcher: !static_method_matcher [ concat(Ljava/lang/String;)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));
MethodMatcher methodMatcher = config.getPointCuts().get(0).getMethodMatcher();
Assert.assertTrue(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "concat", "(Ljava/lang/String;)Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "dude", "(Ljava/lang/String;)Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
}
Aggregations