Search in sources :

Example 71 with TransactionData

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"));
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 72 with TransactionData

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"));
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 73 with TransactionData

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"));
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 74 with TransactionData

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"));
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 75 with TransactionData

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"));
}
Also used : HashMap(java.util.HashMap) DummyStatement(sql.DummyStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) DelegatingConnection(org.apache.commons.dbcp.DelegatingConnection) HttpServletResponse(javax.servlet.http.HttpServletResponse) PreparedStatement(java.sql.PreparedStatement) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Aggregations

TransactionData (com.newrelic.agent.TransactionData)145 Test (org.junit.Test)136 TransactionDataList (com.newrelic.agent.TransactionDataList)46 TransactionStats (com.newrelic.agent.stats.TransactionStats)40 HashMap (java.util.HashMap)34 StatsEngine (com.newrelic.agent.stats.StatsEngine)29 Tracer (com.newrelic.agent.tracers.Tracer)23 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)17 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)16 Transaction (com.newrelic.agent.Transaction)15 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)15 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)15 JSONArray (org.json.simple.JSONArray)15 MockRPMService (com.newrelic.agent.MockRPMService)14 Map (java.util.Map)14 TransactionService (com.newrelic.agent.TransactionService)12 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)12 JSONObject (org.json.simple.JSONObject)12 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)10 SpanEvent (com.newrelic.agent.model.SpanEvent)10