Search in sources :

Example 31 with TransactionStats

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

the class DatastoreForTransactionTest method testAddDatastoresTwoCalls.

@Test
public void testAddDatastoresTwoCalls() {
    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);
    DatastoreForTransaction exts = new DatastoreForTransaction();
    exts.addDatastore(true, stats);
    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/operation/mysql/insert").recordResponseTime(10, TimeUnit.MILLISECONDS);
    exts.addDatastore(true, stats);
    Collection<DataStoreRequest> actual = exts.getDatastores();
    Assert.assertEquals(2, actual.size());
    Iterator<DataStoreRequest> it = actual.iterator();
    while (it.hasNext()) {
        DatastoreRequestImpl impl = (DatastoreRequestImpl) it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("Datastore/operation/mysql/insert")) {
            Assert.assertEquals("mysql", 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) DataStoreRequest(com.newrelic.agent.introspec.DataStoreRequest) Test(org.junit.Test)

Example 32 with TransactionStats

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

the class DatastoreForTransactionTest method testcheckDatastoresOne.

@Test
public void testcheckDatastoresOne() {
    // 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);
    Collection<DatastoreRequestImpl> actual = DatastoreForTransaction.checkDatastores(true, stats);
    Assert.assertEquals(1, actual.size());
    DatastoreRequestImpl impl = actual.iterator().next();
    Assert.assertEquals(1, impl.getCount());
    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/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
    actual = DatastoreForTransaction.checkDatastores(true, stats);
    Assert.assertEquals(0, actual.size());
    actual = DatastoreForTransaction.checkDatastores(false, stats);
    Assert.assertEquals(1, actual.size());
    impl = actual.iterator().next();
    Assert.assertEquals(1, impl.getCount());
    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 33 with TransactionStats

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

the class DatastoreForTransactionTest method testcheckDatastoresSameHost.

@Test
public void testcheckDatastoresSameHost() {
    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/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/operation/mysql/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/mysql/insert")) {
            Assert.assertEquals("mysql", 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 34 with TransactionStats

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

the class DatastoreForTransactionTest method testAddDatastoresOneCall.

@Test
public void testAddDatastoresOneCall() {
    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/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/operation/mysql/insert").recordResponseTime(10, TimeUnit.MILLISECONDS);
    DatastoreForTransaction exts = new DatastoreForTransaction();
    exts.addDatastore(true, stats);
    Collection<DataStoreRequest> actual = exts.getDatastores();
    Assert.assertEquals(2, actual.size());
    Iterator<DataStoreRequest> it = actual.iterator();
    while (it.hasNext()) {
        DatastoreRequestImpl impl = (DatastoreRequestImpl) it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("Datastore/operation/mysql/insert")) {
            Assert.assertEquals("mysql", 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) DataStoreRequest(com.newrelic.agent.introspec.DataStoreRequest) Test(org.junit.Test)

Example 35 with TransactionStats

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

the class ExternalsForTransactionTest method testcheckExternalsTwo.

@Test
public void testcheckExternalsTwo() {
    // 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/secondhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/secondhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    tracers.add(createTracer("External/secondhost/secondlib", "External/secondhost/secondlib/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());
        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("secondhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("secondOp", 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);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allOther").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/secondhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/secondhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    tracers.add(createTracer("External/secondhost/secondlib", "External/secondhost/secondlib/secondOp"));
    actual = ExternalsForTransaction.checkExternals(false, stats, tracers);
    Assert.assertEquals(2, actual.size());
    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("secondhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("secondOp", 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)

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