Search in sources :

Example 61 with TransactionStats

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

the class DatastoreForTransactionTest method testcheckDatastoresTwo.

@Test
public void testcheckDatastoresTwo() {
    // web
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mongo/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mongo/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/operation/mongo/insert").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Collection<DatastoreRequestImpl> actual = DatastoreForTransaction.checkDatastores(true, stats);
    Assert.assertEquals(2, actual.size());
    Iterator<DatastoreRequestImpl> it = actual.iterator();
    while (it.hasNext()) {
        DatastoreRequestImpl impl = it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("Datastore/operation/mongo/insert")) {
            Assert.assertEquals("mongo", impl.getDatastore());
            Assert.assertEquals("insert", impl.getOperation());
        } else {
            Assert.assertEquals("mysql", impl.getDatastore());
            Assert.assertEquals("table", impl.getTable());
            Assert.assertEquals("select", impl.getOperation());
        }
    }
    // other
    stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mongo/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mongo/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/operation/mongo/insert").recordResponseTime(10, TimeUnit.MILLISECONDS);
    actual = DatastoreForTransaction.checkDatastores(false, stats);
    Assert.assertEquals(2, actual.size());
    it = actual.iterator();
    while (it.hasNext()) {
        DatastoreRequestImpl impl = it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("Datastore/operation/mongo/insert")) {
            Assert.assertEquals("mongo", impl.getDatastore());
            Assert.assertEquals("insert", impl.getOperation());
        } else {
            Assert.assertEquals("mysql", impl.getDatastore());
            Assert.assertEquals("table", impl.getTable());
            Assert.assertEquals("select", impl.getOperation());
        }
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Test(org.junit.Test)

Example 62 with TransactionStats

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

the class ExternalsForTransactionTest method testHasExternals.

@Test
public void testHasExternals() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Unscoped/other").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Another/another").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Assert.assertFalse(ExternalsForTransaction.hasExternals(stats));
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Assert.assertTrue(ExternalsForTransaction.hasExternals(stats));
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Test(org.junit.Test)

Example 63 with TransactionStats

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

the class ExternalsForTransactionTest method testcheckExternalsTwoSameMetric.

@Test
public void testcheckExternalsTwoSameMetric() {
    // 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);
    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/mylib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/firstOp"));
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/secondOp"));
    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());
        Assert.assertEquals("myhost", impl.getHostname());
        Assert.assertEquals("mylib", impl.getLibrary());
        boolean firstOp = impl.getOperation().contains("firstOp");
        boolean secondOp = impl.getOperation().contains("secondOp");
        // one should be true and one should be false
        Assert.assertFalse(firstOp && secondOp);
        Assert.assertTrue(firstOp || secondOp);
    }
}
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 64 with TransactionStats

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

the class TransactionServiceTest method testRandomnessPriority.

@Test
public void testRandomnessPriority() throws InterruptedException {
    final List<TransactionEvent> events = new ArrayList<>();
    ServiceFactory.getServiceManager().getTransactionService().addTransactionListener(new TransactionListener() {

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            events.add(ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, transactionData.getBlameOrRootMetricName()));
        }
    });
    for (int i = 0; i < 100; i++) {
        Transaction.clearTransaction();
        Tracer rootTracer = makeTransaction();
        Transaction tx = rootTracer.getTransactionActivity().getTransaction();
        tx.getTransactionActivity().tracerStarted(rootTracer);
        rootTracer.finish(Opcodes.RETURN, 0);
        Assert.assertTrue(tx.isFinished());
    }
    Thread.sleep(1000);
    Assert.assertFalse(events.isEmpty());
    Assert.assertTrue(events.size() == 100);
    float first = events.get(0).getPriority();
    float second = events.get(1).getPriority();
    float third = events.get(2).getPriority();
    float forth = events.get(3).getPriority();
    Assert.assertFalse(first == second && first == third && first == forth);
}
Also used : TransactionEvent(com.newrelic.agent.service.analytics.TransactionEvent) TransactionStats(com.newrelic.agent.stats.TransactionStats) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 65 with TransactionStats

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

the class TransactionServiceTest method testDispatcherTransactionStarted.

@Test
public void testDispatcherTransactionStarted() {
    final AtomicReference<Transaction> startedTransaction = new AtomicReference<>(null);
    final AtomicReference<Transaction> finishedTransaction = new AtomicReference<>(null);
    ServiceFactory.getTransactionService().addTransactionListener(new ExtendedTransactionListener() {

        @Override
        public void dispatcherTransactionStarted(Transaction transaction) {
            startedTransaction.set(transaction);
        }

        @Override
        public void dispatcherTransactionCancelled(Transaction transaction) {
        }

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            finishedTransaction.set(transactionData.getTransaction());
        }
    });
    Tracer tracer = makeTransaction();
    assertNotNull(tracer);
    assertNotNull(startedTransaction.get());
    assertNull(finishedTransaction.get());
    assertEquals(tracer.getTransactionActivity().getTransaction(), startedTransaction.get());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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