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());
}
}
}
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));
}
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);
}
}
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);
}
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());
}
Aggregations