use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method expectedStringInTransaction.
@Test
public void expectedStringInTransaction() {
TransactionData transactionData = createTransactionData(200, new ReportableError("I am expected"), true);
TransactionService txService = ServiceFactory.getTransactionService();
TransactionStats transactionStats = new TransactionStats();
txService.transactionFinished(transactionData, transactionStats);
List<TracedError> tracedErrors = ServiceFactory.getRPMService().getErrorService().getAndClearTracedErrors();
TracedError tracedError = tracedErrors.get(0);
Assert.assertEquals("I am expected", tracedError.getMessage());
Assert.assertTrue(tracedError.expected);
Assert.assertFalse(tracedError.incrementsErrorMetric());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method isIgnoredErrorNestedNoMatch.
@Test
public void isIgnoredErrorNestedNoMatch() throws Exception {
Map<String, Object> config = createConfig("java.lang.IllegalArgumentException");
EventTestHelper.createServiceManager(config);
Throwable error = new Throwable(new Exception(new ArrayIndexOutOfBoundsException()));
Transaction.getTransaction().setThrowable(error, TransactionErrorPriority.API, false);
TransactionData data = new TransactionData(Transaction.getTransaction(), 0);
boolean result = data.hasReportableErrorThatIsNotIgnored();
Assert.assertTrue(result);
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method errorCountMetrics.
@Test
public void errorCountMetrics() throws Exception {
Map<String, Object> config = createConfig("java.lang.Exception");
EventTestHelper.createServiceManager(config);
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
rpmService.setIsConnected(true);
TransactionService txService = ServiceFactory.getTransactionService();
Throwable error = new ArrayIndexOutOfBoundsException();
TransactionData data = createTransactionData(true, 0, error, false);
TransactionStats transactionStats = new TransactionStats();
txService.transactionFinished(data, transactionStats);
Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
data = createTransactionData(true, 0, null, false);
transactionStats = new TransactionStats();
txService.transactionFinished(data, transactionStats);
Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
data = createTransactionData(false, 0, error, false);
transactionStats = new TransactionStats();
txService.transactionFinished(data, transactionStats);
Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.OTHER_TRANSACTION_ERRORS_ALL).getCallCount());
data = createTransactionData(false, 0, null, false);
transactionStats = new TransactionStats();
txService.transactionFinished(data, transactionStats);
Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
StatsService spy = spy(new StatsServiceImpl());
((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
StatsEngine statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
Assert.assertEquals(2, actualErrors.size());
Assert.assertEquals(2, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
spy = spy(new StatsServiceImpl());
((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
Assert.assertEquals(0, actualErrors.size());
Assert.assertEquals(0, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
data = createTransactionData(true, 0, error, false);
txService.transactionFinished(data, new TransactionStats());
spy = spy(new StatsServiceImpl());
((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
Assert.assertEquals(1, actualErrors.size());
Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TokenTimeoutTest method testTxnAttrTokenTimeout.
@Test
public void testTxnAttrTokenTimeout() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
// Name the transaction so we can identify it in the listener below and create an event
tx.setTransactionName(TransactionNamePriority.CUSTOM_HIGH, true, "TokenTimeout", "timeout");
final List<TransactionEvent> events = new ArrayList<>();
final CountDownLatch latch = new CountDownLatch(1);
ServiceFactory.getServiceManager().getTransactionService().addTransactionListener(new TransactionListener() {
@Override
public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
if (transactionData.getPriorityTransactionName().getName().equals("WebTransaction/TokenTimeout/timeout")) {
events.add(ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, transactionData.getBlameOrRootMetricName()));
latch.countDown();
}
}
});
tx.getTransactionActivity().tracerStarted(rootTracer);
// Let this timeout the transaction
Token token = tx.getToken();
rootTracer.finish(Opcodes.RETURN, 0);
assertFalse(tx.isFinished());
// Don't start the thread. The timeout is configured to 0 seconds.
// Allow it to expire and then run the code that implements it.
busyWait(1000);
latch.await();
assertTrue(tx.isFinished());
assertFalse(events.isEmpty());
assertEquals("WebTransaction/TokenTimeout/timeout", events.get(0).getName());
assertEquals(TimeoutCause.TOKEN, events.get(0).getTimeoutCause());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class CompletableFutureTest method testCompletableFutureAccept.
@Test
public void testCompletableFutureAccept() throws Exception {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
CompletableFuture<Integer> future = doCompletableFutureAccept();
Integer result = future.join();
assertNotNull(result);
assertEquals(4, (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(3, userAttributes.size());
assertEquals(1, userAttributes.get("f1"));
assertEquals(2, userAttributes.get("f2"));
assertEquals(4, userAttributes.get("f3"));
}
Aggregations