use of com.newrelic.agent.TokenImpl in project newrelic-java-agent by newrelic.
the class AsyncTransactionServiceTest method testAsyncTransactionServiceTimeout.
@Test(timeout = 90000)
public void testAsyncTransactionServiceTimeout() throws Exception {
TransactionAsyncUtility.createServiceManager(createConfigMap(1));
assertEquals(0, ServiceFactory.getAsyncTxService().cacheSizeForTesting());
ServiceFactory.getAsyncTxService().beforeHarvest("test", null);
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(2, ServiceFactory.getAsyncTxService().cacheSizeForTesting());
Thread.sleep(5000);
ServiceFactory.getAsyncTxService().cleanUpPendingTransactions();
assertEquals(0, ServiceFactory.getAsyncTxService().cacheSizeForTesting());
assertNull(ServiceFactory.getAsyncTxService().extractIfPresent("myFirstKey"));
assertNull(ServiceFactory.getAsyncTxService().extractIfPresent("mySecondKey"));
ServiceFactory.getAsyncTxService().beforeHarvest("test", null);
assertEquals(0, ServiceFactory.getAsyncTxService().cacheSizeForTesting());
}
use of com.newrelic.agent.TokenImpl in project newrelic-java-agent by newrelic.
the class TokenTest method testTracerNullAfterExpire.
@Test
public void testTracerNullAfterExpire() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
Assert.assertNotNull(token.getInitiatingTracer());
Assert.assertNotNull(token.getTransaction());
token.expire();
waitForTransaction();
Assert.assertNull(token.getInitiatingTracer());
Assert.assertNotNull(token.getTransaction());
Assert.assertTrue(token.getTransaction() instanceof WeakRefTransaction);
}
use of com.newrelic.agent.TokenImpl in project newrelic-java-agent by newrelic.
the class TokenTimeoutTest method testLotsOfTokensNotExpired.
@Test
public void testLotsOfTokensNotExpired() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token3 = (TokenImpl) tx.getToken();
TokenImpl token4 = (TokenImpl) tx.getToken();
Tracer token3InitTracer = token3.getInitiatingTracer();
tx.setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, false, "CustomCategory", "names");
// expire after root tracer finish
TransactionAsyncUtility.StartAndThenLink activity1 = new TransactionAsyncUtility.StartAndThenLink(tx, false, true);
activity1.start();
activity1.join();
rootTracer.finish(Opcodes.RETURN, 0);
Assert.assertNull(data);
Assert.assertNull(stats);
// expire before root finish
TransactionAsyncUtility.StartAndThenLink activity2 = new TransactionAsyncUtility.StartAndThenLink(tx, true, false);
activity2.start();
activity2.join();
// if the threads above take longer than 250ms to start and finish then these null checks will cause a flicker
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(4, 2, 2, 0, 2);
assertEquals("RequestDispatcher", token3InitTracer.getMetricName());
assertEquals("Truncated/RequestDispatcher", token3InitTracer.getTransactionSegmentName());
String cause = MessageFormat.format(MetricNames.SUPPORTABILITY_ASYNC_TOKEN_TIMEOUT_CAUSE, "com.newrelic.agent.transaction.TokenTimeoutTest.hi()V");
assertEquals(2, ServiceFactory.getStatsService().getStatsEngineForHarvest("Unit Test").getStats(cause).getCallCount());
}
use of com.newrelic.agent.TokenImpl in project newrelic-java-agent by newrelic.
the class TokenTimeoutTest method testExpireAfterAccess.
@Test
public void testExpireAfterAccess() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
tx.setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, false, "CustomCategory", "names");
Assert.assertNotNull(token.getTransaction());
Assert.assertNotNull(token.getInitiatingTracer());
// if refresh didn't work this token would expire after 250ms
busyWait(200);
tx.refreshToken(token);
ServiceFactory.getTransactionService().processQueue();
Assert.assertNotNull(token.getTransaction());
Assert.assertNotNull(token.getInitiatingTracer());
busyWait(200);
tx.refreshToken(token);
ServiceFactory.getTransactionService().processQueue();
busyWait(300);
ServiceFactory.getTransactionService().processQueue();
// wait for async token timeouts to complete
busyWait(500);
Assert.assertNull(token.getInitiatingTracer());
Assert.assertNull(token.getInitiatingTracer());
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());
}
use of com.newrelic.agent.TokenImpl in project newrelic-java-agent by newrelic.
the class TransactionAsyncRootFirstTest method testStartAndThenLinkExpireBoth.
@Test
public void testStartAndThenLinkExpireBoth() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
rootTracer.finish(Opcodes.RETURN, 0);
// second expire should do nothing
StartAndThenLink activity1 = new StartAndThenLink(token, true, true);
activity1.start();
activity1.join();
verifyDataTwo(activity1, tx, token);
}
Aggregations