Search in sources :

Example 26 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testGetBrowserTimingHeaderNoBeaconConfiguration.

@Test
public void testGetBrowserTimingHeaderNoBeaconConfiguration() {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    String browserTimingHeader = NewRelic.getBrowserTimingHeader();
    Assert.assertEquals("No beacon configuration, the timing header should be empty", "", browserTimingHeader);
    tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Also used : Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 27 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testGetBrowserTimingFooterNoHeader.

@Test
public void testGetBrowserTimingFooterNoHeader() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    Transaction tx = Transaction.getTransaction();
    TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
    PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
    tx.setPriorityTransactionName(ptn);
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    String browserTimingFooter = NewRelic.getBrowserTimingFooter();
    Assert.assertEquals("Incorrect header", "", browserTimingFooter);
    tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 28 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorWithParamsObjects.

@Test
public void testNoticeErrorWithParamsObjects() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    try {
        tx.getTransactionActivity().tracerStarted(tracer);
        Map<String, Object> atts = new HashMap<>();
        atts.put("one", 5);
        atts.put("three", 6);
        NewRelic.noticeError("boom", atts);
        Class<? extends Transaction> c = tx.getClass();
        Method m = c.getDeclaredMethod("getThrowable");
        TransactionThrowable transactionThrowable = (TransactionThrowable) m.invoke(tx);
        Assert.assertEquals("boom", transactionThrowable.throwable.getMessage());
        Assert.assertEquals(2, tx.getErrorAttributes().size());
        Assert.assertEquals(5, tx.getErrorAttributes().get("one"));
        Assert.assertEquals(6, tx.getErrorAttributes().get("three"));
    } finally {
        tx.getTransactionActivity().tracerFinished(tracer, 0);
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) HashMap(java.util.HashMap) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Method(java.lang.reflect.Method) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 29 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorInsideTransaction.

@Test
public void testNoticeErrorInsideTransaction() {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    NewRelic.noticeError(new RuntimeException("boom"));
    NewRelic.noticeError(new RuntimeException("boom2"));
    try {
        Class<? extends Transaction> c = tx.getClass();
        Method m = c.getDeclaredMethod("getThrowable");
        TransactionThrowable transactionThrowable = (TransactionThrowable) m.invoke(tx);
        Assert.assertNotNull(transactionThrowable.throwable);
        Assert.assertEquals("boom2", transactionThrowable.throwable.getMessage());
    } catch (SecurityException | InvocationTargetException | IllegalArgumentException | NoSuchMethodException | IllegalAccessException e) {
    }
    tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Also used : Transaction(com.newrelic.agent.Transaction) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Method(java.lang.reflect.Method) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) InvocationTargetException(java.lang.reflect.InvocationTargetException) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 30 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testSetIgnore.

@Test
public void testSetIgnore() {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    NewRelic.ignoreTransaction();
    Assert.assertEquals(Transaction.getTransaction().isIgnore(), false);
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    Assert.assertEquals(Transaction.getTransaction().isIgnore(), false);
    NewRelic.ignoreTransaction();
    Assert.assertEquals(Transaction.getTransaction().isIgnore(), true);
    Transaction.clearTransaction();
    tx = Transaction.getTransaction();
    tx.setIgnore(true);
    Assert.assertEquals(Transaction.getTransaction().isIgnore(), false);
    tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    Assert.assertEquals(Transaction.getTransaction().isIgnore(), false);
    tx.setIgnore(true);
    Assert.assertEquals(Transaction.getTransaction().isIgnore(), true);
}
Also used : Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Aggregations

BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)85 Test (org.junit.Test)67 Transaction (com.newrelic.agent.Transaction)64 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)33 HashMap (java.util.HashMap)22 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)18 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)16 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)16 Method (java.lang.reflect.Method)16 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)15 SegmentTest (com.newrelic.agent.transaction.SegmentTest)15 TransactionNamePriority (com.newrelic.agent.bridge.TransactionNamePriority)14 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)14 TransactionService (com.newrelic.agent.TransactionService)8 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)8 NewRelicApiImplementation (com.newrelic.api.agent.NewRelicApiImplementation)8 ArrayList (java.util.ArrayList)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Tracer (com.newrelic.agent.tracers.Tracer)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7