Search in sources :

Example 6 with BasicRequestRootTracer

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

the class TransactionTest method testTracerLimitAsyncMultiple.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimitAsyncMultiple() throws Exception {
    Map<String, Object> config = createConfigMap();
    Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
    ttmap.put("segment_limit", 3);
    createServiceManager(config);
    Object context1 = 1L;
    Object context2 = 2L;
    Object context3 = 3L;
    Object context4 = 4L;
    Object context5 = 5L;
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
    InitMultipleThread async1 = new InitMultipleThread(context1, context2, false);
    async1.start();
    async1.join();
    assertEquals(1, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    TransactionStats stats = tx.getOverLimitTxStatsforTesting();
    assertNull(stats);
    InitMultipleThread async2 = new InitMultipleThread(context2, context3, false);
    async2.start();
    async2.join();
    // two have been stored - the rest should be removed
    assertEquals(1, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    float previous = verifyMetric(tx, 1, 0);
    InitMultipleThread async3 = new InitMultipleThread(context3, context4, false);
    async3.start();
    async3.join();
    assertEquals(1, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    previous = verifyMetric(tx, 2, previous);
    InitMultipleThread async4 = new InitMultipleThread(context4, context5, false);
    async4.start();
    async4.join();
    assertEquals(1, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    previous = verifyMetric(tx, 3, previous);
    InitMultipleThread async5 = new InitMultipleThread(context5, null, false);
    async5.start();
    async5.join();
    assertEquals(1, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    previous = verifyMetric(tx, 4, previous);
    finishTransaction(tx, rootTracer);
    assertEquals(0, tx.getRunningTransactionActivityCount());
    assertEquals(2, tx.getFinishedChildren().size());
    // here all of the stats should have been merged in - not just the TXAs that were dropped
    verifyMetric(tx, 5, previous);
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 7 with BasicRequestRootTracer

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

the class TransactionTest method testTracerLimitAsyncStartLate.

// you really should not be starting late like this, but it should still work
@SuppressWarnings("unchecked")
@Test
public void testTracerLimitAsyncStartLate() throws Exception {
    Map<String, Object> config = createConfigMap();
    Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
    ttmap.put("segment_limit", 3);
    createServiceManager(config);
    Object context1 = 1L;
    Object context2 = 2L;
    Object context3 = 3L;
    Object context4 = 4L;
    Object context5 = 5L;
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
    InitThreadStartLate async1 = new InitThreadStartLate(context1, context2, false);
    async1.start();
    async1.join();
    assertEquals(1, tx.getFinishedChildren().size());
    TransactionStats stats = tx.getOverLimitTxStatsforTesting();
    assertNull(stats);
    InitThreadStartLate async2 = new InitThreadStartLate(context2, context3, false);
    async2.start();
    async2.join();
    assertEquals(1, tx.getFinishedChildren().size());
    float previous = verifyMetric(tx, 1, 0);
    InitThreadStartLate async3 = new InitThreadStartLate(context3, context4, false);
    async3.start();
    async3.join();
    assertEquals(1, tx.getFinishedChildren().size());
    previous = verifyMetric(tx, 2, previous);
    InitThreadStartLate async4 = new InitThreadStartLate(context4, context5, false);
    async4.start();
    async4.join();
    assertEquals(1, tx.getFinishedChildren().size());
    previous = verifyMetric(tx, 3, previous);
    InitThreadStartLate async5 = new InitThreadStartLate(context5, null, false);
    async5.start();
    async5.join();
    assertEquals(1, tx.getFinishedChildren().size());
    previous = verifyMetric(tx, 4, previous);
    finishTransaction(tx, rootTracer);
    assertEquals(2, tx.getFinishedChildren().size());
    // here all of the stats should have been merged in - not just the TXAs that were dropped
    verifyMetric(tx, 5, previous);
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 8 with BasicRequestRootTracer

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

the class TransactionTest method testTracerLimit2.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimit2() throws Exception {
    Map<String, Object> config = createConfigMap();
    Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
    ttmap.put("segment_limit", 3);
    createServiceManager(config);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    DefaultTracer t1 = createBasicTracer("one");
    tx.getTransactionActivity().tracerStarted(t1);
    tx.getTransactionActivity().tracerFinished(t1, 0);
    DefaultTracer t2 = createBasicTracer("two");
    tx.getTransactionActivity().tracerStarted(t2);
    tx.getTransactionActivity().tracerFinished(t2, 0);
    DefaultTracer t3 = createBasicTracer("three");
    tx.getTransactionActivity().tracerStarted(t3);
    tx.getTransactionActivity().tracerFinished(t3, 0);
    DefaultTracer t4 = createBasicTracer("four");
    tx.getTransactionActivity().tracerStarted(t4);
    tx.getTransactionActivity().tracerFinished(t4, 0);
    DefaultTracer t5 = createBasicTracer("five");
    tx.getTransactionActivity().tracerStarted(t5);
    tx.getTransactionActivity().tracerFinished(t5, 0);
    finishTransaction(tx, rootTracer);
    Set<TransactionActivity> done = tx.getFinishedChildren();
    assertEquals(1, done.size());
    TransactionActivity txa = done.iterator().next();
    List<Tracer> tracers = txa.getTracers();
    assertEquals(3, tracers.size());
    assertTrue(tracers.contains(t1));
    assertTrue(tracers.contains(t2));
    assertTrue(tracers.contains(t3));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) ImmutableMap(com.google.common.collect.ImmutableMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 9 with BasicRequestRootTracer

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

the class AttributeValidatorTest method testVerifyParametersAndReturnValues.

@Test
public void testVerifyParametersAndReturnValues() {
    Transaction t = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    t.getTransactionActivity().tracerStarted(tracer);
    CustomAttributeSender cas = new CustomAttributeSender();
    assertNull(cas.verifyParameterAndReturnValue("NaN", Double.NaN, "dude"));
    assertNull(cas.verifyParameterAndReturnValue("Infinity", Double.POSITIVE_INFINITY, "dude"));
    assertEquals(cas.verifyParameterAndReturnValue("AtomicLong", new AtomicLong(10), "dude"), 10L);
    assertEquals(cas.verifyParameterAndReturnValue("Boolean", true, "dude"), true);
    assertEquals(cas.verifyParameterAndReturnValue("Integer", 10, "dude"), Integer.valueOf(10));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 10 with BasicRequestRootTracer

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

the class NoticeErrorAttributesTest method testNoticeErrorAPIFirstCallWins.

@Test
public void testNoticeErrorAPIFirstCallWins() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("test.foo", "1");
        impl.noticeError("hello", atts);
        Map<String, String> atts2 = new HashMap<>();
        atts.put("test.bar", "2");
        impl.noticeError("hello", atts2);
        Set<String> expected = Sets.newHashSet("test.foo");
        verifyOutput(t.getErrorAttributes(), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) 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