Search in sources :

Example 6 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method testHttpMethod.

@Test
public void testHttpMethod() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setMethod("POST");
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.getTransaction().getTransactionActivity().markAsResponseSender();
    dispatcher.getTransaction().getRootTracer().finish(0, null);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    Map<String, Object> agentAttributes = dispatcher.getTransaction().getAgentAttributes();
    assertEquals("POST", agentAttributes.get(AttributeNames.REQUEST_METHOD_PARAMETER_NAME));
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 7 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXQueueStartHeaderMilliMagnitude.

@Test
public void requestXQueueStartHeaderMilliMagnitude() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    long nowInMillis = Transaction.getTransaction().getWallClockStartTimeMs();
    long queueStartTimeInMillis = nowInMillis - 10;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + queueStartTimeInMillis);
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    long expectedQueueTime = dispatcher.getTransaction().getWallClockStartTimeMs() - queueStartTimeInMillis;
    assertDelta(expectedQueueTime, dispatcher.getQueueTime(), 1);
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 8 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method statusCodeNoMetric.

@Test
public void statusCodeNoMetric() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    Transaction tx = Transaction.getTransaction();
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    Assert.assertEquals(0, dispatcher.getStatus());
    Assert.assertEquals(0, tx.getStatus());
    String spec = "Network/Inbound/StatusCode/0";
    Assert.assertEquals(0, tx.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
}
Also used : Transaction(com.newrelic.agent.Transaction) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 9 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsBadValue.

@Test
public void requestXStartHeaderRecordMetricsBadValue() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=cafebabe");
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    TransactionStats statsEngine = new TransactionStats();
    dispatcher.recordHeaderMetrics(statsEngine);
    Assert.assertEquals(0, statsEngine.getSize());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 10 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method statusCodeTxaDone.

@Test
public void statusCodeTxaDone() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.setStatus(404);
    dispatcher.transactionActivityWithResponseFinished();
    dispatcher.setStatus(200);
    Assert.assertEquals(404, dispatcher.getStatus());
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) 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