Search in sources :

Example 1 with TransactionTrace

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());
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionTrace(com.newrelic.agent.trace.TransactionTrace) LinkedList(java.util.LinkedList)

Example 2 with TransactionTrace

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);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionTrace(com.newrelic.agent.trace.TransactionTrace) LinkedList(java.util.LinkedList)

Example 3 with TransactionTrace

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);
}
Also used : TransactionTrace(com.newrelic.agent.trace.TransactionTrace)

Example 4 with TransactionTrace

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);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionTrace(com.newrelic.agent.trace.TransactionTrace)

Example 5 with TransactionTrace

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());
    }
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) CountDownLatch(java.util.concurrent.CountDownLatch) AgentConfig(com.newrelic.agent.config.AgentConfig) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionTrace(com.newrelic.agent.trace.TransactionTrace) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Aggregations

TransactionTrace (com.newrelic.agent.trace.TransactionTrace)8 TransactionSegment (com.newrelic.agent.trace.TransactionSegment)3 Tracer (com.newrelic.agent.tracers.Tracer)3 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)2 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)2 LinkedList (java.util.LinkedList)2 MockRPMService (com.newrelic.agent.MockRPMService)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1