use of com.newrelic.agent.ExtendedTransactionListener 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();
}
}
Aggregations