Search in sources :

Example 1 with Match

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

the class OptimizedClassMatcherTest method testSkipObjectMethods_exactMatch.

@Test
public void testSkipObjectMethods_exactMatch() throws IOException {
    List<MethodMatcher> matchers = new ArrayList<>();
    for (Method m : OBJECT_METHODS) {
        matchers.add(new ExactMethodMatcher(m.getName(), m.getDescriptor()));
    }
    ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), OrMethodMatcher.getMethodMatcher(matchers))).build();
    Match match = getMatch(matcher, MyObject.class);
    Assert.assertNull(match);
}
Also used : ClassMatchVisitorFactory(com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory) ArrayList(java.util.ArrayList) Method(org.objectweb.asm.commons.Method) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) AnnotationMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher) ExactReturnTypeMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher) OrMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) NameMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.NameMethodMatcher) AccessMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AccessMethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Example 2 with Match

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

the class OptimizedClassMatcherTest method testReturnTypeMatch.

@Test
public void testReturnTypeMatch() throws IOException {
    ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new ExactReturnTypeMethodMatcher(Type.getType(List.class)))).build();
    InstrumentationContext instrumentationContext = getInstrumentationContext(matcher, Arrays.class);
    Assert.assertFalse(instrumentationContext.getMatches().isEmpty());
    Match match = instrumentationContext.getMatches().values().iterator().next();
    Assert.assertNotNull(match);
    Assert.assertEquals(1, match.getMethods().size());
    Assert.assertTrue(match.getMethods().contains(new Method("asList", "([Ljava/lang/Object;)Ljava/util/List;")));
    Assert.assertEquals(1, match.getClassMatches().size());
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) ExactReturnTypeMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher) ClassMatchVisitorFactory(com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory) Method(org.objectweb.asm.commons.Method) Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Example 3 with Match

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

the class OptimizedClassMatcherTest method testSkipObjectMethods_looseMatch.

@Test
public void testSkipObjectMethods_looseMatch() throws IOException {
    ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AllMethodsMatcher())).build();
    Match match = getMatch(matcher, MyObject.class);
    Assert.assertNotNull(match);
    for (Method m : OBJECT_METHODS) {
        Assert.assertFalse(match.getMethods().contains(m));
    }
}
Also used : ClassMatchVisitorFactory(com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory) Method(org.objectweb.asm.commons.Method) AllMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher) Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Example 4 with Match

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

the class OptimizedClassMatcherTest method testNonMatch.

@Test
public void testNonMatch() throws IOException {
    Match match = getMatch(matcher, Executor.class);
    Assert.assertNull(match);
}
Also used : Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Example 5 with Match

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

the class OptimizedClassMatcherTest method testSingleMatch2.

@Test
public void testSingleMatch2() throws IOException {
    InvocationHandler handler = new InvocationHandler() {

        public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) throws Throwable {
            return null;
        }
    };
    Match match = getMatch(matcher, handler.getClass());
    Assert.assertNotNull(match);
    Assert.assertEquals(1, match.getMethods().size());
    Assert.assertTrue(match.getMethods().contains(new Method("invoke", "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;")));
    Assert.assertEquals(1, match.getClassMatches().size());
    Assert.assertTrue(match.getClassMatches().containsKey(match3));
}
Also used : Method(org.objectweb.asm.commons.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Aggregations

Match (com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match)12 Test (org.junit.Test)12 Method (org.objectweb.asm.commons.Method)11 ClassMatchVisitorFactory (com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory)3 InstrumentationContext (com.newrelic.agent.instrumentation.context.InstrumentationContext)3 ExactReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher)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 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)1 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)1 NameMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.NameMethodMatcher)1 OrMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 ArrayList (java.util.ArrayList)1