use of com.newrelic.agent.trace.TransactionTrace 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.TransactionTrace 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.TransactionTrace in project newrelic-java-agent by newrelic.
the class AsyncTest method verifyTransactionSegmentsBreadthFirst.
public void verifyTransactionSegmentsBreadthFirst(TransactionData data, String scope, String... metricNamesAndThreads) {
Assert.assertNotNull(data);
TransactionTrace trace = TransactionTrace.getTransactionTrace(data);
Assert.assertEquals(scope, trace.getRootMetricName());
verifyGivenTransactionSegmentBreadthFirst(trace.getRootSegment(), metricNamesAndThreads);
}
use of com.newrelic.agent.trace.TransactionTrace 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);
}
use of com.newrelic.agent.trace.TransactionTrace in project newrelic-java-agent by newrelic.
the class RPMServiceTest method doForceRestartException.
private void doForceRestartException() throws Exception {
MockDataSenderFactory dataSenderFactory = new MockDataSenderFactory();
DataSenderFactory.setDataSenderFactory(dataSenderFactory);
Transaction.clearTransaction();
List<String> appNames = singletonList("MyApplication");
RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "test", "()V");
Tracer rootTracer = new BasicRequestRootTracer(Transaction.getTransaction(), sig, this, null, null, new SimpleMetricNameFormat("/test"));
AgentConfig iAgentConfig = mock(AgentConfig.class);
TransactionData data = new TransactionDataTestBuilder("unittest", iAgentConfig, rootTracer).setRequestUri("/unittest").build();
List<TransactionTrace> traces = singletonList(TransactionTrace.getTransactionTrace(data));
MockDataSender dataSender = dataSenderFactory.getLastDataSender();
dataSender.setConnected(false);
dataSender.setException(new ForceRestartException(""));
CountDownLatch latch = new CountDownLatch(1);
dataSender.setLatch(latch);
try {
svc.sendTransactionTraceData(traces);
} finally {
latch.await(10, TimeUnit.SECONDS);
assertTrue(dataSender.isConnected());
}
}
Aggregations