Search in sources :

Example 11 with TransactionDataList

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

the class CompletableFutureTest method testApplyAsync.

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

Example 12 with TransactionDataList

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

the class CompletableFutureTest method testCompletableFutureError.

@Test
public void testCompletableFutureError() throws Exception {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    CompletableFuture<Integer> future = doCompletableFutureError();
    Integer result = future.get();
    assertNotNull(result);
    assertEquals(3, (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(2, userAttributes.size());
    assertEquals(1, userAttributes.get("f1"));
    // f2 is not here because the "exceptionally" function will get called instead
    assertEquals(3, userAttributes.get("e"));
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 13 with TransactionDataList

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

the class CompletableFutureTest method testAcceptBothAsync.

@Test
public void testAcceptBothAsync() {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    acceptBothAsync();
    pause(500);
    AgentHelper.verifyMetrics(AgentHelper.getMetrics(), TRANSACTION_NAME);
    TransactionData transactionData = txs.get(0);
    Map<String, Object> userAttributes = transactionData.getUserAttributes();
    assertTrue(userAttributes.containsKey("three"));
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 14 with TransactionDataList

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

the class ExpectedErrorsTest method expectedClassMessagesFallbackOverride.

@Test
public void expectedClassMessagesFallbackOverride() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("expected_class_messages_fallback_test");
    try {
        try {
            // Doesn't matter what the message is, it will be expected
            throwException(new ExpectedError("blah"));
            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("Errors/all").getCallCount());
        verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 2);
        verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 1);
    } 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 15 with TransactionDataList

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

the class ExpectedErrorsTest method expectedStatusSoClose.

@Test
public void expectedStatusSoClose() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("non_expected_status_code_test");
    try {
        reportStatusCode();
        // Verify the transaction was created and finished
        TransactionDataList transactionList = holder.getTransactionList();
        ServiceFactory.getHarvestService().harvestNow();
        assertEquals(1, transactionList.size());
        TransactionData td = transactionList.get(0);
        assertEquals("WebTransaction/Custom/test.newrelic.test.agent.ExpectedErrorsTest/reportStatusCode", td.getPriorityTransactionName().getName());
        StatsEngine statsEngine = holder.getStatsEngine();
        assertEquals(0, statsEngine.getStats("ErrorsExpected/all").getCallCount());
        assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
        assertEquals(1, statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX)).getApdexFrustrating());
        verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 0, 0);
        verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 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)

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