Search in sources :

Example 36 with TokenImpl

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"));
}
Also used : TokenImpl(com.newrelic.agent.TokenImpl) Test(org.junit.Test)

Example 37 with TokenImpl

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());
}
Also used : Transaction(com.newrelic.agent.Transaction) TokenImpl(com.newrelic.agent.TokenImpl) Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test)

Aggregations

TokenImpl (com.newrelic.agent.TokenImpl)37 Test (org.junit.Test)37 Transaction (com.newrelic.agent.Transaction)35 Tracer (com.newrelic.agent.tracers.Tracer)35 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)31 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)6 StatsBase (com.newrelic.agent.stats.StatsBase)6 TransactionAsyncUtility (com.newrelic.agent.TransactionAsyncUtility)5 WeakRefTransaction (com.newrelic.agent.WeakRefTransaction)1