Search in sources :

Example 16 with TransactionData

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

Example 17 with TransactionData

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

Example 18 with TransactionData

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());
}
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 19 with TransactionData

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());
}
Also used : Transaction(com.newrelic.agent.Transaction) TransactionData(com.newrelic.agent.TransactionData) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 20 with TransactionData

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"));
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) 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