Search in sources :

Example 16 with InstrumentedMethod

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

the class ReinstrumentAnnotationTest method testXmlPlusPointCut.

@Test
public void testXmlPlusPointCut() throws NoSuchMethodException, SecurityException {
    RpcCall rpcCall = new RpcCall();
    InstrumentedMethod annotation = test.newrelic.test.agent.RpcCall.class.getDeclaredMethod("invoke", Object[].class).getAnnotation(InstrumentedMethod.class);
    Assert.assertNotNull(annotation);
    Assert.assertEquals(1, annotation.instrumentationTypes().length);
    Assert.assertEquals(InstrumentationType.Pointcut, annotation.instrumentationTypes()[0]);
    Assert.assertEquals("com.newrelic.agent.instrumentation.pointcuts.XmlRpcPointCut", annotation.instrumentationNames()[0]);
    // reinstrument with more instrumentation
    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    sb.append("<extension xmlns=\"https://newrelic.com/docs/java/xsd/v1.0\"");
    sb.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    sb.append(" xsi:schemaLocation=\"newrelic-extension extension.xsd \" name=\"Not A Pointcut\">");
    sb.append("<instrumentation>");
    sb.append("<pointcut transactionStartPoint=\"true\" >");
    sb.append("<className>test.newrelic.test.agent.RpcCall");
    sb.append("</className>");
    sb.append("<method>");
    sb.append("<name>invoke</name>");
    sb.append("</method>");
    sb.append("</pointcut>");
    sb.append("</instrumentation>");
    sb.append("</extension>");
    // reinstrument for the first time
    ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
    annotation = test.newrelic.test.agent.RpcCall.class.getDeclaredMethod("invoke", Object[].class).getAnnotation(InstrumentedMethod.class);
    Assert.assertNotNull(annotation);
    Assert.assertEquals(2, annotation.instrumentationTypes().length);
    for (int i = 0; i < annotation.instrumentationTypes().length; i++) {
        if (annotation.instrumentationTypes()[i] == InstrumentationType.Pointcut) {
            Assert.assertEquals("com.newrelic.agent.instrumentation.pointcuts.XmlRpcPointCut", annotation.instrumentationNames()[i]);
        } else if (annotation.instrumentationTypes()[i] == InstrumentationType.RemoteCustomXml) {
            Assert.assertEquals("Not A Pointcut", annotation.instrumentationNames()[i]);
        } else {
            Assert.fail("The instrumentation type should be custom yaml or remote custom xml. Type: " + annotation.instrumentationTypes()[i]);
        }
    }
}
Also used : RpcCall(test.newrelic.test.agent.RpcCall) InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Test(org.junit.Test)

Example 17 with InstrumentedMethod

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

the class ReinstrumentAnnotationTest method testAnnotationIgnore.

@Test
public void testAnnotationIgnore() throws NoSuchMethodException, SecurityException {
    String transactionMetric = "OtherTransaction/Custom/" + InstrumentMeObj2.class.getName() + "/getSecondAge";
    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    sb.append("<extension xmlns=\"https://newrelic.com/docs/java/xsd/v1.0\"");
    sb.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    sb.append(" xsi:schemaLocation=\"newrelic-extension extension.xsd \" name=\"custom xml wahoo\">");
    sb.append("<instrumentation>");
    sb.append("<pointcut transactionStartPoint=\"true\" ignoreTransaction=\"true\">");
    sb.append("<className>com.newrelic.agent.reinstrument.InstrumentMeObj2");
    sb.append("</className>");
    sb.append("<method>");
    sb.append("<name>getSecondAge</name>");
    sb.append("<parameters>");
    sb.append("</parameters>");
    sb.append("</method>");
    sb.append("</pointcut>");
    sb.append("</instrumentation>");
    sb.append("</extension>");
    InstrumentMeObj2 obj = new InstrumentMeObj2();
    obj.getSecondAge();
    InstrumentTestUtils.verifyMetricNotPresent(transactionMetric);
    // reinstrument for the first time
    ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
    InstrumentedMethod annotation = InstrumentMeObj2.class.getDeclaredMethod("getSecondAge").getAnnotation(InstrumentedMethod.class);
    InstrumentMeObj2 obj1 = new InstrumentMeObj2();
    obj1.getSecondAge();
    InstrumentTestUtils.verifyMetricNotPresent(transactionMetric);
    // no annotation for ignored methods
    Assert.assertNull(annotation);
}
Also used : InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Test(org.junit.Test)

Example 18 with InstrumentedMethod

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

the class TraceAnnotationTest method testInstrumentedMethodMarker.

@Test
public void testInstrumentedMethodMarker() throws SecurityException, NoSuchMethodException {
    Method method = Simple.class.getDeclaredMethod("foo");
    InstrumentedMethod annotation = method.getAnnotation(InstrumentedMethod.class);
    Assert.assertNotNull(annotation);
    Assert.assertEquals(InstrumentationType.TraceAnnotation, annotation.instrumentationTypes()[0]);
    Assert.assertEquals("TraceAnnotationTest.java", annotation.instrumentationNames()[0]);
}
Also used : InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Method(java.lang.reflect.Method) InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Test(org.junit.Test)

Aggregations

InstrumentedMethod (com.newrelic.agent.instrumentation.InstrumentedMethod)18 Test (org.junit.Test)16 Method (java.lang.reflect.Method)8 InstrumentedClass (com.newrelic.agent.instrumentation.InstrumentedClass)3 ArrayList (java.util.ArrayList)2 InstrumentationType (com.newrelic.agent.instrumentation.InstrumentationType)1 PointCut (com.newrelic.agent.instrumentation.PointCut)1 WeavedMethod (com.newrelic.agent.instrumentation.WeavedMethod)1 TraceDetails (com.newrelic.agent.instrumentation.tracing.TraceDetails)1 ExactMethodInfo (com.newrelic.agent.profile.method.ExactMethodInfo)1 MethodInfo (com.newrelic.agent.profile.method.MethodInfo)1 Future (java.util.concurrent.Future)1 Level (java.util.logging.Level)1 ServletConfig (javax.servlet.ServletConfig)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpJspPage (javax.servlet.jsp.HttpJspPage)1 SolrCore (org.apache.solr.core.SolrCore)1