Search in sources :

Example 31 with TransactionData

use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.

the class TransactionTraceBucketTest method slowest.

@Test
public void slowest() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> ttMap = createConfigMap();
    ttMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 0.5f);
    configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttMap);
    createServiceManager(configMap);
    ITransactionSampler transactionSampler = new TransactionTraceSampler();
    long durationInMillis = 1000L;
    TransactionData td = createTransactionData("/en/betting/Football/*", durationInMillis - 100);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/en/betting/Football/*", durationInMillis - 200);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    List<TransactionTrace> traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/en/betting/Football/*", traces.get(0).getRequestUri());
    Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
}
Also used : TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 32 with TransactionData

use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.

the class TransactionTraceBucketTest method noTraceCount.

@Test
public void noTraceCount() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> ttMap = createConfigMap();
    ttMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 0.5f);
    ttMap.put(TransactionTracerConfigImpl.TOP_N, 10);
    configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttMap);
    createServiceManager(configMap);
    ITransactionSampler transactionSampler = new TransactionTraceSampler();
    long durationInMillis = 1000L;
    TransactionData td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    List<TransactionTrace> traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/en/betting/Football/*", traces.get(0).getRequestUri());
    Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(0, traces.size());
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(0, traces.size());
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(0, traces.size());
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(0, traces.size());
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(0, traces.size());
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/en/betting/Football/*", traces.get(0).getRequestUri());
    Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
}
Also used : TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 33 with TransactionData

use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.

the class TransactionTraceBucketTest method harvest.

@Test
public void harvest() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> ttMap = createConfigMap();
    ttMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 0.5f);
    configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttMap);
    createServiceManager(configMap);
    ITransactionSampler transactionSampler = new TransactionTraceSampler();
    long durationInMillis = 1000L;
    TransactionData td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    List<TransactionTrace> traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/en/betting/Football/*", traces.get(0).getRequestUri());
    Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
    td = createTransactionData("/de/betting/Chess/*", durationInMillis + 100L);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/de/betting/Chess/*", traces.get(0).getRequestUri());
    Assert.assertEquals(durationInMillis + 100L, traces.get(0).getDuration());
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(0, traces.size());
}
Also used : TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 34 with TransactionData

use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.

the class TransactionTraceServiceTest method randomTransactionSampler.

@Test
public void randomTransactionSampler() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> ttConfigMap = new HashMap<>();
    configMap.put("transaction_tracer", ttConfigMap);
    ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
    ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
    ttConfigMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 1000f);
    createServiceManager(configMap);
    TransactionTraceService ttService = ServiceFactory.getTransactionTraceService();
    TransactionData td = createTransactionData("/en/betting/Baseball/*", APP_NAME, 10L);
    ttService.dispatcherTransactionFinished(td, null);
    ttService.afterHarvest(APP_NAME);
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService(APP_NAME);
    List<TransactionTrace> traces = rpmService.getTraces();
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/en/betting/Baseball/*", traces.get(0).getRequestUri());
    Assert.assertEquals(10L, traces.get(0).getDuration());
}
Also used : HashMap(java.util.HashMap) TransactionData(com.newrelic.agent.TransactionData) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 35 with TransactionData

use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.

the class DistributedTraceServiceImplTest method txnFinished.

@Test
public void txnFinished() {
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    TransactionStats transactionStats = new TransactionStats();
    Map<String, Object> intrinsicAttributes = new HashMap<>();
    long startTimeInMillis = System.currentTimeMillis();
    long responseTimeInNanos = TimeUnit.MILLISECONDS.toNanos(1350);
    TransactionData transactionData = createTransactionData(intrinsicAttributes, startTimeInMillis, responseTimeInNanos, null);
    distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
    SimpleStatsEngine unscopedStats = transactionStats.getUnscopedStats();
    String responseTime = MessageFormat.format(MetricNames.DURATION_BY_PARENT_UNKNOWN_ALL, "HTTPS");
    String errors = MessageFormat.format(MetricNames.ERRORS_BY_PARENT_UNKNOWN, "HTTPS");
    assertEquals(1.35, unscopedStats.getOrCreateResponseTimeStats(responseTime).getTotal(), 0.01f);
    assertEquals(1, unscopedStats.getStats(errors).getCallCount());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) 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