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);
}
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());
}
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);
}
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());
}
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());
}
Aggregations