Search in sources :

Example 41 with TransactionData

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

the class SpringBootTest method testDuplicateTransactions.

@Test
public void testDuplicateTransactions() throws Exception {
    final AtomicInteger txCounter = new AtomicInteger(0);
    final AtomicInteger finishedTxCount = new AtomicInteger(0);
    final AtomicReference<String> finishedTxString = new AtomicReference<>();
    try (ConfigurableApplicationContext context = SpringApplication.run(ArticleResource.class)) {
        ServiceFactory.getTransactionService().addTransactionListener(new ExtendedTransactionListener() {

            @Override
            public void dispatcherTransactionStarted(Transaction transaction) {
                txCounter.incrementAndGet();
            }

            @Override
            public void dispatcherTransactionCancelled(Transaction transaction) {
            // no-op
            }

            @Override
            public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
                txCounter.decrementAndGet();
                if (transactionData.getBlameMetricName().startsWith("OtherTransaction")) {
                    return;
                }
                finishedTxCount.incrementAndGet();
                finishedTxString.set(transactionData.getBlameMetricName());
            }
        });
        int port = (int) context.getBean("port");
        HttpURLConnection connection = (HttpURLConnection) new URL("http", "localhost", port, "/").openConnection();
        int responseCode = connection.getResponseCode();
        assertEquals(200, responseCode);
        // 20 * 250ms = 5 seconds
        int timeout = 10;
        while (timeout > 0 && txCounter.get() > 0) {
            Thread.sleep(250);
            timeout--;
        }
        assertEquals(1, finishedTxCount.get());
        assertEquals("WebTransaction/SpringController/ (GET)", finishedTxString.get());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) URL(java.net.URL) ExtendedTransactionListener(com.newrelic.agent.ExtendedTransactionListener) TransactionStats(com.newrelic.agent.stats.TransactionStats) HttpURLConnection(java.net.HttpURLConnection) Transaction(com.newrelic.agent.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 42 with TransactionData

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

the class AgentTest method ttSizeLimitExceeded.

/**
 * If the transaction trace size limit is exceeded, a tracer should record metrics but not be part of the
 * transaction trace.
 */
@Test
public void ttSizeLimitExceeded() throws ServletException, IOException {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    TestSizeLimitServlet servlet = new TestSizeLimitServlet();
    String path = "/my/word";
    AgentHelper.invokeServlet(servlet, "", APPLICATION_NAME_2, path);
    StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
    MetricName metricName = MetricName.create("Custom/test.newrelic.test.agent.AgentTest$TestSizeLimitServlet/doNothing", "WebTransaction/Servlet/TestSizeLimitServlet");
    ResponseTimeStats stats = statsEngine.getResponseTimeStats(metricName);
    Assert.assertEquals(2, stats.getCallCount());
    Assert.assertEquals(2, txs.size());
    TransactionData transactionData = txs.get(1);
    Collection<Tracer> tracers = AgentHelper.getTracers(transactionData.getRootTracer());
    Assert.assertEquals(3, tracers.size());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) MetricName(com.newrelic.agent.metric.MetricName) TransactionDataList(com.newrelic.agent.TransactionDataList) Tracer(com.newrelic.agent.tracers.Tracer) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 43 with TransactionData

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

the class AgentTest method transactionTraceDisabled.

@Test
public void transactionTraceDisabled() throws Exception {
    try {
        TransactionDataList txList = new TransactionDataList();
        ServiceFactory.getTransactionService().addTransactionListener(txList);
        AgentHelper.invokeServlet(new TestServlet(), "", "App", "/foo/bar");
        synchronized (this) {
            wait(1000);
        }
        Assert.assertEquals(2, txList.size());
        TransactionData transactionData = txList.get(1);
        Tracer dispatcherTracer = transactionData.getRootTracer();
        Assert.assertTrue(dispatcherTracer.getDuration() > dispatcherTracer.getExclusiveDuration());
    } finally {
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) Tracer(com.newrelic.agent.tracers.Tracer) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 44 with TransactionData

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

the class CompletableFutureTest method testLargeCompletableFuture.

@Test
public void testLargeCompletableFuture() throws Exception {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    CompletableFuture<Integer> future = doLargeCompletableFuture();
    Integer result = future.get();
    assertNotNull(result);
    assertEquals(9, (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(1, userAttributes.size());
    assertEquals(9, userAttributes.get("max"));
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 45 with TransactionData

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

the class CompletableFutureTest method testAcceptEitherAsync.

@Test
public void testAcceptEitherAsync() {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    acceptEitherAsync();
    pause(500);
    AgentHelper.verifyMetrics(AgentHelper.getMetrics(), TRANSACTION_NAME);
    TransactionData transactionData = txs.get(0);
    Map<String, Object> userAttributes = transactionData.getUserAttributes();
    assertTrue(userAttributes.containsKey("result"));
}
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