use of com.newrelic.agent.TokenImpl in project newrelic-java-agent by newrelic.
the class AsyncTransactionServiceTest method testAsyncTransactionService.
@Test(timeout = 90000)
public void testAsyncTransactionService() throws Exception {
TransactionAsyncUtility.createServiceManager(createConfigMap(90000));
Transaction.clearTransaction();
TokenImpl token = new TokenImpl(null);
assertTrue(ServiceFactory.getAsyncTxService().putIfAbsent("myFirstKey", token));
assertTrue(ServiceFactory.getAsyncTxService().putIfAbsent("mySecondKey", token));
assertFalse(ServiceFactory.getAsyncTxService().putIfAbsent("myFirstKey", token));
assertFalse(ServiceFactory.getAsyncTxService().putIfAbsent("mySecondKey", token));
assertEquals(token, ServiceFactory.getAsyncTxService().extractIfPresent("myFirstKey"));
assertNull(ServiceFactory.getAsyncTxService().extractIfPresent("myFirstKey"));
assertEquals(token, ServiceFactory.getAsyncTxService().extractIfPresent("mySecondKey"));
assertNull(ServiceFactory.getAsyncTxService().extractIfPresent("mySecondKey"));
}
use of com.newrelic.agent.TokenImpl in project newrelic-java-agent by newrelic.
the class TokenTimeoutTest method testNoExpirationWhileRunning.
@Test
public void testNoExpirationWhileRunning() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
Tracer tokenInitTracer = token.getInitiatingTracer();
tx.setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, false, "CustomCategory", "names");
rootTracer.finish(Opcodes.RETURN, 0);
Assert.assertNull(data);
Assert.assertNull(stats);
busyWait(250);
ServiceFactory.getTransactionService().processQueue();
// wait for async token timeouts to complete
busyWait(500);
Assert.assertNotNull(data);
Assert.assertNotNull(stats);
assertEquals(1, stats.size());
assertTokenMetricCounts(1, 0, 1, 0, 0);
assertEquals("RequestDispatcher", tokenInitTracer.getMetricName());
assertEquals("Truncated/RequestDispatcher", tokenInitTracer.getTransactionSegmentName());
Assert.assertNull(tx.getAgentAttributes().get(AttributeNames.THREAD_NAME));
assertEquals(TimeoutCause.TOKEN, tx.getTimeoutCause());
String cause = MessageFormat.format(MetricNames.SUPPORTABILITY_ASYNC_TOKEN_TIMEOUT_CAUSE, "com.newrelic.agent.transaction.TokenTimeoutTest.hi()V");
assertEquals(1, ServiceFactory.getStatsService().getStatsEngineForHarvest("Unit Test").getStats(cause).getCallCount());
}
Aggregations