Search in sources :

Example 11 with ExactClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher 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 12 with ExactClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher in project newrelic-java-agent by newrelic.

the class ClassTransformerServiceTest method addTraceMatcher.

@Test
public void addTraceMatcher() throws UnmodifiableClassException {
    Assert.assertFalse(TestClass.class.isAnnotationPresent(InstrumentedClass.class));
    ServiceFactory.getClassTransformerService().addTraceMatcher(new DefaultClassAndMethodMatcher(new ExactClassMatcher(Type.getType(ClassTransformerServiceTest.class).getInternalName() + "$TestClass"), new AllMethodsMatcher()), "dude");
    ServiceFactory.getCoreService().getInstrumentation().retransformClasses(TestClass.class);
    Assert.assertTrue(TestClass.class.isAnnotationPresent(InstrumentedClass.class));
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) DefaultClassAndMethodMatcher(com.newrelic.agent.instrumentation.classmatchers.DefaultClassAndMethodMatcher) AllMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher) Test(org.junit.Test)

Example 13 with ExactClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher in project newrelic-java-agent by newrelic.

the class PointCutConfigTest method incrediblyConcisePointcut.

@Test
public void incrediblyConcisePointcut() throws Exception {
    final String yaml = "oder:\n  java/lang/String.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();
    ClassMatcher classMatcher = config.getPointCuts().get(0).getClassMatcher();
    Assert.assertTrue(classMatcher instanceof ExactClassMatcher);
    Assert.assertTrue(classMatcher.isMatch(String.class));
    Assert.assertFalse(classMatcher.isMatch(List.class));
    Assert.assertTrue(methodMatcher instanceof ExactMethodMatcher);
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ClassMatcher) ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) 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 ExactClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher in project newrelic-java-agent by newrelic.

the class PointCutTest method verifyEqualsAndHashCode.

@Test
public void verifyEqualsAndHashCode() throws Exception {
    AgentTestUtils.createServiceManager(new HashMap<String, Object>());
    PointCut pc1 = new DefaultPointCut(new PointCutConfiguration("hi"), null, new ExactClassMatcher("myclass"), new ExactMethodMatcher("mymethod", "()V"));
    PointCut pc2 = new DefaultPointCut(new PointCutConfiguration("hi"), null, new ExactClassMatcher("myclass"), new ExactMethodMatcher("mymethod", "()V"));
    Assert.assertTrue(pc1.equals(pc2));
    Assert.assertEquals(pc1.hashCode(), pc2.hashCode());
    pc2 = new DefaultPointCut(new PointCutConfiguration("hi"), null, new ExactClassMatcher("myotherClass"), new ExactMethodMatcher("mymethod", "()V"));
    Assert.assertFalse(pc1.equals(pc2));
    Assert.assertNotSame(pc1.hashCode(), pc2.hashCode());
    pc2 = new DefaultPointCut(new PointCutConfiguration("hi"), null, new ExactClassMatcher("myclass"), new ExactMethodMatcher("myothermethod", "()V"));
    Assert.assertFalse(pc1.equals(pc2));
    Assert.assertNotSame(pc1.hashCode(), pc2.hashCode());
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) Test(org.junit.Test)

Aggregations

ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)14 Test (org.junit.Test)12 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)7 DefaultClassAndMethodMatcher (com.newrelic.agent.instrumentation.classmatchers.DefaultClassAndMethodMatcher)5 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)4 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)3 HashSafeClassAndMethodMatcher (com.newrelic.agent.instrumentation.classmatchers.HashSafeClassAndMethodMatcher)3 AllMethodsMatcher (com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher)2 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)1 ClassName (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.ClassName)1 AndClassMatcher (com.newrelic.agent.instrumentation.classmatchers.AndClassMatcher)1 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)1 NotMatcher (com.newrelic.agent.instrumentation.classmatchers.NotMatcher)1 OrClassMatcher (com.newrelic.agent.instrumentation.classmatchers.OrClassMatcher)1 AccessMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AccessMethodMatcher)1 NotMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.NotMethodMatcher)1