Search in sources :

Example 1 with BasicRequestRootTracer

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

the class TransactionTest method testTracerLimit1.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimit1() 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);
    DefaultTracer t2 = createBasicTracer("two");
    tx.getTransactionActivity().tracerStarted(t2);
    DefaultTracer t3 = createBasicTracer("three");
    tx.getTransactionActivity().tracerStarted(t3);
    DefaultTracer t4 = createBasicTracer("four");
    tx.getTransactionActivity().tracerStarted(t4);
    DefaultTracer t5 = createBasicTracer("five");
    tx.getTransactionActivity().tracerStarted(t5);
    tx.getTransactionActivity().tracerFinished(t5, 0);
    tx.getTransactionActivity().tracerFinished(t4, 0);
    tx.getTransactionActivity().tracerFinished(t3, 0);
    tx.getTransactionActivity().tracerFinished(t2, 0);
    tx.getTransactionActivity().tracerFinished(t1, 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));
    // Verify that we send up the segment_clamp supportability metric
    TransactionStats stats = txa.getTransactionStats();
    assertNotNull(stats);
    StatsImpl segmentClamp = (StatsImpl) stats.getUnscopedStats().getStatsMap().get(MetricNames.SUPPORTABILITY_TRANSACTION_SEGMENT_CLAMP);
    assertNotNull(segmentClamp);
    // The limit is 3 so the clamp will take effect at 4
    assertEquals(4, (int) segmentClamp.getTotal());
    // Should get incremented once for the tx
    assertEquals(1, segmentClamp.getCallCount());
}
Also used : 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) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ImmutableMap(com.google.common.collect.ImmutableMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 2 with BasicRequestRootTracer

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

the class TransactionTest method testTracerLimitAsyncWhenStartedLate.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimitAsyncWhenStartedLate() 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);
    // register context1, but don't start it until we're over the segment limit
    assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
    // register context1 again, make sure we return false
    assertFalse(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
    // register context2
    assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context2));
    // start context2 on new thread and register context3
    InitThread doContext2 = new InitThread(context2, context3, false);
    doContext2.start();
    doContext2.join();
    // activity for context2 should finish normally
    assertEquals(1, tx.getFinishedChildren().size());
    // start context3 on new thread and register context4
    InitThread doContext3 = new InitThread(context3, context4, false);
    doContext3.start();
    doContext3.join();
    // activity for context3 should finish normally
    assertEquals(2, tx.getFinishedChildren().size());
    // start context4 on new thread and register context5
    InitThread doContext4 = new InitThread(context4, context5, false);
    doContext4.start();
    doContext4.join();
    // activity for context4 should finish normally
    assertEquals(3, tx.getFinishedChildren().size());
    // stats object to hold additional activity results should be created
    TransactionStats stats = tx.getOverLimitTxStatsforTesting();
    assertNull(stats);
    // start context5 on a new thread
    InitThread doContext5 = new InitThread(context5, null, false);
    doContext5.start();
    doContext5.join();
    // context5 should not be retained in finished children set because we're over the segment limit
    assertEquals(3, tx.getFinishedChildren().size());
    // context5's stats should get dumped into the tx stats object
    stats = tx.getOverLimitTxStatsforTesting();
    assertNotNull(stats);
    ResponseTimeStatsImpl theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
    assertNotNull(theStat);
    float initValue = theStat.getTotal();
    assertEquals(1, theStat.getCallCount());
    // start context1 on a new thread
    InitThread doContext1 = new InitThread(context1, null, false);
    doContext1.start();
    doContext1.join();
    // context1 should not be retained in finished children set because we're over the segment limit
    assertEquals(3, tx.getFinishedChildren().size());
    // context1's stats should get dumped into the tx stats object
    stats = tx.getOverLimitTxStatsforTesting();
    assertNotNull(stats);
    theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
    assertNotNull(theStat);
    assertTrue(theStat.getTotal() > initValue);
    assertEquals(2, theStat.getCallCount());
    // finish the transaction
    finishTransaction(tx, rootTracer);
    // root activity gets placed in finished children
    assertEquals(4, tx.getFinishedChildren().size());
    // all of the stats should have been merged in - not just the TXAs that were dropped
    stats = tx.getOverLimitTxStatsforTesting();
    assertNotNull(stats);
    theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
    assertNotNull(theStat);
    assertTrue(theStat.getTotal() > initValue);
    assertEquals(5, theStat.getCallCount());
}
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 3 with BasicRequestRootTracer

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

the class TransactionTest method testTracerLimitSync.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimitSync() throws Exception {
    Map<String, Object> config = createConfigMap();
    Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
    ttmap.put(TransactionTracerConfigImpl.SEGMENT_LIMIT, 5);
    createServiceManager(config);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    for (int i = 0; i < 10; i++) {
        Segment segment = rootTracer.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Sync Segment");
        if (segment != null) {
            segment.end();
        }
        // Wait for segment to end
        Thread.sleep(5);
    }
    finishTransaction(tx, rootTracer);
    assertEquals(6, tx.getTransactionCounts().getSegmentCount());
    assertEquals(0, tx.getRunningTransactionActivityCount());
}
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 4 with BasicRequestRootTracer

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

the class TransactionTest method createDispatcherTracer.

// Create a Tracer for tests that require one.
private Tracer createDispatcherTracer(boolean createRequest) {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    if (createRequest) {
        MockHttpRequest httpRequest = new MockHttpRequest();
        MockHttpResponse httpResponse = new MockHttpResponse();
        return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
    } else {
        return new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("thisismyname"));
    }
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 5 with BasicRequestRootTracer

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

the class TransactionTest method recordCpuAndGCTimeWithLegacyAsync.

@Test
public void recordCpuAndGCTimeWithLegacyAsync() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    createServiceManager(configMap);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    Thread.sleep(40);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    tx.addTotalCpuTimeForLegacy(5000000);
    rootTracer.finish(Opcodes.ARETURN, null);
    tx.recordFinalGCTime(tx.getTransactionActivity().getTransactionStats());
    Long cpuTime = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    assertNotNull(cpuTime);
    assertTrue(cpuTime > 5000000);
    tx.recordFinalGCTime(tx.getTransactionActivity().getTransactionStats());
    Long cpuTime2 = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    assertEquals(cpuTime, cpuTime2);
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

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