Search in sources :

Example 36 with TransactionDataList

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

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

use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.

the class ExpectedErrorsTest method expectedErrorNoTransaction.

@Test
public void expectedErrorNoTransaction() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("expected_error_test");
    try {
        try {
            throwExceptionNoTransaction("something");
            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(0, transactionList.size());
        StatsEngine statsEngine = holder.getStatsEngine();
        assertEquals(0, statsEngine.getStats("Errors/all").getCallCount());
        assertEquals(1, statsEngine.getStats("ErrorsExpected/all").getCallCount());
        verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 0);
        verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 0);
    } finally {
        holder.close();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 39 with TransactionDataList

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

Example 40 with TransactionDataList

use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.

the class ExpectedErrorsTest method nonExpectedErrorNoTransaction.

@Test
public void nonExpectedErrorNoTransaction() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("non_expected_error_test");
    try {
        try {
            throwExceptionNoTransaction("something");
            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(0, transactionList.size());
        StatsEngine statsEngine = holder.getStatsEngine();
        assertEquals(0, statsEngine.getStats("ErrorsExpected/all").getCallCount());
        assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
        verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 0);
        verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 0);
    } finally {
        holder.close();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) StatsEngine(com.newrelic.agent.stats.StatsEngine) 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