Search in sources :

Example 36 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class ExternalsForTransactionTest method testAddExternalsOneCall.

@Test
public void testAddExternalsOneCall() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    tracers.add(createTracer("External/myhost/secondlib", "External/myhost/secondlib/seconop"));
    ExternalsForTransaction exts = new ExternalsForTransaction();
    exts.addExternals(true, stats, tracers);
    Collection<ExternalRequest> actual = exts.getExternals();
    Assert.assertEquals(2, actual.size());
    Iterator<ExternalRequest> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("External/myhost/mylib")) {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("mylib", impl.getLibrary());
            Assert.assertEquals("myop", impl.getOperation());
        } else {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("seconop", impl.getOperation());
        }
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 37 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class ExternalsForTransactionTest method testcheckExternalsOne.

@Test
public void testcheckExternalsOne() {
    // web
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    Collection<ExternalRequestImpl> actual = ExternalsForTransaction.checkExternals(true, stats, tracers);
    Assert.assertEquals(1, actual.size());
    ExternalRequestImpl impl = actual.iterator().next();
    Assert.assertEquals(1, impl.getCount());
    Assert.assertEquals("myhost", impl.getHostname());
    Assert.assertEquals("mylib", impl.getLibrary());
    Assert.assertEquals("myOp", impl.getOperation());
    // other
    stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    actual = ExternalsForTransaction.checkExternals(false, stats, tracers);
    Assert.assertEquals(1, actual.size());
    impl = actual.iterator().next();
    Assert.assertEquals(1, impl.getCount());
    Assert.assertEquals("myhost", impl.getHostname());
    Assert.assertEquals("mylib", impl.getLibrary());
    Assert.assertEquals("myOp", impl.getOperation());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 38 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class ExternalsForTransactionTest method testAddExternalsTwoCallsSameOperation.

@Test
public void testAddExternalsTwoCallsSameOperation() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    ExternalsForTransaction exts = new ExternalsForTransaction();
    exts.addExternals(true, stats, tracers);
    stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    exts.addExternals(true, stats, tracers);
    Collection<ExternalRequest> actual = exts.getExternals();
    Assert.assertEquals(1, actual.size());
    Iterator<ExternalRequest> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
        Assert.assertEquals(2, impl.getCount());
        Assert.assertEquals("myhost", impl.getHostname());
        Assert.assertEquals("mylib", impl.getLibrary());
        Assert.assertEquals("myop", impl.getOperation());
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 39 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class ExternalsForTransactionTest method testcheckExternalsSameHost.

@Test
public void testcheckExternalsSameHost() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    tracers.add(createTracer("External/myhost/secondlib", "External/myhost/secondlib/thirdOp"));
    Collection<ExternalRequestImpl> actual = ExternalsForTransaction.checkExternals(true, stats, tracers);
    Assert.assertEquals(2, actual.size());
    Iterator<ExternalRequestImpl> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("External/myhost/mylib")) {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("mylib", impl.getLibrary());
            Assert.assertEquals("myOp", impl.getOperation());
        } else {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("thirdOp", impl.getOperation());
        }
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 40 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class TraceAnnotationTest method testCallAsyncAnnotatedThreadInsideOfTxnMultiThreaded.

/* Case 4: @Trace(async = true), multithreaded with a started Transaction */
@Test
public void testCallAsyncAnnotatedThreadInsideOfTxnMultiThreaded() throws InterruptedException {
    Transaction.clearTransaction();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicBoolean metricsAssertionsPassed = new AtomicBoolean(false);
    // AgentBridge getTransaction call should return null if no Transaction exists in ThreadLocal
    Assert.assertNull(AgentBridge.getAgent().getTransaction(false));
    // Transaction listener which will only countdown the latch when a specific txn finishes
    ServiceFactory.getTransactionService().addTransactionListener(new TransactionListener() {

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            PriorityTransactionName ptn = transactionData.getTransaction().getPriorityTransactionName();
            String txnMetric1 = "Java/test.newrelic.test.agent.TraceAnnotationTest$AsyncAnnotatedThreadInsideOfTxn/run";
            String txnMetric2 = "Java/test.newrelic.test.agent.TraceAnnotationTest/callAsyncAnnotatedThreadInsideOfTxnMultiThreaded";
            Map<String, StatsBase> scopedStatsMap = transactionStats.getScopedStats().getStatsMap();
            if (ptn.getPartialName().equals("/MyCategory/TracedAsyncTxn")) {
                try {
                    Assert.assertTrue("The following metric should exist: " + txnMetric1, scopedStatsMap.containsKey(txnMetric1));
                    Assert.assertTrue("The following metric should exist: " + txnMetric2, scopedStatsMap.containsKey(txnMetric2));
                    metricsAssertionsPassed.set(true);
                } catch (Throwable t) {
                    metricsAssertionsPassed.set(false);
                    t.printStackTrace();
                } finally {
                    latch.countDown();
                }
            }
        }
    });
    callAsyncAnnotatedThreadInsideOfTxnMultiThreaded();
    latch.await();
    Assert.assertTrue("Metric assertions didn't pass", metricsAssertionsPassed.get());
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransactionStats(com.newrelic.agent.stats.TransactionStats) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) TransactionData(com.newrelic.agent.TransactionData) CountDownLatch(java.util.concurrent.CountDownLatch) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

TransactionStats (com.newrelic.agent.stats.TransactionStats)104 Test (org.junit.Test)90 TransactionData (com.newrelic.agent.TransactionData)40 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)15 Tracer (com.newrelic.agent.tracers.Tracer)15 HashMap (java.util.HashMap)14 SpanEvent (com.newrelic.agent.model.SpanEvent)13 TransactionService (com.newrelic.agent.TransactionService)12 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)11 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)11 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)11 ArrayList (java.util.ArrayList)11 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)10 Map (java.util.Map)9 Transaction (com.newrelic.agent.Transaction)8 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)8 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)7 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 JSONArray (org.json.simple.JSONArray)5