use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testSendOther.
@Test
public void testSendOther() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
TransactionActivityInitiator rootTracer = new OtherRootTracer(Transaction.getTransaction(), null, new Object(), null);
TransactionData transactionData = new TransactionDataTestBuilder(APP_NAME, iAgentConfig, new MockDispatcherTracer()).setDispatcher(rootTracer.createDispatcher()).setFrontendMetricName("Frontend/metricname").build();
TransactionStats transactionStats = new TransactionStats();
transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
// populate the eventData map
service.harvestEvents(APP_NAME);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
service.dispatcherTransactionFinished(transactionData, transactionStats);
assertEquals(1, currentEventData.size());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method createAndSendTransaction.
private DistributedSamplingPriorityQueue<TransactionEvent> createAndSendTransaction() {
TransactionData transactionData = generateTransactionData(APP_NAME);
TransactionStats transactionStats = new TransactionStats();
transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
service.dispatcherTransactionFinished(transactionData, transactionStats);
return currentEventData;
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testDifferentAppNamesOneDisabled.
@Test
public void testDifferentAppNamesOneDisabled() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
// server side says app name 2 disabled
Map<String, Object> data = new HashMap<>();
data.put("collect_analytics_events", Boolean.FALSE);
((ConfigServiceImpl) configService).connected(rpmServiceAppName2, data);
// default app name
TransactionData transactionData = generateTransactionData(APP_NAME);
TransactionStats transactionStats = new TransactionStats();
transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
// second app name
TransactionData transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
TransactionStats transactionStats2 = new TransactionStats();
transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
// third app name
String appName3 = "thirdAppName";
rpmServiceManager.getOrCreateRPMService(appName3);
TransactionData transactionData3 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), appName3);
TransactionStats transactionStats3 = new TransactionStats();
transactionStats3.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(10, TimeUnit.MILLISECONDS);
// populate the eventData map
service.harvestEvents(APP_NAME);
// populate the eventData map
service.harvestEvents(APP_NAME_2);
// populate the eventData map
service.harvestEvents(appName3);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData2 = getEventData(APP_NAME_2);
assertEquals(0, currentEventData2.size());
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData3 = getEventData(appName3);
assertEquals(0, currentEventData3.size());
service.dispatcherTransactionFinished(transactionData, transactionStats);
service.dispatcherTransactionFinished(transactionData2, transactionStats2);
service.dispatcherTransactionFinished(transactionData3, transactionStats3);
assertEquals(1, currentEventData.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
currentEventData2 = getEventData(APP_NAME_2);
assertNull(currentEventData2);
assertEquals(1, currentEventData3.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData3.peek().getDuration(), 0);
service.harvestEvents(APP_NAME);
currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
service.harvestEvents(appName3);
currentEventData3 = getEventData(appName3);
assertEquals(0, currentEventData3.size());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class LogSenderServiceImplTest method testHighSecurity.
@Test
public void testHighSecurity() throws Exception {
Map<String, Object> config = createConfig(true, 180);
LogSenderServiceImpl logSenderService = createService(config);
Transaction transaction = Mockito.mock(Transaction.class);
when(ServiceFactory.getTransactionService().getTransaction(false)).thenReturn(transaction);
LogSenderServiceImpl.TransactionLogs logs = new LogSenderServiceImpl.TransactionLogs(AgentConfigImpl.createAgentConfig(Collections.emptyMap()));
when(transaction.getLogEventData()).thenReturn(logs);
when(transaction.getApplicationName()).thenReturn(appName);
when(transaction.isInProgress()).thenReturn(true);
logSenderService.recordLogEvent(ImmutableMap.of("field", "value"));
logSenderService.recordLogEvent(ImmutableMap.of("field2", "value2"));
logSenderService.recordLogEvent(ImmutableMap.of("field3", "value3"));
MockRPMService analyticsData = new MockRPMService();
when(ServiceFactory.getServiceManager().getRPMServiceManager().getRPMService(appName)).thenReturn(analyticsData);
TransactionData transactionData = Mockito.mock(TransactionData.class);
when(transactionData.getApplicationName()).thenReturn(appName);
when(transactionData.getLogEventData()).thenReturn(logs);
logSenderService.transactionListener.dispatcherTransactionFinished(transactionData, null);
logSenderService.harvestHarvestables();
assertEquals(0, analyticsData.getEvents().size());
assertEquals(0, logs.events.size());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanEventHttp.
@Test
public void testSpanEventHttp() {
DefaultTracer tracer = prepareTracer();
tracer.reportAsExternal(HttpParameters.library("library").uri(URI.create("http://www.newrelic.com")).procedure("call").noInboundHeaders().build());
tracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertNull(spanEvent.getParentId());
assertEquals("library", spanEvent.getIntrinsics().get("component"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
assertEquals("http://www.newrelic.com", spanEvent.getAgentAttributes().get("http.url"));
assertEquals("call", spanEvent.getAgentAttributes().get("http.method"));
}
Aggregations