use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class SegmentTest method testTracedActivityHoldsTransactionOpen.
/**
* Unfinished tracedActivities should not allow the transaction to finish.
*/
@Test
public void testTracedActivityHoldsTransactionOpen() throws InterruptedException {
Tracer root = makeTransaction();
Assert.assertNotNull(root);
Assert.assertNotNull(root.getTransactionActivity().getTransaction());
Thread.sleep(1);
final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, Segment.UNNAMED_SEGMENT);
Assert.assertNotNull(segment);
Thread.sleep(1);
final Segment segment2 = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, Segment.UNNAMED_SEGMENT);
root.finish(Opcodes.ARETURN, null);
Thread.sleep(1);
assertFalse(root.getTransactionActivity().getTransaction().isFinished());
Thread.sleep(1);
// Need to check this before the segment ends
Assert.assertSame("Segment must be child of root tracer", root, segment.getTracedMethod().getParentTracedMethod());
Assert.assertSame("Segment2 must be child of root tracer", root, segment2.getTracedMethod().getParentTracedMethod());
segment.end();
assertFalse(root.getTransactionActivity().getTransaction().isFinished());
Thread.sleep(1);
segment2.end();
Thread.sleep(1);
assertTrue(root.getTransactionActivity().getTransaction().isFinished());
assertEquals(3, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
assertEquals(3, getNumTracers(root.getTransactionActivity().getTransaction()));
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class SegmentTest method testAsyncWithoutTimeout.
/**
* tracer(dispatcher) start
* --tracedActivity start
* (harvest)
* --tracedActivity finish
* tracer finish
* <p>
* Transaction should not timeout the segment
*/
@Test
public void testAsyncWithoutTimeout() throws InterruptedException {
final long configTimeoutMillis = ServiceFactory.getConfigService().getDefaultAgentConfig().getValue("traced_activity_timeout", 10 * 60) * 1000;
final Tracer root = makeTransaction();
Assert.assertNotNull(root);
Assert.assertNotNull(root.getTransactionActivity().getTransaction());
Thread.sleep(1);
final long startTs = System.currentTimeMillis();
final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Async Without Timeout");
Assert.assertNotNull(segment);
ServiceFactory.getTransactionService().processQueue();
final long durationMs = System.currentTimeMillis() - startTs;
root.finish(Opcodes.ARETURN, null);
// this will almost always be true since the configTimeout is 3 seconds.
if (durationMs < configTimeoutMillis) {
// the TA was running less than the timeout when the harvest completed. Should not have been timed out.
assertEquals(2, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
} else {
// the TA was running more than the timeout when the harvest completed. Could have been timed out correctly.
System.err.println("Skipping timeout assert. duration " + durationMs + " exceeds timeout " + configTimeoutMillis);
}
Assert.assertSame("Segment must be child of root tracer", root, segment.getTracedMethod().getParentTracedMethod());
// now let's finish
segment.end();
assertTrue(root.getTransactionActivity().getTransaction().isFinished());
assertEquals(2, getNumTracers(root.getTransactionActivity().getTransaction()));
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class TransactionAsyncEdgeCaseTest method testLinkSameThreadOneTracer.
@Test
public void testLinkSameThreadOneTracer() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
Transaction.linkTxOnThread(token);
token.expire();
rootTracer.finish(Opcodes.RETURN, 0);
waitForTransaction();
Assert.assertNotNull(data);
Assert.assertNotNull(stats);
Assert.assertEquals(1, data.getTransactionActivities().size());
Collection<Tracer> tracers = data.getTracers();
Assert.assertEquals(1, tracers.size() + 1);
Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class TransactionAsyncEdgeCaseTest method testLinkAndExpireSameThreadTwoTracers.
@Test
public void testLinkAndExpireSameThreadTwoTracers() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
token.linkAndExpire();
Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod");
tx.getTransactionActivity().tracerStarted(defaultTracer);
defaultTracer.finish(Opcodes.RETURN, 0);
rootTracer.finish(Opcodes.RETURN, 0);
waitForTransaction();
Assert.assertNotNull(data);
Assert.assertNotNull(stats);
Assert.assertEquals(1, data.getTransactionActivities().size());
Collection<Tracer> tracers = data.getTracers();
Assert.assertEquals(2, tracers.size() + 1);
Iterator<Tracer> it = tracers.iterator();
while (it.hasNext()) {
Tracer t = it.next();
Assert.assertEquals("Custom/mymethod", t.getMetricName());
}
Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod");
Assert.assertEquals(1, sb.getCallCount());
sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
Assert.assertEquals(1, sb.getCallCount());
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class TransactionAsyncEdgeCaseTest method testLinkAndExpireSameThreadOneTracer.
@Test
public void testLinkAndExpireSameThreadOneTracer() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
token.linkAndExpire();
rootTracer.finish(Opcodes.RETURN, 0);
waitForTransaction();
Assert.assertNotNull(data);
Assert.assertNotNull(stats);
Assert.assertEquals(1, data.getTransactionActivities().size());
Collection<Tracer> tracers = data.getTracers();
Assert.assertEquals(1, tracers.size() + 1);
Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
}
Aggregations