Search in sources :

Example 1 with TokenImpl

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

Example 2 with TokenImpl

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

Example 3 with TokenImpl

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

Example 4 with TokenImpl

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

Example 5 with TokenImpl

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