use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.
the class TransactionTraceTest method testOneTracerInTransactionWithDepthChildren.
@Test
public void testOneTracerInTransactionWithDepthChildren() {
// transaction
long start = System.currentTimeMillis();
Transaction.getTransaction();
Tracer rootTracer = IntrospectorImplTest.createOtherTracer("rootOnly");
Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
Tracer child1 = IntrospectorImplTest.createDefaultTracer("default1");
Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
Tracer child2 = IntrospectorImplTest.createDefaultTracer("default2");
Transaction.getTransaction().getTransactionActivity().tracerStarted(child2);
Tracer child3 = IntrospectorImplTest.createDefaultTracer("default3");
Transaction.getTransaction().getTransactionActivity().tracerStarted(child3);
child3.setAgentAttribute("myatt", "hello");
child3.setAgentAttribute("myNumber", 99);
child3.finish(Opcodes.RETURN, 0);
child2.finish(Opcodes.RETURN, 0);
child1.finish(Opcodes.RETURN, 0);
rootTracer.finish(Opcodes.RETURN, 0);
long end = System.currentTimeMillis();
// data check
Assert.assertEquals(1, impl.getFinishedTransactionCount());
Map<String, TracedMetricData> metrics = impl.getUnscopedMetrics();
TracedMetricData txMetric = metrics.get("OtherTransaction/rootOnly");
Collection<TransactionTrace> traces = impl.getTransactionTracesForTransaction("OtherTransaction/rootOnly");
Assert.assertEquals(1, traces.size());
TransactionTrace trace = traces.iterator().next();
Assert.assertEquals(txMetric.getTotalTimeInSec(), trace.getResponseTimeInSec(), .01);
Assert.assertEquals(trace.getWallClockDurationInSec(), trace.getResponseTimeInSec(), .01);
Assert.assertTrue(trace.getStartTime() >= start);
Assert.assertTrue(trace.getStartTime() <= end);
TraceSegment segment = trace.getInitialTraceSegment();
Assert.assertEquals(1, segment.getChildren().size());
TraceSegment seg = segment.getChildren().get(0);
long relativeStart = segment.getRelativeStartTime();
long relativeEnd = segment.getRelativeEndTime();
int count = 0;
while (seg != null) {
count++;
Assert.assertTrue(seg.getRelativeStartTime() >= relativeStart);
Assert.assertTrue(seg.getRelativeEndTime() <= relativeEnd);
Assert.assertTrue(seg.getRelativeStartTime() <= seg.getRelativeEndTime());
relativeStart = seg.getRelativeStartTime();
relativeEnd = seg.getRelativeEndTime();
Map<String, Object> info = seg.getTracerAttributes();
Assert.assertNull(info.get("async_context"));
Assert.assertNotNull(info.get("exclusive_duration_millis"));
Assert.assertTrue(seg.getMethodName().startsWith("default"));
Assert.assertTrue(seg.getName().startsWith("Custom/default"));
Assert.assertEquals("MyClass", seg.getClassName());
if (seg.getName().equals("Custom/default3")) {
Assert.assertEquals("hello", info.get("myatt"));
Assert.assertEquals(99, info.get("myNumber"));
Assert.assertEquals(0, seg.getChildren().size());
seg = null;
} else {
Assert.assertEquals(1, seg.getChildren().size());
seg = seg.getChildren().get(0);
}
}
Assert.assertEquals(3, count);
}
use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.
the class AkkaTest method testSend.
@Test
public void testSend() throws InterruptedException {
ActorSystem system = ActorSystem.create("AkkaTestSystem");
TestApp.sendMessageInTransaction(system);
Introspector introspector = InstrumentationTestRunner.getIntrospector();
int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
assertEquals(1, finishedTransactionCount);
String transactionName = "OtherTransaction/AkkaForward/Forward";
Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName);
assertTrue(metricsForTransaction.containsKey("Akka/forward/forwardActor"));
assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ForwardActor.class.getName()));
}
use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.
the class AkkaTest method testBroadcast.
@Test
public void testBroadcast() throws InterruptedException {
ActorSystem system = ActorSystem.create("AkkaTestSystem");
TestApp.broadcastInTransaction(system);
Introspector introspector = InstrumentationTestRunner.getIntrospector();
int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
assertEquals(1, finishedTransactionCount);
String transactionName = "OtherTransaction/Akka/Broadcast";
Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName);
assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ActorA.class.getName()));
assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ActorB.class.getName()));
assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ActorC.class.getName()));
Map<String, TracedMetricData> unscopedMetrics = introspector.getUnscopedMetrics();
assertTrue(unscopedMetrics.containsKey("ActorA"));
assertTrue(unscopedMetrics.containsKey("ActorB"));
assertTrue(unscopedMetrics.containsKey("ActorC"));
}
use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.
the class AkkaTest method testBroadcastStress.
@Test
public void testBroadcastStress() throws InterruptedException {
/**
* @formatter:off
*
* This test tries to cover the following case:
*
* Suppose System broadcasts a message to A and B. B forwards the same message to C.
*
* System
* / \
* A B @Trace(dispatcher = true)
* |
* C
*
* A possible execution of this can be as follows:
*
* A is busy, and does not read the message.
* B starts the transaction, and forwards message to C
* A wakes up, and reads message.
* C reads message.
*
* We want to ensure that A never links to B.
*
* To increase the likelihood of running into the execution above, we have actor A forward the same message to itself several times.
* We do the same thing for actor C.
*/
ActorSystem system = ActorSystem.create("AkkaTestSystem");
TestApp.broadcastStress(system);
Introspector introspector = InstrumentationTestRunner.getIntrospector();
int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
assertEquals(1, finishedTransactionCount);
assertTrue(introspector.getTransactionNames().contains("OtherTransaction/Akka/ParentActor"));
Map<String, TracedMetricData> unscopedMetrics = introspector.getUnscopedMetrics();
assertFalse(unscopedMetrics.containsKey(ActorNoTxnBranch.ROLLUP_NAME));
}
use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.
the class AkkaTest method testRoutedActorToRouteeSend.
@Test
public void testRoutedActorToRouteeSend() throws InterruptedException {
ActorSystem system = ActorSystem.create("AkkaTestSystem");
TestApp.sendRoutedMessageToRouteeInTransaction(system);
Introspector introspector = InstrumentationTestRunner.getIntrospector();
int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
assertEquals(1, finishedTransactionCount);
String transactionName = "OtherTransaction/Akka/Routee";
Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName);
assertTrue(metricsForTransaction.containsKey("Akka/receive/" + RoutingActor.class.getName()));
assertTrue(metricsForTransaction.containsKey("Akka/receive/" + Routee.class.getName()));
}
Aggregations