use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class SpringBootTest method testDuplicateTransactions.
@Test
public void testDuplicateTransactions() throws Exception {
final AtomicInteger txCounter = new AtomicInteger(0);
final AtomicInteger finishedTxCount = new AtomicInteger(0);
final AtomicReference<String> finishedTxString = new AtomicReference<>();
try (ConfigurableApplicationContext context = SpringApplication.run(ArticleResource.class)) {
ServiceFactory.getTransactionService().addTransactionListener(new ExtendedTransactionListener() {
@Override
public void dispatcherTransactionStarted(Transaction transaction) {
txCounter.incrementAndGet();
}
@Override
public void dispatcherTransactionCancelled(Transaction transaction) {
// no-op
}
@Override
public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
txCounter.decrementAndGet();
if (transactionData.getBlameMetricName().startsWith("OtherTransaction")) {
return;
}
finishedTxCount.incrementAndGet();
finishedTxString.set(transactionData.getBlameMetricName());
}
});
int port = (int) context.getBean("port");
HttpURLConnection connection = (HttpURLConnection) new URL("http", "localhost", port, "/").openConnection();
int responseCode = connection.getResponseCode();
assertEquals(200, responseCode);
// 20 * 250ms = 5 seconds
int timeout = 10;
while (timeout > 0 && txCounter.get() > 0) {
Thread.sleep(250);
timeout--;
}
assertEquals(1, finishedTxCount.get());
assertEquals("WebTransaction/SpringController/ (GET)", finishedTxString.get());
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.newrelic.agent.TransactionData 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());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class AgentTest method transactionTraceDisabled.
@Test
public void transactionTraceDisabled() throws Exception {
try {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
AgentHelper.invokeServlet(new TestServlet(), "", "App", "/foo/bar");
synchronized (this) {
wait(1000);
}
Assert.assertEquals(2, txList.size());
TransactionData transactionData = txList.get(1);
Tracer dispatcherTracer = transactionData.getRootTracer();
Assert.assertTrue(dispatcherTracer.getDuration() > dispatcherTracer.getExclusiveDuration());
} finally {
}
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class CompletableFutureTest method testLargeCompletableFuture.
@Test
public void testLargeCompletableFuture() throws Exception {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
CompletableFuture<Integer> future = doLargeCompletableFuture();
Integer result = future.get();
assertNotNull(result);
assertEquals(9, (int) result);
// Give the transaction time to finish
txs.waitFor(1, 5000);
assertEquals(1, txs.size());
TransactionData txData = txs.get(0);
Map<String, Object> userAttributes = txData.getUserAttributes();
assertNotNull(userAttributes);
assertEquals(1, userAttributes.size());
assertEquals(9, userAttributes.get("max"));
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class CompletableFutureTest method testAcceptEitherAsync.
@Test
public void testAcceptEitherAsync() {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
acceptEitherAsync();
pause(500);
AgentHelper.verifyMetrics(AgentHelper.getMetrics(), TRANSACTION_NAME);
TransactionData transactionData = txs.get(0);
Map<String, Object> userAttributes = transactionData.getUserAttributes();
assertTrue(userAttributes.containsKey("result"));
}
Aggregations