Search in sources :

Example 11 with InstrumentationContext

use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.

the class OptimizedClassMatcherTest method getInstrumentationContext.

private InstrumentationContext getInstrumentationContext(ClassMatchVisitorFactory matcher2, Class<?> clazz) throws IOException {
    ClassLoader loader = clazz.getClassLoader();
    if (loader == null) {
        loader = ClassLoader.getSystemClassLoader();
    }
    ClassReader reader = ClassMatcherTest.getClassReader(clazz);
    InstrumentationContext context = new InstrumentationContext(null, null, Mockito.mock(ProtectionDomain.class));
    context.match(loader, null, reader, Arrays.asList(matcher2));
    return context;
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) ProtectionDomain(java.security.ProtectionDomain) ClassReader(org.objectweb.asm.ClassReader)

Example 12 with InstrumentationContext

use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.

the class OptimizedClassMatcherTest method testAnnotationMatch.

@Test
public void testAnnotationMatch() throws IOException {
    InstrumentationContext instrumentationContext = getInstrumentationContext(matcher, AnnotatedClass.class);
    Match match = instrumentationContext.getMatches().values().iterator().next();
    Assert.assertNotNull(match);
    Assert.assertEquals(2, match.getMethods().size());
    Assert.assertTrue(match.getMethods().contains(new Method("annotation1", "()V")));
    Assert.assertTrue(match.getMethods().contains(new Method("annotation2", "()Z")));
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) Method(org.objectweb.asm.commons.Method) Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Example 13 with InstrumentationContext

use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.

the class TraceByReturnTypeMatchVisitorTest method testFutureAndStringReturnType.

@Test
public void testFutureAndStringReturnType() throws IOException {
    InstrumentationContext context = instrumentClass(FutureAndStringInstrumented.class);
    Set<Method> tracedMethods = context.getTraceInformation().getTraceAnnotations().keySet();
    Set<String> tracedMethodNames = methodNames(tracedMethods);
    Assert.assertTrue(allMatchTypeDescriptor(tracedMethods, Future.class, String.class));
    Assert.assertThat(tracedMethodNames, containsInAnyOrder("returnString", "returnFuture"));
    Assert.assertThat(tracedMethodNames, not(contains("returnInteger")));
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) Future(java.util.concurrent.Future) Method(org.objectweb.asm.commons.Method) Test(org.junit.Test)

Example 14 with InstrumentationContext

use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.

the class TraceByReturnTypeMatchVisitorTest method instrumentClass.

private InstrumentationContext instrumentClass(Class<?> clazz) throws IOException {
    InstrumentationContext context = new InstrumentationContext(null, clazz, clazz.getProtectionDomain());
    ClassReader reader = new ClassReader(clazz.getName());
    ClassVisitor visitor = new TraceByReturnTypeMatchVisitor().newClassMatchVisitor(clazz.getClassLoader(), clazz, reader, new ClassWriter(0), context);
    reader.accept(visitor, 0);
    return context;
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) TraceByReturnTypeMatchVisitor(com.newrelic.agent.instrumentation.context.TraceByReturnTypeMatchVisitor) ClassWriter(org.objectweb.asm.ClassWriter)

Example 15 with InstrumentationContext

use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.

the class PatternNonstaticExample method visit.

private InstrumentationContext visit(Class<?> clazz) throws IOException {
    InstrumentationContext context = new InstrumentationContext(null, clazz, clazz.getProtectionDomain());
    ClassReader reader = new ClassReader(clazz.getName());
    ClassVisitor visitor = new TraceLambdaVisitor().newClassMatchVisitor(clazz.getClassLoader(), clazz, reader, new ClassWriter(0), context);
    reader.accept(visitor, 0);
    return context;
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter)

Aggregations

InstrumentationContext (com.newrelic.agent.instrumentation.context.InstrumentationContext)15 Test (org.junit.Test)10 Method (org.objectweb.asm.commons.Method)9 ClassReader (org.objectweb.asm.ClassReader)7 ClassVisitor (org.objectweb.asm.ClassVisitor)4 ClassWriter (org.objectweb.asm.ClassWriter)4 Match (com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match)3 ClassMatchVisitorFactory (com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory)3 TestLogger (com.newrelic.agent.bridge.TestLogger)2 RequireMethodsAdapter (com.newrelic.agent.instrumentation.RequireMethodsAdapter)2 ClassMatcherTest (com.newrelic.agent.instrumentation.classmatchers.ClassMatcherTest)2 TraceClassVisitor (com.newrelic.agent.instrumentation.tracing.TraceClassVisitor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 ClassReader (com.newrelic.agent.deps.org.objectweb.asm.ClassReader)1 ClassVisitor (com.newrelic.agent.deps.org.objectweb.asm.ClassVisitor)1 ClassWriter (com.newrelic.agent.deps.org.objectweb.asm.ClassWriter)1