use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.
the class AsyncTest method verifyTransactionSegmentNodesWithExecContext.
public void verifyTransactionSegmentNodesWithExecContext(Map<String, String> metricToContext) {
Assert.assertNotNull(data);
TransactionTrace trace = TransactionTrace.getTransactionTrace(data);
TransactionSegment root = trace.getRootSegment();
Queue<TransactionSegment> segments = new LinkedList<>(root.getChildren());
int index = 0;
while (!segments.isEmpty()) {
TransactionSegment seg = segments.poll();
String context = metricToContext.get(seg.getMetricName());
if (context != null) {
Assert.assertNotNull(seg.getTraceParameters().get("async_context"));
Assert.assertEquals(context, seg.getTraceParameters().get("async_context"));
index++;
} else {
Assert.assertNull(seg.getTraceParameters().get("async_context"));
}
segments.addAll(seg.getChildren());
}
Assert.assertEquals(index, metricToContext.size());
}
use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.
the class AsyncTest method verifyTransactionSegmentsChildren.
public void verifyTransactionSegmentsChildren(String parent, String... children) {
Assert.assertNotNull(data);
TransactionTrace trace = TransactionTrace.getTransactionTrace(data);
TransactionSegment root = trace.getRootSegment();
Queue<TransactionSegment> segments = new LinkedList<>(root.getChildren());
int index = 0;
while (!segments.isEmpty()) {
TransactionSegment seg = segments.poll();
if (parent.equals(seg.getMetricName())) {
Collection<TransactionSegment> actualChildren = seg.getChildren();
List<String> expectedChildren = Arrays.asList(children);
for (TransactionSegment current : actualChildren) {
Assert.assertTrue(expectedChildren.contains(current.getMetricName()));
index++;
}
} else {
segments.addAll(seg.getChildren());
}
}
Assert.assertEquals(index, children.length);
}
use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.
the class TraceSegmentImpl method createTraceSegment.
static TraceSegmentImpl createTraceSegment(TransactionTrace trace, TransactionSegment tracer) {
TraceSegmentImpl output = new TraceSegmentImpl();
output.name = tracer.getMetricName();
output.startMs = tracer.getStartTime();
output.endMs = tracer.getEndTime();
output.className = tracer.getClassName();
output.methodName = tracer.getMethodName();
output.atts = Maps.newHashMap(tracer.getTraceParameters());
output.atts.putAll(trace.getUserAttributes());
Collection<TransactionSegment> originalChildren = tracer.getChildren();
output.children = new ArrayList<>(originalChildren.size());
for (TransactionSegment current : originalChildren) {
TraceSegmentImpl impl = createTraceSegment(trace, current);
output.children.add(impl);
}
output.uri = tracer.getUri();
output.callCount = tracer.getCallCount();
return output;
}
use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.
the class AsyncTest method verifyGivenTransactionSegmentBreadthFirst.
private void verifyGivenTransactionSegmentBreadthFirst(TransactionSegment segment, String... metricNamesAndThreads) {
Assert.assertEquals("ROOT", segment.getMetricName());
Assert.assertNotNull(segment.getTraceParameters().get("async_context"));
Queue<TransactionSegment> segments = new LinkedList<>(segment.getChildren());
int index = 0;
while (!segments.isEmpty()) {
TransactionSegment seg = segments.poll();
Assert.assertEquals(metricNamesAndThreads[index], seg.getMetricName());
index++;
String next = metricNamesAndThreads[index];
if (next.equals(NO_ASYNC_CONTEXT)) {
Assert.assertNull(seg.getTraceParameters().get("async_context"));
} else {
Assert.assertNotNull(seg.getTraceParameters().get("async_context"));
Assert.assertEquals(metricNamesAndThreads[index], seg.getTraceParameters().get("async_context"));
}
index++;
segments.addAll(seg.getChildren());
}
Assert.assertEquals(index, metricNamesAndThreads.length);
}
use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.
the class AsyncTest method verifyTransactionSegmentsBreadthFirst.
public void verifyTransactionSegmentsBreadthFirst(String scope, String... metricNamesAndThreads) {
Assert.assertNotNull(data);
TransactionTrace trace = TransactionTrace.getTransactionTrace(data);
Assert.assertEquals(scope, trace.getRootMetricName());
TransactionSegment root = trace.getRootSegment();
verifyGivenTransactionSegmentBreadthFirst(root, metricNamesAndThreads);
}
Aggregations