use of com.newrelic.agent.TransactionStatsListener in project newrelic-java-agent by newrelic.
the class DistributedTracingTest method testCrossApplicationTracingDisabled.
@Test
public void testCrossApplicationTracingDisabled() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("cross_application_disabled_test");
TransactionService transactionService = ServiceFactory.getTransactionService();
final CountDownLatch latch = new CountDownLatch(1);
TransactionStatsListener listener = new TransactionStatsListener() {
@Override
public void dispatcherTransactionStatsFinished(TransactionData transactionData, TransactionStats transactionStats) {
// Use this to ensure that the transaction fully finished and that it
// didn't bail out early (transaction stats listeners are fired at the end of tx processing)
latch.countDown();
}
};
try {
transactionService.addTransactionStatsListener(listener);
noCreateOrAcceptPayload();
// Wait up to 30 seconds for the transaction to finish, if it doesn't then it means we encountered an issue and it never finished
latch.await(30, TimeUnit.SECONDS);
SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
assertNotNull(spanEventsPool);
List<SpanEvent> spanEvents = spanEventsPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
spanEventsPool.clear();
SpanEvent firstSpanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(firstSpanEvent);
String traceId = firstSpanEvent.getTraceId();
for (SpanEvent event : spanEvents) {
// Assert that all tracers have the same traceId
assertEquals(traceId, event.getTraceId());
}
TransactionDataList transactionList = holder.getTransactionList();
assertNotNull(transactionList);
assertEquals(1, transactionList.size());
} finally {
transactionService.removeTransactionStatsListener(listener);
holder.close();
}
}
Aggregations