Search in sources :

Example 1 with TransactionActivityInitiator

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

the class TransactionEventsServiceTest method testSendOther.

@Test
public void testSendOther() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    TransactionActivityInitiator rootTracer = new OtherRootTracer(Transaction.getTransaction(), null, new Object(), null);
    TransactionData transactionData = new TransactionDataTestBuilder(APP_NAME, iAgentConfig, new MockDispatcherTracer()).setDispatcher(rootTracer.createDispatcher()).setFrontendMetricName("Frontend/metricname").build();
    TransactionStats transactionStats = new TransactionStats();
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
    // populate the eventData map
    service.harvestEvents(APP_NAME);
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    assertEquals(1, currentEventData.size());
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) TransactionStats(com.newrelic.agent.stats.TransactionStats) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 2 with TransactionActivityInitiator

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

the class AsyncTest method verifyCpu.

public void verifyCpu(long minCpu) {
    Assert.assertNotNull(data);
    Assert.assertNotNull(data.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME));
    Long val = (Long) data.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    Assert.assertTrue("The cpu should be greater than 0", val > 0);
    Assert.assertTrue("The cpu should be greater than the expeted min value " + minCpu, val > minCpu);
    long cpuTime = 0L;
    Collection<Tracer> tracers = new HashSet<>();
    tracers.add(data.getRootTracer());
    tracers.addAll(data.getTracers());
    Collection<TransactionActivity> txas = new HashSet<>();
    // collect all txas for the transaction
    for (Tracer current : tracers) {
        if (current instanceof TransactionActivityInitiator) {
            txas.add(((DefaultTracer) current).getTransactionActivity());
        }
    }
    for (TransactionActivity txa : txas) {
        cpuTime += txa.getTotalCpuTime();
    }
    Assert.assertEquals("The cpu should be sum of txa cpus ", cpuTime, val.longValue());
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) TransactionActivity(com.newrelic.agent.TransactionActivity) HashSet(java.util.HashSet)

Example 3 with TransactionActivityInitiator

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

the class ExternalAsyncTest method verifyCpu.

@Override
public void verifyCpu(long minCpu) {
    super.verifyCpu(minCpu);
    Collection<Tracer> tracers = data.getTracers();
    for (Tracer current : tracers) {
        if (current instanceof TransactionActivityInitiator) {
            TransactionActivity txa = current.getTransactionActivity();
            if (txa.getRootTracer().getAgentAttribute("async_context").equals(ASYNC_TXA_NAME)) {
                Assert.assertEquals("External calls should have zero CPU time", 0L, txa.getTotalCpuTime());
            }
        }
    }
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) Tracer(com.newrelic.agent.tracers.Tracer) TransactionActivity(com.newrelic.agent.TransactionActivity)

Example 4 with TransactionActivityInitiator

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

the class CustomTracerFactoryTest method testTracerWithParent.

@Test
public void testTracerWithParent() {
    Transaction transaction = Transaction.getTransaction();
    transaction.getTransactionActivity().tracerStarted(new OtherRootTracer(transaction, signature, this, new SimpleMetricNameFormat("test")));
    TracingMethodTracerFactory mtf = new TracingMethodTracerFactory();
    CustomTracerFactory factory = new CustomTracerFactory(mtf);
    Tracer tracer = factory.getTracer(transaction, signature, this, new Object[0]);
    Assert.assertFalse(tracer instanceof TransactionActivityInitiator);
    Assert.assertNotNull(mtf.tracer);
    Exception ex = new Exception();
    tracer.finish(ex);
    Assert.assertEquals(ex, mtf.tracer.exception);
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) MethodTracer(com.newrelic.api.agent.MethodTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 5 with TransactionActivityInitiator

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

the class CustomTracerFactoryTest method testNoTracerWithoutParent.

@Test
public void testNoTracerWithoutParent() {
    Transaction transaction = Transaction.getTransaction();
    NoTracerMethodTracerFactory mtf = new NoTracerMethodTracerFactory();
    CustomTracerFactory factory = new CustomTracerFactory(mtf);
    Tracer tracer = factory.getTracer(transaction, signature, this, new Object[0]);
    Assert.assertTrue(tracer instanceof TransactionActivityInitiator);
    Assert.assertEquals(1, mtf.invocationCount);
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) MethodTracer(com.newrelic.api.agent.MethodTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Aggregations

TransactionActivityInitiator (com.newrelic.agent.tracers.TransactionActivityInitiator)10 Tracer (com.newrelic.agent.tracers.Tracer)7 Test (org.junit.Test)7 Transaction (com.newrelic.agent.Transaction)6 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)6 MethodTracer (com.newrelic.api.agent.MethodTracer)4 TransactionActivity (com.newrelic.agent.TransactionActivity)2 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)2 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)2 MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)1 TransactionData (com.newrelic.agent.TransactionData)1 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1 TransactionTimer (com.newrelic.agent.transaction.TransactionTimer)1 HashSet (java.util.HashSet)1