Search in sources :

Example 21 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.

the class BasicRequestDispatcherTracerTest method requestXQueueStartHeaderFractionalSecondsMagnitude.

@Test
public void requestXQueueStartHeaderFractionalSecondsMagnitude() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    double nowInSeconds = TimeConversion.convertMillisToSeconds(Transaction.getTransaction().getWallClockStartTimeMs());
    double queueStartTimeInSeconds = nowInSeconds - 10;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, String.format("t=%1$.3f", queueStartTimeInSeconds));
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    assertDelta(10000, dispatcher.getQueueTime(), 1);
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 22 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.

the class AgentTest method ignoreApdex.

@Test
public void ignoreApdex() throws Exception {
    final List<Dispatcher> txData = new ArrayList<>();
    Servlet servlet = new DummyServlet() {

        private static final long serialVersionUID = 1L;

        @NewRelicIgnoreApdex
        @Override
        public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            Tracer lastTracer = Transaction.getTransaction().getTransactionActivity().getLastTracer();
            txData.add(Transaction.getTransaction().getDispatcher());
            Dude dude = new Dude();
            dude.go().go();
            Assert.assertEquals(2, AgentHelper.getChildren(lastTracer).size());
        }
    };
    AgentHelper.invokeServlet(servlet, "ignore", "Test", "/foo/bar");
    Assert.assertEquals(1, txData.size());
    WebRequestDispatcher dispatcher = (WebRequestDispatcher) txData.get(0);
    Assert.assertTrue(dispatcher.isIgnoreApdex());
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Tracer(com.newrelic.agent.tracers.Tracer) ArrayList(java.util.ArrayList) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) GenericServlet(javax.servlet.GenericServlet) WebServlet(javax.servlet.annotation.WebServlet) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 23 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.

the class AgentTest method servletStartTime.

@Test
public void servletStartTime() throws ServletException, Exception {
    ServletConfig config = createServletConfig();
    final Servlet servlet = new MockServlet(config);
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    long queueTime = System.currentTimeMillis() - 5;
    Mockito.when(request.getHeader("X-Queue-Start")).thenReturn("t=" + queueTime);
    long requestTime = System.currentTimeMillis() - 100;
    Mockito.when(request.getHeader("X-Request-Start")).thenReturn("t=" + requestTime);
    Transaction tx = new Callable<Transaction>() {

        @Trace(dispatcher = true)
        @Override
        public Transaction call() throws Exception {
            servlet.service(request, Mockito.mock(HttpServletResponse.class));
            return Transaction.getTransaction();
        }
    }.call();
    long externalTime = ((WebRequestDispatcher) tx.getDispatcher()).getQueueTime();
    long txStartTime = tx.getWallClockStartTimeMs();
    long expectedQueueTime = txStartTime - queueTime;
    // Since we no longer track "X-Request-Start" separately this will be 0
    long expectedRequestTime = 0;
    // allow for rounding
    Assert.assertEquals(expectedRequestTime + expectedQueueTime, externalTime, 1);
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Trace(com.newrelic.api.agent.Trace) NewRelicIgnoreTransaction(test.newrelic.test.agent.TraceAnnotationTest.NewRelicIgnoreTransaction) Transaction(com.newrelic.agent.Transaction) ServletConfig(javax.servlet.ServletConfig) MockServletConfig(org.apache.struts.mock.MockServletConfig) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) GenericServlet(javax.servlet.GenericServlet) WebServlet(javax.servlet.annotation.WebServlet) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Test(org.junit.Test)

Example 24 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.

the class ApiTest method runTestWebFrameworkAPI.

@Trace(dispatcher = true)
private void runTestWebFrameworkAPI() {
    NewRelic.setAppServerPort(666);
    NewRelic.setInstanceName("instance");
    NewRelic.setServerInfo("server", "6.6.6");
    com.newrelic.agent.bridge.Transaction txn = AgentBridge.getAgent().getTransaction();
    AgentIdentity env = ServiceFactory.getEnvironmentService().getEnvironment().getAgentIdentity();
    txn.convertToWebTransaction();
    Assert.assertTrue(txn.isWebTransaction());
    ExtendedRequest request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
    txn.setWebRequest(request);
    Assert.assertTrue(txn.isWebRequestSet());
    ApiTestHelper.DummyResponse dummyResponse = new ApiTestHelper.DummyResponse();
    NewRelic.getAgent().getTransaction().setWebResponse(dummyResponse);
    Assert.assertTrue(txn.isWebResponseSet());
    WebRequestDispatcher webRequestDispatcher = (WebRequestDispatcher) AgentBridge.getAgent().getTransaction().getWebResponse();
    try {
        int status = webRequestDispatcher.getResponse().getStatus();
        String statusMessage = webRequestDispatcher.getResponse().getStatusMessage();
        Assert.assertEquals(200, status);
        Assert.assertEquals("HTTP 200 OK", statusMessage);
    } catch (Exception ex) {
        Assert.fail();
    }
    int port = env.getServerPort();
    String instance = env.getInstanceName();
    String dispatcher = env.getDispatcher();
    String version = env.getDispatcherVersion();
    Assert.assertEquals(666, port);
    Assert.assertEquals("instance", instance);
    Assert.assertEquals("server", dispatcher);
    Assert.assertEquals("6.6.6", version);
    NewRelic.getAgent().getTransaction().markResponseSent();
    Transaction tx = Transaction.getTransaction(false);
    Assert.assertNotEquals(0, tx.getTransactionTimer().getResponseTimeInNanos());
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Transaction(com.newrelic.agent.Transaction) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Trace(com.newrelic.api.agent.Trace)

Example 25 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.

the class TransactionDispatcherTest method testSetDispatcherFirstWins.

@Test
public void testSetDispatcherFirstWins() {
    Transaction tx = Transaction.getTransaction(true);
    Dispatcher dispatcherOne = new WebRequestDispatcher(new MockHttpRequest(), new MockHttpResponse(), tx);
    tx.setDispatcher(dispatcherOne);
    assertEquals(dispatcherOne, tx.getDispatcher());
    Dispatcher dispatcherTwo = new WebRequestDispatcher(new MockHttpRequest(), new MockHttpResponse(), tx);
    tx.setDispatcher(dispatcherTwo);
    assertEquals(dispatcherOne, tx.getDispatcher());
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Test(org.junit.Test)

Aggregations

WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)55 Test (org.junit.Test)49 TransactionStats (com.newrelic.agent.stats.TransactionStats)11 Transaction (com.newrelic.agent.Transaction)10 ApdexStats (com.newrelic.agent.stats.ApdexStats)4 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)3 Response (com.newrelic.api.agent.Response)3 HashMap (java.util.HashMap)3 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)3 ConnectionConfigListener (com.newrelic.agent.ConnectionConfigListener)2 MockRPMService (com.newrelic.agent.MockRPMService)2 WebResponse (com.newrelic.agent.bridge.WebResponse)2 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 Request (com.newrelic.api.agent.Request)2 Trace (com.newrelic.api.agent.Trace)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 GenericServlet (javax.servlet.GenericServlet)2