Search in sources :

Example 11 with MethodMatcher

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()));
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) 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)

Example 12 with MethodMatcher

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()));
}
Also used : 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)

Example 13 with MethodMatcher

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) 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)

Example 14 with MethodMatcher

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);
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ByteArrayInputStream(java.io.ByteArrayInputStream) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) 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)

Example 15 with MethodMatcher

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()));
}
Also used : 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

MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)21 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)19 Test (org.junit.Test)16 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)11 ArrayList (java.util.ArrayList)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)3 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)3 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)3 OrMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher)3 LambdaMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.LambdaMethodMatcher)2 ReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ReturnTypeMethodMatcher)2 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)2 List (java.util.List)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 Extension (com.newrelic.agent.extension.beans.Extension)1 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)1 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1