Search in sources :

Example 51 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionAsyncEdgeCaseTest method testLinkAfterExpireTxStillInProgress2.

@Test
public void testLinkAfterExpireTxStillInProgress2() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "outer-hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod1");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    defaultTracer.finish(Opcodes.RETURN, 0);
    token.expire();
    Assert.assertNull(data);
    Assert.assertNull(stats);
    LinkFail activity1 = new LinkFail(token);
    activity1.start();
    activity1.join();
    rootTracer.finish(Opcodes.RETURN, 0);
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertFalse(activity1.linkResult);
    Assert.assertFalse(Transaction.linkTxOnThread(token));
    Assert.assertEquals(2, count);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test)

Example 52 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionAsyncEdgeCaseTest method testLinkAfterExpireTxNotInProgress.

@Test
public void testLinkAfterExpireTxNotInProgress() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "outer-hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod1");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    defaultTracer.finish(Opcodes.RETURN, 0);
    Thread.sleep(250);
    ServiceFactory.getTransactionService().processQueue();
    Thread.sleep(500);
    Assert.assertFalse(token.expire());
    rootTracer.finish(Opcodes.RETURN, 0);
    Assert.assertFalse(Transaction.linkTxOnThread(token));
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertFalse(Transaction.linkTxOnThread(token));
    Assert.assertEquals(1, data.getTransactionActivities().size());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test)

Example 53 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionAsyncEdgeCaseTest method testLinkSameThreadTwoTracers.

@Test
public void testLinkSameThreadTwoTracers() 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);
    Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    token.expire();
    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());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) StatsBase(com.newrelic.agent.stats.StatsBase) ResponseTimeStatsImpl(com.newrelic.agent.stats.ResponseTimeStatsImpl) Test(org.junit.Test)

Example 54 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionAsyncUtility method basicDataVerify.

public static Collection<Tracer> basicDataVerify(TransactionData data, TransactionStats stats, Activity activity, int count) {
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertTrue(activity.wasTxEqual);
    Assert.assertTrue(activity.isTxaNotNull);
    Assert.assertEquals(count, data.getTransactionActivities().size());
    Collection<Tracer> tracers = data.getTracers();
    Assert.assertEquals(count, tracers.size() + 1);
    for (Tracer current : tracers) {
        String segmentName = current.getTransactionSegmentName();
        Assert.assertTrue(segmentName.startsWith("RequestDispatcher/com.newrelic.agent.transaction.TransactionAsync") || segmentName.startsWith("Java/java.lang.Object/rootcom.newrelic.agent.TokenImpl@"));
    }
    TransactionAsyncUtility.verifyUnscoped(stats);
    return tracers;
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 55 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionDataTest method getRootTracer.

@Test
public void getRootTracer() {
    Tracer expected = Mockito.mock(Tracer.class);
    Mockito.when(tx.getRootTracer()).thenReturn(expected);
    TransactionData txd = getTxData(tx);
    Tracer result = txd.getRootTracer();
    Assert.assertNotNull(result);
    Assert.assertSame(expected, result);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test)

Aggregations

Tracer (com.newrelic.agent.tracers.Tracer)263 Test (org.junit.Test)195 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)104 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)99 Transaction (com.newrelic.agent.Transaction)86 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)54 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)41 ExitTracer (com.newrelic.agent.bridge.ExitTracer)39 TokenImpl (com.newrelic.agent.TokenImpl)35 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)31 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)25 TransactionData (com.newrelic.agent.TransactionData)24 HashMap (java.util.HashMap)24 SqlTracer (com.newrelic.agent.tracers.SqlTracer)20 ArrayList (java.util.ArrayList)19 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)17 TransactionStats (com.newrelic.agent.stats.TransactionStats)16 MockRPMService (com.newrelic.agent.MockRPMService)15 JSONArray (org.json.simple.JSONArray)15 JSONObject (org.json.simple.JSONObject)14