use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderMilliMagnitude.
@Test
public void requestXStartHeaderMilliMagnitude() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMillis = Transaction.getTransaction().getWallClockStartTimeMs();
long queueStartTimeInMillis = nowInMillis - 10;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_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);
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderNoTEquals.
@Test
public void requestXStartHeaderNoTEquals() 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_START_HEADER, String.valueOf(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);
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsMultipleServersMissingServerNames.
@Test
public void requestXStartHeaderRecordMetricsMultipleServersMissingServerNames() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long requestStartTimeInMicroseconds1 = nowInMicroseconds - 30000;
long requestStartTimeInMicroseconds2 = nowInMicroseconds - 20000;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "t=" + requestStartTimeInMicroseconds1 + "t=" + requestStartTimeInMicroseconds2);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
long txStartTimeInMicroseconds = TimeUnit.MICROSECONDS.convert(dispatcher.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
float expected1 = (float) (requestStartTimeInMicroseconds2 - requestStartTimeInMicroseconds1) / TimeConversion.MICROSECONDS_PER_SECOND;
float expected2 = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds2) / TimeConversion.MICROSECONDS_PER_SECOND;
float expectedTotal = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds1) / 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(expectedTotal, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .001);
Assert.assertEquals(1, statsEngine.getSize());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method apdexFrustrating_ignoredError.
@Test
public void apdexFrustrating_ignoredError() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.setStatus(404);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
Assert.assertFalse(dispatcher.isApdexFrustrating());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordApdexMetrics.
@Test
public void requestXStartHeaderRecordApdexMetrics() 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() - 24005));
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(1, apdexStats.getApdexFrustrating());
apdexStats = statsEngine.getApdexStats(MetricName.create("Apdex/Uri/Unknown"));
Assert.assertEquals(1, apdexStats.getApdexFrustrating());
}
Aggregations