Search in sources :

Example 36 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method testAutoAppNamingApdexT.

@Test
public void testAutoAppNamingApdexT() throws Exception {
    Map<String, Object> configMap = createConfigMap(0);
    // Configuring this in the newrelic.yml file is deprecated.
    // This is mocking a server side config property we get on connect.
    configMap.put(AgentConfigImpl.APDEX_T, 0.001f);
    createServiceManager(AgentConfigImpl.createAgentConfig(configMap), configMap);
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    // App name is something other than APP_NAME = "Unit Test"
    dispatcher.getTransaction().setApplicationName(ApplicationNamePriority.SERVLET_INIT_PARAM, "SecondAppName");
    dispatcher.transactionFinished("WebTransaction/transactionName", new TransactionStats());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 37 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXStartHeader.

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

Example 38 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method statusCodePolicyProperty.

@Test
public void statusCodePolicyProperty() throws Exception {
    ServiceManager old = ServiceFactory.getServiceManager();
    Map<String, Object> configMap = createConfigMap(0);
    configMap.put(HiddenProperties.LAST_STATUS_CODE_POLICY, false);
    createServiceManager(AgentConfigImpl.createAgentConfig(configMap), configMap);
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.setStatus(404);
    dispatcher.setStatus(200);
    Assert.assertEquals(404, dispatcher.getStatus());
    ServiceFactory.getServiceManager().stop();
    ServiceFactory.setServiceManager(old);
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 39 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method testReferrer.

@Test
public void testReferrer() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader("Referer", "HelloThere!");
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    Assert.assertNull(Transaction.getTransaction().getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME));
    dispatcher.transactionActivityWithResponseFinished();
    Assert.assertEquals("HelloThere!", Transaction.getTransaction().getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME));
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 40 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXStartHeaderFractionalSecondsMagnitude.

@Test
public void requestXStartHeaderFractionalSecondsMagnitude() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    double nowInSeconds = TimeConversion.convertMillisToSeconds(Transaction.getTransaction().getWallClockStartTimeMs());
    double queueStartTimeInSeconds = nowInSeconds - 10;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_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)

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