Search in sources :

Example 1 with TransactionDataList

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

the class ApiTest method testSetTxNameThenSetRequestAndResponse.

@Test
public void testSetTxNameThenSetRequestAndResponse() {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    NewRelic.setTransactionName("Test", "Foo");
    Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
    Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(request, response);
    tracer.finish(0, null);
    Assert.assertEquals("WebTransaction/Test/Foo", tx.getPriorityTransactionName().getName());
}
Also used : MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TransactionDataList(com.newrelic.agent.TransactionDataList) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 2 with TransactionDataList

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

the class SpanParentTest method testSpanAndTransactionParenting.

@Test
public void testSpanAndTransactionParenting() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
    executeSpanAndTransactionParentingTest();
    try {
        TransactionDataList transactionList = holder.getTransactionList();
        assertEquals(2, transactionList.size());
        TransactionData tx1 = transactionList.get(0);
        TransactionData tx2 = transactionList.get(1);
        Collection<Tracer> tracers1 = tx1.getTracers();
        // Only a "rootTracer" on this transaction (root tracer is not in this list)
        assertEquals(0, tracers1.size());
        Collection<Tracer> tracers2 = tx2.getTracers();
        // 1 "rootTracer" (not in this list) + 2 non-external/datastore tracers + 2 external datastore tracers
        assertEquals(4, tracers2.size());
        SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
        String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
        SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
        assertNotNull(spanEventsPool);
        List<SpanEvent> spanEvents = spanEventsPool.asList();
        spanEventsPool.clear();
        assertNotNull(spanEvents);
        assertEquals(6, spanEvents.size());
        SpanEvent rootSpanEvent = null;
        Set<String> spanEventGuids = new HashSet<>();
        for (SpanEvent spanEvent : spanEvents) {
            if (spanEvent.getParentId() == null) {
                rootSpanEvent = spanEvent;
            }
            spanEventGuids.add(spanEvent.getGuid());
        }
        assertNotNull(rootSpanEvent);
        assertEquals(6, spanEventGuids.size());
        // Ensure that spans are only parented to other spans
        for (SpanEvent spanEvent : spanEvents) {
            if (spanEvent.getParentId() == null) {
                continue;
            }
            assertTrue(spanEventGuids.contains(spanEvent.getParentId()));
        }
        TransactionEventsService transactionEventsService = ServiceFactory.getServiceManager().getTransactionEventsService();
        DistributedSamplingPriorityQueue<TransactionEvent> txEventPool = transactionEventsService.getOrCreateDistributedSamplingReservoir(appName);
        assertNotNull(txEventPool);
        List<TransactionEvent> txEvents = txEventPool.asList();
        txEventPool.clear();
        assertNotNull(txEvents);
        assertEquals(2, txEvents.size());
        TransactionEvent parent = null;
        TransactionEvent child = null;
        for (TransactionEvent txEvent : txEvents) {
            if (txEvent.getParentId() == null) {
                parent = txEvent;
            } else {
                child = txEvent;
            }
        }
        assertNotNull(parent);
        assertNotNull(child);
        assertNull(parent.getParentId());
        assertEquals(parent.getGuid(), child.getParentId());
    } finally {
        holder.close();
    }
}
Also used : EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Tracer(com.newrelic.agent.tracers.Tracer) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionEvent(com.newrelic.agent.service.analytics.TransactionEvent) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 3 with TransactionDataList

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

the class SpanParentTest method testSpanParenting.

@Test
public void testSpanParenting() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
    Header actualHeader = txnStarter(false);
    try {
        TransactionDataList transactionList = holder.getTransactionList();
        ServiceFactory.getHarvestService().harvestNow();
        assertEquals(1, transactionList.size());
        Collection<Tracer> tracers = transactionList.get(0).getTracers();
        String expectedGuid = ((TracerList) tracers).get(0).getGuid();
        String actualGuid = findGuid(actualHeader.getValue());
        Assert.assertEquals(expectedGuid, actualGuid);
    } finally {
        holder.close();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) Header(org.apache.http.Header) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test)

Example 4 with TransactionDataList

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

the class SpringBootAsyncTest method testInconsistentState.

@Test
public void testInconsistentState() {
    ConfigurableApplicationContext context = SpringApplication.run(AsyncResource.class);
    // Ignore the servlet init() transactions
    transactions.clear();
    try {
        Collection<Future<?>> futures = new ArrayList<>();
        for (int i = 0; i < 250; i++) {
            futures.add(executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8090/" + ENDPOINT.getPort()).openConnection();
                        int responseCode = connection.getResponseCode();
                        assertEquals(200, responseCode);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }));
        }
        for (Future<?> future : futures) {
            future.get(30, TimeUnit.SECONDS);
        }
        TransactionDataList list = transactions.waitFor(250, TimeUnit.SECONDS.toMillis(30));
        Set<String> uniqueTxNames = new HashSet<>(list.getTransactionNames());
        assertEquals(1, uniqueTxNames.size());
        assertTrue(uniqueTxNames.contains("WebTransaction/SpringController/{port} (GET)"));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        executor.shutdownNow();
        executorService.shutdownNow();
        context.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ArrayList(java.util.ArrayList) URL(java.net.URL) TransactionDataList(com.newrelic.agent.TransactionDataList) HttpURLConnection(java.net.HttpURLConnection) Future(java.util.concurrent.Future) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with TransactionDataList

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

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