Search in sources :

Example 41 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXQueueStartHeader.

@Test
public void requestXQueueStartHeader() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
    long queueStartTimeInMicroseconds = nowInMicroseconds - 10000;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + queueStartTimeInMicroseconds);
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    long queueStartTimeInMilliseconds = TimeUnit.MILLISECONDS.convert(queueStartTimeInMicroseconds, TimeUnit.MICROSECONDS);
    long expectedQueueTime = dispatcher.getTransaction().getWallClockStartTimeMs() - queueStartTimeInMilliseconds;
    assertDelta(expectedQueueTime, dispatcher.getQueueTime(), 1);
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 42 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method referrerHeaderRecorded1.

@Test
public void referrerHeaderRecorded1() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader("Referer", "http://example.com:80?myparam=test&secret=donttell");
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    Transaction tx = Transaction.getTransaction();
    dispatcher.setStatus(500);
    dispatcher.transactionActivityWithResponseFinished();
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    Assert.assertTrue("Referer header should be captured", ((String) tx.getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME)).contains("example.com"));
    Assert.assertFalse("Referer header shouldn't include url parameters", ((String) tx.getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME)).contains("donttell"));
}
Also used : Transaction(com.newrelic.agent.Transaction) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 43 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXStartHeaderNanoMagnitude.

@Test
public void requestXStartHeaderNanoMagnitude() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    long nowInNanos = TimeUnit.NANOSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
    long queueStartTimeInNanos = nowInNanos - 100000000l;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "t=" + queueStartTimeInNanos);
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    long queueStartTimeInMilliseconds = TimeUnit.MILLISECONDS.convert(queueStartTimeInNanos, TimeUnit.NANOSECONDS);
    long expectedQueueTime = dispatcher.getTransaction().getWallClockStartTimeMs() - queueStartTimeInMilliseconds;
    assertDelta(expectedQueueTime, dispatcher.getQueueTime(), 1);
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 44 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXQueueStartHeaderNegativeValue.

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

Example 45 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method statusCodeFreezePolicy.

@Test
public void statusCodeFreezePolicy() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.setStatus(404);
    dispatcher.freezeStatus();
    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