use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartAndXQueueHeaderRecordMetrics.
@Test
public void requestXStartAndXQueueHeaderRecordMetrics() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long requestStartTimeInMicroseconds = nowInMicroseconds - 30000;
long queueStartTimeInMicroseconds = nowInMicroseconds - 10000;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + requestStartTimeInMicroseconds);
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + queueStartTimeInMicroseconds);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
float expectedQueueTime = (float) (nowInMicroseconds - queueStartTimeInMicroseconds) / TimeConversion.MICROSECONDS_PER_SECOND;
TransactionStats statsEngine = new TransactionStats();
dispatcher.recordHeaderMetrics(statsEngine);
String spec = MetricName.QUEUE_TIME.getName();
Assert.assertEquals(1, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
assertDelta(expectedQueueTime, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .01);
Assert.assertEquals(1, statsEngine.getSize());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method apdexNotKeyTransaction.
@Test
public void apdexNotKeyTransaction() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
Transaction tx = Transaction.getTransaction();
dispatcher.setStatus(200);
dispatcher.transactionFinished("WebTransaction/Custom/UrlGenerator/ru/betting/Motorsport", tx.getTransactionActivity().getTransactionStats());
ApdexStats stats1 = tx.getTransactionActivity().getTransactionStats().getUnscopedStats().getApdexStats("Apdex/Custom/UrlGenerator/ru/betting/Motorsport");
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out);
stats1.writeJSONString(writer);
writer.close();
Assert.assertEquals("[1,0,0,0.5,0.5,0]", out.toString());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method apdexFrustrating_error.
@Test
public void apdexFrustrating_error() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.setStatus(400);
dispatcher.freezeStatus();
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
Assert.assertTrue(dispatcher.isApdexFrustrating());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXQueueHeaderRecordApdexMetrics.
@Test
public void requestXQueueHeaderRecordApdexMetrics() throws Exception {
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
rpmService.setEverConnected(true);
Map<String, Object> data = new HashMap<>();
data.put(AgentConfigImpl.APDEX_T, 6.0d);
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
connectionConfigListener.connected(rpmService, data);
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.getTransaction().getRootTracer().finish(0, null);
StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(APP_NAME);
ApdexStats apdexStats = statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX));
Assert.assertEquals(0, apdexStats.getApdexFrustrating());
apdexStats = statsEngine.getApdexStats(MetricName.create("Apdex/Uri/Unknown"));
Assert.assertEquals(0, apdexStats.getApdexFrustrating());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXQueueStartHeaderTimeAfterTracerStartTime.
@Test
public void requestXQueueStartHeaderTimeAfterTracerStartTime() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long dispatcherStartTimeInMicroseconds = nowInMicroseconds + 10000;
long queueStartTimeInMicroseconds = dispatcherStartTimeInMicroseconds + 10;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + queueStartTimeInMicroseconds);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
Assert.assertEquals(0, dispatcher.getQueueTime());
}
Aggregations