Search in sources :

Example 11 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TransactionAsyncTimeoutTest method testRegisterTwiceRunOnceLinkAndExpire.

@Test
public void testRegisterTwiceRunOnceLinkAndExpire() throws Exception {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    final Token t1 = tx.getToken();
    final Token t2 = tx.getToken();
    tx.getTransactionActivity().tracerFinished(rootTracer, 0);
    Assert.assertNull(data);
    Assert.assertNull(stats);
    Thread a1 = new Thread() {

        @Override
        public void run() {
            Transaction.clearTransaction();
            Transaction oldTx = Transaction.getTransaction();
            Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one" + t1.toString());
            oldTx.getTransactionActivity().tracerStarted(rootTracer);
            boolean test = t1.linkAndExpire();
            Transaction newTx = Transaction.getTransaction();
            Assert.assertTrue(oldTx != newTx);
            newTx.getTransactionActivity().tracerFinished(rootTracer, 0);
        }
    };
    a1.start();
    a1.join();
    Thread.sleep(2000);
    ServiceFactory.getAsyncTxService().beforeHarvest("Unit Test", null);
    ServiceFactory.getTransactionService().processQueue();
    // wait for async token timeouts to complete
    Thread.sleep(500);
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(2, tx.getFinishedChildren().size());
    assertTokenMetricCounts(2, 1, 1, 0, 1);
}
Also used : Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) Token(com.newrelic.api.agent.Token) Test(org.junit.Test)

Example 12 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TraceAnnotationTest method callAsyncAnnotatedThreadInsideOfTxnMultiThreaded.

@Trace(dispatcher = true)
private void callAsyncAnnotatedThreadInsideOfTxnMultiThreaded() {
    Token token = NewRelic.getAgent().getTransaction().getToken();
    NewRelic.getAgent().getTransaction().setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, true, "MyCategory", "TracedAsyncTxn");
    // Inside of a txn, getToken should return TokenImpl
    Assert.assertEquals("NewRelic.getAgent().getTransaction().getToken() should return TokenImpl", com.newrelic.agent.TokenImpl.class, token.getClass());
    // Inside of a txn, getTransaction should return TransactionApiImpl
    Assert.assertEquals("NewRelic.getAgent().getTransaction() should return TransactionApiImpl", com.newrelic.agent.TransactionApiImpl.class, NewRelic.getAgent().getTransaction().getClass());
    // AgentBridge getTransaction call should return the TransactionApiImpl that exists in ThreadLocal
    Assert.assertNotNull(AgentBridge.getAgent().getTransaction(false));
    AsyncAnnotatedThreadInsideOfTxn asyncAnnotatedThreadInsideOfTxn = new AsyncAnnotatedThreadInsideOfTxn(token);
    asyncAnnotatedThreadInsideOfTxn.start();
}
Also used : Token(com.newrelic.api.agent.Token) Trace(com.newrelic.api.agent.Trace)

Example 13 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TestClass method getTokenApiSupportabilityNPEAfter.

public void getTokenApiSupportabilityNPEAfter() {
    Weaver.callOriginal();
    Token token = AgentBridge.getAgent().getTransaction(false).getToken();
    token.linkAndExpire();
}
Also used : Token(com.newrelic.api.agent.Token)

Example 14 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TestClass method getTokenApiSupportabilityNPEBefore.

public void getTokenApiSupportabilityNPEBefore() {
    Token token = AgentBridge.getAgent().getTransaction(false).getToken();
    token.linkAndExpire();
    Weaver.callOriginal();
}
Also used : Token(com.newrelic.api.agent.Token)

Example 15 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TransactionAsyncTimeoutTest method testMarkLastTxaFinished.

@Test
public void testMarkLastTxaFinished() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    final Token token = tx.getToken();
    TransactionActivity txa = TransactionActivity.get();
    txa.tracerFinished(rootTracer, 0);
    Assert.assertEquals("Last Txa should have been marked finished.", txa.getRootTracer().getEndTime(), tx.getTransactionTimer().getTimeLastTxaFinished());
    Thread a1 = new Thread() {

        @Override
        public void run() {
            Transaction.clearTransaction();
            Transaction oldTx = Transaction.getTransaction();
            Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "thread" + token.toString());
            oldTx.getTransactionActivity().tracerStarted(rootTracer);
            token.link();
            Transaction newTx = Transaction.getTransaction();
            Assert.assertTrue(oldTx != newTx);
            TransactionActivity txa = TransactionActivity.get();
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            txa.tracerFinished(rootTracer, 0);
            Assert.assertEquals("Last Txa should have been marked finished.", txa.getRootTracer().getEndTime(), newTx.getTransactionTimer().getTimeLastTxaFinished());
        }
    };
    a1.start();
    a1.join();
}
Also used : Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) Token(com.newrelic.api.agent.Token) TransactionActivity(com.newrelic.agent.TransactionActivity) Test(org.junit.Test)

Aggregations

Token (com.newrelic.api.agent.Token)24 Trace (com.newrelic.api.agent.Trace)8 Transaction (com.newrelic.agent.Transaction)4 Tracer (com.newrelic.agent.tracers.Tracer)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 TransactionActivity (com.newrelic.agent.TransactionActivity)1 NoOpToken (com.newrelic.agent.bridge.NoOpToken)1 Transaction (com.newrelic.agent.bridge.Transaction)1 WeavePackageType (com.newrelic.api.agent.weaver.internal.WeavePackageType)1 MuleUtils (com.nr.agent.instrumentation.mule3.MuleUtils)1 Job (gov.cms.ab2d.common.model.Job)1 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)1 FhirVersion (gov.cms.ab2d.fhir.FhirVersion)1 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1