use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.
the class TraceByReturnTypeMatchVisitorTest method testStringReturnType.
@Test
public void testStringReturnType() throws IOException {
InstrumentationContext context = instrumentClass(StringInstrumented.class);
Set<Method> tracedMethods = context.getTraceInformation().getTraceAnnotations().keySet();
Set<String> tracedMethodNames = methodNames(tracedMethods);
Assert.assertTrue(allMatchTypeDescriptor(tracedMethods, String.class));
Assert.assertThat(tracedMethodNames, containsInAnyOrder("returnString"));
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 testFutureReturnType.
@Test
public void testFutureReturnType() throws IOException {
InstrumentationContext context = instrumentClass(JavaFutureInstrumented.class);
Set<Method> tracedMethods = context.getTraceInformation().getTraceAnnotations().keySet();
Set<String> tracedMethodNames = methodNames(tracedMethods);
Assert.assertTrue(allMatchTypeDescriptor(tracedMethods, Future.class));
Assert.assertThat(tracedMethodNames, containsInAnyOrder("returnFuture", "submitFuture", "access$000"));
Assert.assertThat(tracedMethodNames, not(contains("returnString", "returnInteger")));
}
use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.
the class ClassNoticingFactoryTest method noticingJunit.
@Test
public void noticingJunit() throws IOException {
ExecutorService executorService = mock(ExecutorService.class);
JarAnalystFactory factory = mock(JarAnalystFactory.class);
when(factory.createURLAnalyzer(any(URL.class))).thenReturn(mock(Runnable.class));
ClassNoticingFactory target = new ClassNoticingFactory(factory, executorService, new TestLogger());
target.newClassMatchVisitor(Test.class.getClassLoader(), Test.class, new ClassReader("org.junit.Test"), new ClassWriter(0), new InstrumentationContext(null, Test.class, Test.class.getProtectionDomain()));
ArgumentCaptor<URL> captor = ArgumentCaptor.forClass(URL.class);
verify(factory, times(1)).createURLAnalyzer(captor.capture());
// Yes, this test will fail if you upgrade junit. Should be an easy fix, but sorry!
assertTrue(captor.getValue().toString(), captor.getValue().toString().endsWith("junit-4.12.jar"));
}
use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.
the class ClassNoticingFactoryTest method noticingTestClass.
@Test
public void noticingTestClass() throws IOException {
ExecutorService executorService = mock(ExecutorService.class);
JarAnalystFactory factory = mock(JarAnalystFactory.class);
when(factory.createURLAnalyzer(any(URL.class))).thenReturn(mock(Runnable.class));
ClassNoticingFactory target = new ClassNoticingFactory(factory, executorService, new TestLogger());
target.newClassMatchVisitor(this.getClass().getClassLoader(), this.getClass(), new ClassReader(this.getClass().getName()), new ClassWriter(0), new InstrumentationContext(null, this.getClass(), this.getClass().getProtectionDomain()));
String codeSourceLocation = this.getClass().getProtectionDomain().getCodeSource().getLocation().toString();
if (codeSourceLocation.endsWith("/")) {
// we expect the test classes to be staged in a gradle directory, not in a jar.
verifyZeroInteractions(factory, executorService);
} else {
fail("Unexpected jar for test class?? " + codeSourceLocation);
}
}
use of com.newrelic.agent.instrumentation.context.InstrumentationContext in project newrelic-java-agent by newrelic.
the class OptimizedClassMatcherTest method testGenericsMatch.
@Test
public void testGenericsMatch() throws IOException {
InstrumentationContext instrumentationContext = getInstrumentationContext(matcher, ArgGenerics.class);
Match match = instrumentationContext.getMatches().values().iterator().next();
Assert.assertNotNull(match);
Assert.assertEquals(3, match.getMethods().size());
Assert.assertTrue(match.getMethods().contains(new Method("add", "(Ljava/lang/Object;)Z")));
Assert.assertEquals(match.getMethods().size(), match.getClassMatches().size());
Assert.assertTrue(match.getClassMatches().containsKey(match7));
Assert.assertEquals(2, instrumentationContext.getBridgeMethods().size());
Assert.assertEquals(new Method("add", "(Ljava/lang/String;)Z"), instrumentationContext.getBridgeMethods().get(new Method("add", "(Ljava/lang/Object;)Z")));
}
Aggregations