use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class SegmentTest method testMetricMigrationAsync.
@Test
public void testMetricMigrationAsync() throws InterruptedException {
Tracer root = makeTransaction();
Assert.assertNotNull(root);
Assert.assertNotNull(root.getTransactionActivity().getTransaction());
final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
segment.getTracedMethod().addRollupMetricName("rollupMetric");
Thread finishThread = new Thread(new Runnable() {
@Override
public void run() {
segment.getTracedMethod().addRollupMetricName("rollupMetric2");
segment.end();
}
});
finishThread.start();
finishThread.join();
root.finish(Opcodes.ARETURN, null);
assertTrue(root.getTransactionActivity().getTransaction().isFinished());
ResponseTimeStats rollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("rollupMetric");
assertEquals(1, rollupMetric.getCallCount());
ResponseTimeStats exclusiveRollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("rollupMetric2");
assertEquals(1, exclusiveRollupMetric.getCallCount());
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method checkInstanceMetric.
/**
* @param host Host to report.
* @param port Port to report.
* @param expectedHost expected host in instance metric.
* @param expectedInstanceID expected identifier in instance metric.
*/
public void checkInstanceMetric(String product, String host, Integer port, String expectedHost, String expectedInstanceID) {
DefaultTracer tracer = prepareTracer();
final TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
tracer.reportAsExternal(DatastoreParameters.product(product).collection("MyCollection").operation("operation").instance(host, port).build());
tracer.finish(0, null);
ResponseTimeStats responseTimeStats = stats.getUnscopedStats().getOrCreateResponseTimeStats(String.format("Datastore/instance/DB/%s/%s", expectedHost, expectedInstanceID));
assertEquals(responseTimeStats.getCallCount(), 1);
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class AsyncTracerTestEdgeCaseThree method testAsyncEqualsTrue.
@Test
public void testAsyncEqualsTrue() throws InterruptedException {
Thread secondThread = Txn();
System.out.println("Awaiting termination");
secondThread.join();
// Wait for Transaction to finish (due to Token expiration on separate thread)
Thread.sleep(5000);
verifyScopedMetricsPresent("OtherTransaction/Custom/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree/Txn", "Java/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree/Txn", "Java/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree$1/tracerOne");
ResponseTimeStats tracerOneStats = getStats().getScopedStats().getOrCreateResponseTimeStats("Java/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree$1/tracerOne");
Assert.assertNotNull("No stats for tracerOne", tracerOneStats);
// first invocation of tracerOne (3) is outside tracked transaction.
Assert.assertEquals("tracerOne was called a different number of times", 1, tracerOneStats.getCallCount());
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class TransactionTimeTest method testTransactionTimesOtherTransaction.
@Test
public void testTransactionTimesOtherTransaction() throws InterruptedException {
doWork();
// verify count on stats
Assert.assertNotNull(stats);
ResponseTimeStats stat = stats.getScopedStats().getOrCreateResponseTimeStats("Custom/test.newrelic.test.agent.TransactionTimeTest/hello1");
Assert.assertNotNull(stat);
Assert.assertEquals(1, stat.getCallCount());
stat = stats.getScopedStats().getOrCreateResponseTimeStats("Custom/test.newrelic.test.agent.TransactionTimeTest/hello2");
Assert.assertNotNull(stat);
Assert.assertEquals(1, stat.getCallCount());
// verify total time
double expected = data.getRootTracer().getDuration() / 1000000000.0;
Assert.assertEquals(expected, stats.getUnscopedStats().getOrCreateResponseTimeStats("OtherTransaction/Custom/test.newrelic.test.agent.TransactionTimeTest/doWork").getTotal(), .001);
Assert.assertEquals(expected, stats.getUnscopedStats().getOrCreateResponseTimeStats("OtherTransactionTotalTime/Custom/test.newrelic.test.agent.TransactionTimeTest/doWork").getTotal(), .001);
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class AgentTest method ttSizeLimitExceeded.
/**
* If the transaction trace size limit is exceeded, a tracer should record metrics but not be part of the
* transaction trace.
*/
@Test
public void ttSizeLimitExceeded() throws ServletException, IOException {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
TestSizeLimitServlet servlet = new TestSizeLimitServlet();
String path = "/my/word";
AgentHelper.invokeServlet(servlet, "", APPLICATION_NAME_2, path);
StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
MetricName metricName = MetricName.create("Custom/test.newrelic.test.agent.AgentTest$TestSizeLimitServlet/doNothing", "WebTransaction/Servlet/TestSizeLimitServlet");
ResponseTimeStats stats = statsEngine.getResponseTimeStats(metricName);
Assert.assertEquals(2, stats.getCallCount());
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
Collection<Tracer> tracers = AgentHelper.getTracers(transactionData.getRootTracer());
Assert.assertEquals(3, tracers.size());
}
Aggregations