use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method test.
@Test
public void test() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
TransactionData transactionData = generateTransactionData(APP_NAME);
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());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
service.harvestEvents(APP_NAME);
currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testDifferentAppNamesOneDisabledMiddle.
@Test
public void testDifferentAppNamesOneDisabledMiddle() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
// 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";
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);
assertEquals(1, currentEventData2.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData2.peek().getDuration(), 0);
assertEquals(1, currentEventData3.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData3.peek().getDuration(), 0);
// 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);
// second time with second name
transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
transactionStats2 = new TransactionStats();
transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
service.dispatcherTransactionFinished(transactionData2, transactionStats2);
currentEventData2 = getEventData(APP_NAME_2);
// since the second app has been disabled - this should be false
assertNull(currentEventData2);
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testErrorSavesData.
@Test
public void testErrorSavesData() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
TransactionData transactionData = generateTransactionData(APP_NAME);
TransactionStats transactionStats = new TransactionStats();
// populate the eventData map
service.harvestEvents(APP_NAME);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
for (int i = 0; i < TEST_RESERVOIR_SIZE * 2; i++) {
service.dispatcherTransactionFinished(transactionData, transactionStats);
}
assertEquals(TEST_RESERVOIR_SIZE * 2, currentEventData.getNumberOfTries());
service.harvestEvents(APP_NAME);
assertEquals(TEST_RESERVOIR_SIZE * 2, currentEventData.getNumberOfTries());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testDisabled.
@Test
public void testDisabled() throws Exception {
setup(false, true, TEST_RESERVOIR_SIZE);
assertFalse(service.isEnabled());
TransactionData transactionData = generateTransactionData(APP_NAME);
TransactionStats transactionStats = new TransactionStats();
// populate the eventData map
service.harvestEvents(APP_NAME);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
service.dispatcherTransactionFinished(transactionData, transactionStats);
assertEquals(0, currentEventData.size());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testUserParameters.
@Test
public void testUserParameters() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
Map<String, Object> userParams = new LazyMapImpl<>();
userParams.put("key1", "value1");
userParams.put("key2", "value2");
TransactionData transactionData = generateTransactionDataAndComplete(userParams, APP_NAME);
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());
final TransactionEvent queueHead = currentEventData.peek();
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, queueHead.getDuration(), 0);
final Map<String, Object> attributes = queueHead.getUserAttributesCopy();
assertEquals(2, attributes.size());
assertEquals("value1", attributes.get("key1"));
assertEquals("value2", attributes.get("key2"));
service.harvestEvents(APP_NAME);
currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
}
Aggregations