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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations