Search in sources :

Example 6 with DefaultClassAndMethodMatcher

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

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

the class ClassesMatcherTest method getMatchingClasses_Annotation.

@Trace
@Test
public void getMatchingClasses_Annotation() {
    ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AnnotationMethodMatcher(Type.getType(Trace.class)))).build();
    Set<Class<?>> matchingClasses = ClassesMatcher.getMatchingClasses(Collections.singletonList(matcher), matcherHelper, ClassesMatcherTest.class, ArrayList.class, HashMap.class);
    assertEquals(1, matchingClasses.size());
    assertTrue(matchingClasses.contains(ClassesMatcherTest.class));
}
Also used : DefaultClassAndMethodMatcher(com.newrelic.agent.instrumentation.classmatchers.DefaultClassAndMethodMatcher) AllClassesMatcher(com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher) AnnotationMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher) Trace(com.newrelic.api.agent.Trace) Test(org.junit.Test)

Aggregations

DefaultClassAndMethodMatcher (com.newrelic.agent.instrumentation.classmatchers.DefaultClassAndMethodMatcher)7 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)5 Test (org.junit.Test)5 HashSafeClassAndMethodMatcher (com.newrelic.agent.instrumentation.classmatchers.HashSafeClassAndMethodMatcher)3 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)3 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)2 Trace (com.newrelic.api.agent.Trace)2 AccessMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AccessMethodMatcher)1 AllMethodsMatcher (com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher)1 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)1 ExactReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher)1 NotMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.NotMethodMatcher)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 BeforeClass (org.junit.BeforeClass)1