Search in sources :

Example 66 with TransactionData

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

the class ErrorServiceTest method expectedStringInTransaction.

@Test
public void expectedStringInTransaction() {
    TransactionData transactionData = createTransactionData(200, new ReportableError("I am expected"), true);
    TransactionService txService = ServiceFactory.getTransactionService();
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(transactionData, transactionStats);
    List<TracedError> tracedErrors = ServiceFactory.getRPMService().getErrorService().getAndClearTracedErrors();
    TracedError tracedError = tracedErrors.get(0);
    Assert.assertEquals("I am expected", tracedError.getMessage());
    Assert.assertTrue(tracedError.expected);
    Assert.assertFalse(tracedError.incrementsErrorMetric());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionService(com.newrelic.agent.TransactionService) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 67 with TransactionData

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

the class ErrorServiceTest method isIgnoredErrorNestedNoMatch.

@Test
public void isIgnoredErrorNestedNoMatch() throws Exception {
    Map<String, Object> config = createConfig("java.lang.IllegalArgumentException");
    EventTestHelper.createServiceManager(config);
    Throwable error = new Throwable(new Exception(new ArrayIndexOutOfBoundsException()));
    Transaction.getTransaction().setThrowable(error, TransactionErrorPriority.API, false);
    TransactionData data = new TransactionData(Transaction.getTransaction(), 0);
    boolean result = data.hasReportableErrorThatIsNotIgnored();
    Assert.assertTrue(result);
}
Also used : TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 68 with TransactionData

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

the class ErrorServiceTest method errorCountMetrics.

@Test
public void errorCountMetrics() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    EventTestHelper.createServiceManager(config);
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    TransactionService txService = ServiceFactory.getTransactionService();
    Throwable error = new ArrayIndexOutOfBoundsException();
    TransactionData data = createTransactionData(true, 0, error, false);
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(true, 0, null, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(false, 0, error, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.OTHER_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(false, 0, null, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    StatsService spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    StatsEngine statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(2, actualErrors.size());
    Assert.assertEquals(2, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
    spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(0, actualErrors.size());
    Assert.assertEquals(0, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
    data = createTransactionData(true, 0, error, false);
    txService.transactionFinished(data, new TransactionStats());
    spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(1, actualErrors.size());
    Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
}
Also used : TransactionService(com.newrelic.agent.TransactionService) StatsService(com.newrelic.agent.stats.StatsService) StatsEngine(com.newrelic.agent.stats.StatsEngine) TransactionStats(com.newrelic.agent.stats.TransactionStats) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionData(com.newrelic.agent.TransactionData) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 69 with TransactionData

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

the class TokenTimeoutTest method testTxnAttrTokenTimeout.

@Test
public void testTxnAttrTokenTimeout() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    // Name the transaction so we can identify it in the listener below and create an event
    tx.setTransactionName(TransactionNamePriority.CUSTOM_HIGH, true, "TokenTimeout", "timeout");
    final List<TransactionEvent> events = new ArrayList<>();
    final CountDownLatch latch = new CountDownLatch(1);
    ServiceFactory.getServiceManager().getTransactionService().addTransactionListener(new TransactionListener() {

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            if (transactionData.getPriorityTransactionName().getName().equals("WebTransaction/TokenTimeout/timeout")) {
                events.add(ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, transactionData.getBlameOrRootMetricName()));
                latch.countDown();
            }
        }
    });
    tx.getTransactionActivity().tracerStarted(rootTracer);
    // Let this timeout the transaction
    Token token = tx.getToken();
    rootTracer.finish(Opcodes.RETURN, 0);
    assertFalse(tx.isFinished());
    // Don't start the thread. The timeout is configured to 0 seconds.
    // Allow it to expire and then run the code that implements it.
    busyWait(1000);
    latch.await();
    assertTrue(tx.isFinished());
    assertFalse(events.isEmpty());
    assertEquals("WebTransaction/TokenTimeout/timeout", events.get(0).getName());
    assertEquals(TimeoutCause.TOKEN, events.get(0).getTimeoutCause());
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) ExtendedTransactionListener(com.newrelic.agent.ExtendedTransactionListener) TransactionEvent(com.newrelic.agent.service.analytics.TransactionEvent) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Token(com.newrelic.agent.bridge.Token) TransactionData(com.newrelic.agent.TransactionData) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 70 with TransactionData

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

the class CompletableFutureTest method testCompletableFutureAccept.

@Test
public void testCompletableFutureAccept() throws Exception {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    CompletableFuture<Integer> future = doCompletableFutureAccept();
    Integer result = future.join();
    assertNotNull(result);
    assertEquals(4, (int) result);
    // 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("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)

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