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