Search in sources :

Example 56 with TransactionDataList

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

the class IgnoreErrorsTest method ignoreClassesFallback.

@Test
public void ignoreClassesFallback() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("ignore_classes_fallback_test");
    try {
        try {
            throwException(new IgnoredError("blah"));
            fail("The ignored 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.IgnoreErrorsTest/throwException", td.getPriorityTransactionName().getName());
        StatsEngine statsEngine = holder.getStatsEngine();
        assertEquals(0, statsEngine.getStats("Errors/all").getCallCount());
    } 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 57 with TransactionDataList

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

the class IgnoreErrorsTest method ignoreSuperclassMessages.

@Test
public void ignoreSuperclassMessages() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("ignore_superclass_messages_test");
    try {
        try {
            throwException(new IgnoredError("blah"));
            fail("The ignored 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.IgnoreErrorsTest/throwException", td.getPriorityTransactionName().getName());
        StatsEngine statsEngine = holder.getStatsEngine();
        // yml is configured to ignore the superclass Exception, shouldn't apply to subclass IgnoredError
        assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
    } 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 58 with TransactionDataList

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

the class ApiTest method setRequestAndResponseFirstWins.

@Test
public void setRequestAndResponseFirstWins() throws Exception {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("otherRootTracer"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    Request firstRequest = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "firstWins", "", ""));
    Response firstResponse = new FirstResponse(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(firstRequest, firstResponse);
    Request secondRequest = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "thisIsABug", "", ""));
    Response secondResponse = new SecondResponse(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(secondRequest, secondResponse);
    tracer.finish(0, null);
    Assert.assertEquals(firstRequest.getRequestURI(), tx.getDispatcher().getUri());
    Assert.assertEquals(firstResponse.getStatus(), ((WebRequestDispatcher) tx.getDispatcher()).getStatus());
    String name = tx.getPriorityTransactionName().getName();
    Assert.assertNotEquals("WebTransaction/Uri/thisIsABug", name);
    Assert.assertEquals("WebTransaction/Uri/firstWins", name);
}
Also used : 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) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) 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) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 59 with TransactionDataList

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

the class ApiTest method setRequestAndResponseNullRequestResponse.

@Test
public void setRequestAndResponseNullRequestResponse() {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("otherRootTracer"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    NewRelic.setRequestAndResponse(null, null);
    Assert.assertFalse(tx.isWebRequestSet());
    Assert.assertFalse(tx.isWebResponseSet());
    tracer.finish(0, null);
    Assert.assertTrue(tx.isWebTransaction());
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 60 with TransactionDataList

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

the class ApiTest method testSetRequestAndResponse.

@Test
public void testSetRequestAndResponse() {
    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));
    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(1, txList.size());
    Assert.assertEquals("/mytest", txList.get(0).getRequestUri(AgentConfigImpl.ATTRIBUTES));
    TransactionStats stats = apiTestHelper.tranStats;
    ResponseTimeStats dispatcherStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("HttpDispatcher");
    Assert.assertEquals(1, dispatcherStats.getCallCount());
    Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats("WebTransaction/Uri/mytest").getCallCount());
    Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex/Uri/mytest").getApdexSatisfying());
    Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex").getApdexSatisfying());
    Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.WEB_TRANSACTION).getCallCount());
    Assert.assertEquals(0, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.OTHER_TRANSACTION_ALL).getCallCount());
}
Also used : 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) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) 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) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) 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