use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class ApiTest method testSetTxNameThenSetRequestAndResponse.
@Test
public void testSetTxNameThenSetRequestAndResponse() {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
Transaction tx = Transaction.getTransaction();
OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
NewRelic.setTransactionName("Test", "Foo");
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
tracer.finish(0, null);
Assert.assertEquals("WebTransaction/Test/Foo", tx.getPriorityTransactionName().getName());
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class SpanParentTest method testSpanAndTransactionParenting.
@Test
public void testSpanAndTransactionParenting() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
executeSpanAndTransactionParentingTest();
try {
TransactionDataList transactionList = holder.getTransactionList();
assertEquals(2, transactionList.size());
TransactionData tx1 = transactionList.get(0);
TransactionData tx2 = transactionList.get(1);
Collection<Tracer> tracers1 = tx1.getTracers();
// Only a "rootTracer" on this transaction (root tracer is not in this list)
assertEquals(0, tracers1.size());
Collection<Tracer> tracers2 = tx2.getTracers();
// 1 "rootTracer" (not in this list) + 2 non-external/datastore tracers + 2 external datastore tracers
assertEquals(4, tracers2.size());
SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
assertNotNull(spanEventsPool);
List<SpanEvent> spanEvents = spanEventsPool.asList();
spanEventsPool.clear();
assertNotNull(spanEvents);
assertEquals(6, spanEvents.size());
SpanEvent rootSpanEvent = null;
Set<String> spanEventGuids = new HashSet<>();
for (SpanEvent spanEvent : spanEvents) {
if (spanEvent.getParentId() == null) {
rootSpanEvent = spanEvent;
}
spanEventGuids.add(spanEvent.getGuid());
}
assertNotNull(rootSpanEvent);
assertEquals(6, spanEventGuids.size());
// Ensure that spans are only parented to other spans
for (SpanEvent spanEvent : spanEvents) {
if (spanEvent.getParentId() == null) {
continue;
}
assertTrue(spanEventGuids.contains(spanEvent.getParentId()));
}
TransactionEventsService transactionEventsService = ServiceFactory.getServiceManager().getTransactionEventsService();
DistributedSamplingPriorityQueue<TransactionEvent> txEventPool = transactionEventsService.getOrCreateDistributedSamplingReservoir(appName);
assertNotNull(txEventPool);
List<TransactionEvent> txEvents = txEventPool.asList();
txEventPool.clear();
assertNotNull(txEvents);
assertEquals(2, txEvents.size());
TransactionEvent parent = null;
TransactionEvent child = null;
for (TransactionEvent txEvent : txEvents) {
if (txEvent.getParentId() == null) {
parent = txEvent;
} else {
child = txEvent;
}
}
assertNotNull(parent);
assertNotNull(child);
assertNull(parent.getParentId());
assertEquals(parent.getGuid(), child.getParentId());
} finally {
holder.close();
}
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class SpanParentTest method testSpanParenting.
@Test
public void testSpanParenting() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
Header actualHeader = txnStarter(false);
try {
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
Collection<Tracer> tracers = transactionList.get(0).getTracers();
String expectedGuid = ((TracerList) tracers).get(0).getGuid();
String actualGuid = findGuid(actualHeader.getValue());
Assert.assertEquals(expectedGuid, actualGuid);
} finally {
holder.close();
}
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class SpringBootAsyncTest method testInconsistentState.
@Test
public void testInconsistentState() {
ConfigurableApplicationContext context = SpringApplication.run(AsyncResource.class);
// Ignore the servlet init() transactions
transactions.clear();
try {
Collection<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < 250; i++) {
futures.add(executor.submit(new Runnable() {
@Override
public void run() {
try {
HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8090/" + ENDPOINT.getPort()).openConnection();
int responseCode = connection.getResponseCode();
assertEquals(200, responseCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}));
}
for (Future<?> future : futures) {
future.get(30, TimeUnit.SECONDS);
}
TransactionDataList list = transactions.waitFor(250, TimeUnit.SECONDS.toMillis(30));
Set<String> uniqueTxNames = new HashSet<>(list.getTransactionNames());
assertEquals(1, uniqueTxNames.size());
assertTrue(uniqueTxNames.contains("WebTransaction/SpringController/{port} (GET)"));
} catch (Exception e) {
e.printStackTrace();
} finally {
executor.shutdownNow();
executorService.shutdownNow();
context.close();
}
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class AgentTest method ttSizeLimitExceeded.
/**
* If the transaction trace size limit is exceeded, a tracer should record metrics but not be part of the
* transaction trace.
*/
@Test
public void ttSizeLimitExceeded() throws ServletException, IOException {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
TestSizeLimitServlet servlet = new TestSizeLimitServlet();
String path = "/my/word";
AgentHelper.invokeServlet(servlet, "", APPLICATION_NAME_2, path);
StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
MetricName metricName = MetricName.create("Custom/test.newrelic.test.agent.AgentTest$TestSizeLimitServlet/doNothing", "WebTransaction/Servlet/TestSizeLimitServlet");
ResponseTimeStats stats = statsEngine.getResponseTimeStats(metricName);
Assert.assertEquals(2, stats.getCallCount());
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
Collection<Tracer> tracers = AgentHelper.getTracers(transactionData.getRootTracer());
Assert.assertEquals(3, tracers.size());
}
Aggregations