Search in sources :

Example 31 with TransactionDataList

use of com.newrelic.agent.TransactionDataList 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 32 with TransactionDataList

use of com.newrelic.agent.TransactionDataList 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 33 with TransactionDataList

use of com.newrelic.agent.TransactionDataList 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 34 with TransactionDataList

use of com.newrelic.agent.TransactionDataList 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 35 with TransactionDataList

use of com.newrelic.agent.TransactionDataList 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

TransactionDataList (com.newrelic.agent.TransactionDataList)70 Test (org.junit.Test)69 TransactionData (com.newrelic.agent.TransactionData)46 StatsEngine (com.newrelic.agent.stats.StatsEngine)36 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)12 Tracer (com.newrelic.agent.tracers.Tracer)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 Transaction (com.newrelic.agent.Transaction)6 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)6 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)6 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)6 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)6 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)5 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)5 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)5 Request (com.newrelic.api.agent.Request)5 Response (com.newrelic.api.agent.Response)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)5 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)5