Search in sources :

Example 11 with TransactionData

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 12 with TransactionData

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);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 13 with TransactionData

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 14 with TransactionData

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 15 with TransactionData

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) LazyMapImpl(com.newrelic.agent.LazyMapImpl) Test(org.junit.Test)

Aggregations

TransactionData (com.newrelic.agent.TransactionData)145 Test (org.junit.Test)136 TransactionDataList (com.newrelic.agent.TransactionDataList)46 TransactionStats (com.newrelic.agent.stats.TransactionStats)40 HashMap (java.util.HashMap)34 StatsEngine (com.newrelic.agent.stats.StatsEngine)29 Tracer (com.newrelic.agent.tracers.Tracer)23 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)17 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)16 Transaction (com.newrelic.agent.Transaction)15 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)15 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)15 JSONArray (org.json.simple.JSONArray)15 MockRPMService (com.newrelic.agent.MockRPMService)14 Map (java.util.Map)14 TransactionService (com.newrelic.agent.TransactionService)12 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)12 JSONObject (org.json.simple.JSONObject)12 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)10 SpanEvent (com.newrelic.agent.model.SpanEvent)10