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());
}
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());
}
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());
}
}
}
}
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);
}
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);
}
Aggregations