Search in sources :

Example 76 with TransactionData

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TransactionDataList(com.newrelic.agent.TransactionDataList) 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) TransactionData(com.newrelic.agent.TransactionData) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException) Test(org.junit.Test)

Example 77 with TransactionData

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();
    }
}
Also used : TransactionStatsListener(com.newrelic.agent.TransactionStatsListener) TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionService(com.newrelic.agent.TransactionService) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 78 with TransactionData

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

Example 79 with TransactionData

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());
}
Also used : ServletException(javax.servlet.ServletException) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 80 with TransactionData

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();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) 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