Search in sources :

Example 26 with TransactionData

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

the class SlowQueryInfoTest method testEmptyTxnUrlRequestUriDisabled.

@Test
public void testEmptyTxnUrlRequestUriDisabled() {
    Map<String, Object> attributeMap = new HashMap<>();
    attributeMap.put("exclude", "request.*");
    Map<String, Object> settings = new HashMap<>();
    settings.put("attributes", attributeMap);
    setupServiceManager(settings);
    SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
    Transaction transaction = Transaction.getTransaction();
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setUri("http://jvm.agent.uri");
    transaction.setDispatcher(dispatcher);
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
    SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
    assertEquals(null, sqlTrace.getUri());
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 27 with TransactionData

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

the class SlowQueryInfoTest method testTxnUrl.

@Test
public void testTxnUrl() {
    setupServiceManager(new HashMap<String, Object>());
    Transaction transaction = Transaction.getTransaction();
    SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setUri("http://jvm.agent.uri");
    transaction.setDispatcher(dispatcher);
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
    SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
    assertEquals("http://jvm.agent.uri", sqlTrace.getUri());
}
Also used : SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 28 with TransactionData

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

the class KeyTransactionTraceSamplerTest method testSameScore.

@Test
public void testSameScore() throws Exception {
    Map<String, Double> keyTransactions = new HashMap<>();
    keyTransactions.put("keyTxnOne", 0.5);
    keyTransactions.put("keyTxnTwo", 0.25);
    setupAgent(keyTransactions);
    KeyTransactionTraceSampler sampler = new KeyTransactionTraceSampler();
    TransactionData keyTxnOne = createTransactionData("keyTxnOne", 1000);
    TransactionData keyTxnTwo = createTransactionData("keyTxnTwo", 500);
    sampler.noticeTransaction(keyTxnOne);
    sampler.noticeTransaction(keyTxnTwo);
    assertEquals(sampler.getScore(keyTxnOne), sampler.getScore(keyTxnTwo));
    // First one noticed should win
    List<TransactionTrace> traces = sampler.harvest(APP_NAME);
    TransactionTrace transactionTrace = traces.get(0);
    assertEquals("keyTxnOne", transactionTrace.getRequestUri());
    sampler.noticeTransaction(keyTxnTwo);
    sampler.noticeTransaction(keyTxnOne);
    transactionTrace = sampler.harvest(APP_NAME).get(0);
    assertEquals("keyTxnTwo", transactionTrace.getRequestUri());
}
Also used : HashMap(java.util.HashMap) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 29 with TransactionData

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

the class RandomTransactionSamplerTest method samplerChecksForMatchingAppName.

@Test
public void samplerChecksForMatchingAppName() throws Exception {
    ITransactionSampler transactionSampler = new RandomTransactionSampler(5);
    long durationInMillis = 5000L;
    TransactionData td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/en/betting/Football/*", durationInMillis + 100L);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    List<TransactionTrace> traces = transactionSampler.harvest("Bogus");
    Assert.assertEquals(0, traces.size());
    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 30 with TransactionData

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

the class TransactionTraceBucketTest method topN2.

@Test
public void topN2() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> ttMap = createConfigMap();
    ttMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 0.5f);
    ttMap.put(TransactionTracerConfigImpl.TOP_N, 2);
    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));
    td = createTransactionData("/de/betting/Chess/*", durationInMillis);
    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, traces.get(0).getDuration());
    td = createTransactionData("/en/betting/Football/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/de/betting/Chess/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/ru/betting/Motorsport/*", durationInMillis);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/ru/betting/Motorsport/*", traces.get(0).getRequestUri());
    Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
    td = createTransactionData("/en/betting/Football/*", durationInMillis - 200L);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/en/betting/Football/*", durationInMillis - 100L);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/ru/betting/Motorsport/*", durationInMillis);
    Assert.assertFalse(transactionSampler.noticeTransaction(td));
    td = createTransactionData("/ru/betting/Motorsport/*", durationInMillis + 100L);
    Assert.assertTrue(transactionSampler.noticeTransaction(td));
    traces = transactionSampler.harvest(APP_NAME);
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/ru/betting/Motorsport/*", traces.get(0).getRequestUri());
    Assert.assertEquals(durationInMillis + 100L, traces.get(0).getDuration());
}
Also used : 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