use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class CompletableFutureTest method testAllOf.
@Test
public void testAllOf() throws Exception {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
allOf();
pause(500);
AgentHelper.verifyMetrics(AgentHelper.getMetrics(), TRANSACTION_NAME);
TransactionData transactionData = txs.get(0);
Map<String, Object> userAttributes = transactionData.getUserAttributes();
assertEquals(TRANSACTION_NAME, transactionData.getBlameMetricName());
assertTrue(userAttributes.containsKey("one"));
assertTrue(userAttributes.containsKey("two"));
assertTrue(userAttributes.containsKey("three"));
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class CompletableFutureTest method testWhenComplete.
@Test
public void testWhenComplete() throws Exception {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
CompletableFuture<Integer> future = doWhenComplete();
Integer result = future.get();
assertNotNull(result);
assertEquals(4, (int) result);
// Give the transaction time to finish
txs.waitFor(1, 1000);
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(4, userAttributes.get("f2"));
assertEquals(2, userAttributes.get("f3"));
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class CompletableFutureTest method testThenCompose.
@Test
public void testThenCompose() throws Exception {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
CompletableFuture<Integer> future = doThenCompose();
Integer result = future.get();
assertNotNull(result);
assertEquals(4, (int) result);
// Give the transaction time to finish
txs.waitFor(1, 1000);
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"));
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class CompletableFutureTest method testAnyOf.
@Test
public void testAnyOf() throws Exception {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
CompletableFuture<?> future = doAnyOf();
future.get();
// 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("req1"));
assertEquals(2, userAttributes.get("req2"));
assertEquals(3, userAttributes.get("req3"));
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class DatabaseTest method sql.
@Test
public void sql() throws Exception {
Connection connection = DatabaseHelper.getConnection();
PreparedStatement statement = connection.prepareStatement("select * from test where name = ?");
statement.setString(1, "test");
statement.executeQuery();
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"));
}
Aggregations