use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class DatabaseTest method sqlException.
@Test
public void sqlException() throws Exception {
final String BAD_SQL = "this sql is no good!";
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
final Map<String, Object> params = new HashMap<>();
try {
new StubServlet("dude") {
private static final long serialVersionUID = 1L;
@Override
protected void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
Connection connection = DatabaseHelper.getConnection();
Statement stmt = connection.createStatement();
try {
stmt.executeQuery(BAD_SQL);
} finally {
params.putAll(Transaction.getTransaction().getIntrinsicAttributes());
}
}
};
} catch (Exception e) {
}
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
Assert.assertEquals(500, transactionData.getResponseStatus());
Assert.assertEquals(BAD_SQL, params.get("sql"));
}
use of com.newrelic.agent.TransactionData 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();
}
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class ErrorsTest method errorWithUnfamiliarUrl.
@Test
public void errorWithUnfamiliarUrl() throws Exception {
error(500);
Assert.assertEquals(transactionList.toString(), 1, transactionList.size());
TransactionData transactionData = transactionList.get(0);
Assert.assertEquals(MetricNames.NORMALIZED_URI_WEB_TRANSACTION + "/500/*", transactionData.getBlameMetricName());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class ErrorsTest method test404.
@Test
public void test404() throws Exception {
try {
AgentHelper.invokeServlet(null, "", "Test", "bad_request");
Assert.fail();
} catch (ServletException e) {
}
Assert.assertEquals(1, transactionList.size());
TransactionData transactionData = transactionList.get(0);
Assert.assertEquals(MetricNames.NORMALIZED_URI_WEB_TRANSACTION + "/404/*", transactionData.getBlameMetricName());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method expectedErrorWrongMessage.
@Test
public void expectedErrorWrongMessage() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("expected_error_bad_message_test");
try {
try {
throwException("pleasen be right");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.ExpectedErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("ErrorsExpected/all").getCallCount());
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 0, 1);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 1, 0);
} finally {
holder.close();
}
}
Aggregations