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;
}
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")));
}
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")));
}
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;
}
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;
}
Aggregations