use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTest method testTracerLimitAsyncMultiple.
@SuppressWarnings("unchecked")
@Test
public void testTracerLimitAsyncMultiple() throws Exception {
Map<String, Object> config = createConfigMap();
Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
ttmap.put("segment_limit", 3);
createServiceManager(config);
Object context1 = 1L;
Object context2 = 2L;
Object context3 = 3L;
Object context4 = 4L;
Object context5 = 5L;
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
tx.getTransactionActivity().tracerStarted(rootTracer);
assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
InitMultipleThread async1 = new InitMultipleThread(context1, context2, false);
async1.start();
async1.join();
assertEquals(1, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
TransactionStats stats = tx.getOverLimitTxStatsforTesting();
assertNull(stats);
InitMultipleThread async2 = new InitMultipleThread(context2, context3, false);
async2.start();
async2.join();
// two have been stored - the rest should be removed
assertEquals(1, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
float previous = verifyMetric(tx, 1, 0);
InitMultipleThread async3 = new InitMultipleThread(context3, context4, false);
async3.start();
async3.join();
assertEquals(1, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
previous = verifyMetric(tx, 2, previous);
InitMultipleThread async4 = new InitMultipleThread(context4, context5, false);
async4.start();
async4.join();
assertEquals(1, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
previous = verifyMetric(tx, 3, previous);
InitMultipleThread async5 = new InitMultipleThread(context5, null, false);
async5.start();
async5.join();
assertEquals(1, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
previous = verifyMetric(tx, 4, previous);
finishTransaction(tx, rootTracer);
assertEquals(0, tx.getRunningTransactionActivityCount());
assertEquals(2, tx.getFinishedChildren().size());
// here all of the stats should have been merged in - not just the TXAs that were dropped
verifyMetric(tx, 5, previous);
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTest method testTracerLimitAsyncStartLate.
// you really should not be starting late like this, but it should still work
@SuppressWarnings("unchecked")
@Test
public void testTracerLimitAsyncStartLate() throws Exception {
Map<String, Object> config = createConfigMap();
Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
ttmap.put("segment_limit", 3);
createServiceManager(config);
Object context1 = 1L;
Object context2 = 2L;
Object context3 = 3L;
Object context4 = 4L;
Object context5 = 5L;
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
tx.getTransactionActivity().tracerStarted(rootTracer);
assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
InitThreadStartLate async1 = new InitThreadStartLate(context1, context2, false);
async1.start();
async1.join();
assertEquals(1, tx.getFinishedChildren().size());
TransactionStats stats = tx.getOverLimitTxStatsforTesting();
assertNull(stats);
InitThreadStartLate async2 = new InitThreadStartLate(context2, context3, false);
async2.start();
async2.join();
assertEquals(1, tx.getFinishedChildren().size());
float previous = verifyMetric(tx, 1, 0);
InitThreadStartLate async3 = new InitThreadStartLate(context3, context4, false);
async3.start();
async3.join();
assertEquals(1, tx.getFinishedChildren().size());
previous = verifyMetric(tx, 2, previous);
InitThreadStartLate async4 = new InitThreadStartLate(context4, context5, false);
async4.start();
async4.join();
assertEquals(1, tx.getFinishedChildren().size());
previous = verifyMetric(tx, 3, previous);
InitThreadStartLate async5 = new InitThreadStartLate(context5, null, false);
async5.start();
async5.join();
assertEquals(1, tx.getFinishedChildren().size());
previous = verifyMetric(tx, 4, previous);
finishTransaction(tx, rootTracer);
assertEquals(2, tx.getFinishedChildren().size());
// here all of the stats should have been merged in - not just the TXAs that were dropped
verifyMetric(tx, 5, previous);
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTest method testTracerLimit2.
@SuppressWarnings("unchecked")
@Test
public void testTracerLimit2() throws Exception {
Map<String, Object> config = createConfigMap();
Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
ttmap.put("segment_limit", 3);
createServiceManager(config);
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
tx.getTransactionActivity().tracerStarted(rootTracer);
DefaultTracer t1 = createBasicTracer("one");
tx.getTransactionActivity().tracerStarted(t1);
tx.getTransactionActivity().tracerFinished(t1, 0);
DefaultTracer t2 = createBasicTracer("two");
tx.getTransactionActivity().tracerStarted(t2);
tx.getTransactionActivity().tracerFinished(t2, 0);
DefaultTracer t3 = createBasicTracer("three");
tx.getTransactionActivity().tracerStarted(t3);
tx.getTransactionActivity().tracerFinished(t3, 0);
DefaultTracer t4 = createBasicTracer("four");
tx.getTransactionActivity().tracerStarted(t4);
tx.getTransactionActivity().tracerFinished(t4, 0);
DefaultTracer t5 = createBasicTracer("five");
tx.getTransactionActivity().tracerStarted(t5);
tx.getTransactionActivity().tracerFinished(t5, 0);
finishTransaction(tx, rootTracer);
Set<TransactionActivity> done = tx.getFinishedChildren();
assertEquals(1, done.size());
TransactionActivity txa = done.iterator().next();
List<Tracer> tracers = txa.getTracers();
assertEquals(3, tracers.size());
assertTrue(tracers.contains(t1));
assertTrue(tracers.contains(t2));
assertTrue(tracers.contains(t3));
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class AttributeValidatorTest method testVerifyParametersAndReturnValues.
@Test
public void testVerifyParametersAndReturnValues() {
Transaction t = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
t.getTransactionActivity().tracerStarted(tracer);
CustomAttributeSender cas = new CustomAttributeSender();
assertNull(cas.verifyParameterAndReturnValue("NaN", Double.NaN, "dude"));
assertNull(cas.verifyParameterAndReturnValue("Infinity", Double.POSITIVE_INFINITY, "dude"));
assertEquals(cas.verifyParameterAndReturnValue("AtomicLong", new AtomicLong(10), "dude"), 10L);
assertEquals(cas.verifyParameterAndReturnValue("Boolean", true, "dude"), true);
assertEquals(cas.verifyParameterAndReturnValue("Integer", 10, "dude"), Integer.valueOf(10));
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class NoticeErrorAttributesTest method testNoticeErrorAPIFirstCallWins.
@Test
public void testNoticeErrorAPIFirstCallWins() {
try {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
AttributesService service = new AttributesService();
manager.setAttributesService(service);
RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
RPMService mockRPMService = mock(RPMService.class);
ErrorService errorService = new ErrorServiceImpl(APP_NAME);
when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
when(mockRPMService.getErrorService()).thenReturn(errorService);
Transaction t = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
t.getTransactionActivity().tracerStarted(tracer);
NewRelicApiImplementation impl = new NewRelicApiImplementation();
Map<String, String> atts = new HashMap<>();
atts.put("test.foo", "1");
impl.noticeError("hello", atts);
Map<String, String> atts2 = new HashMap<>();
atts.put("test.bar", "2");
impl.noticeError("hello", atts2);
Set<String> expected = Sets.newHashSet("test.foo");
verifyOutput(t.getErrorAttributes(), expected);
} finally {
Transaction.clearTransaction();
}
}
Aggregations