use of com.newrelic.agent.stats.ResponseTimeStatsImpl in project newrelic-java-agent by newrelic.
the class TransactionAsyncEdgeCaseTest method testLinkAndExpireSameThreadTwoTracers.
@Test
public void testLinkAndExpireSameThreadTwoTracers() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
token.linkAndExpire();
Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod");
tx.getTransactionActivity().tracerStarted(defaultTracer);
defaultTracer.finish(Opcodes.RETURN, 0);
rootTracer.finish(Opcodes.RETURN, 0);
waitForTransaction();
Assert.assertNotNull(data);
Assert.assertNotNull(stats);
Assert.assertEquals(1, data.getTransactionActivities().size());
Collection<Tracer> tracers = data.getTracers();
Assert.assertEquals(2, tracers.size() + 1);
Iterator<Tracer> it = tracers.iterator();
while (it.hasNext()) {
Tracer t = it.next();
Assert.assertEquals("Custom/mymethod", t.getMetricName());
}
Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod");
Assert.assertEquals(1, sb.getCallCount());
sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
Assert.assertEquals(1, sb.getCallCount());
}
use of com.newrelic.agent.stats.ResponseTimeStatsImpl in project newrelic-java-agent by newrelic.
the class TransactionAsyncEdgeCaseTest method testLinkSameThreadTwoTracers.
@Test
public void testLinkSameThreadTwoTracers() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
Transaction.linkTxOnThread(token);
Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod");
tx.getTransactionActivity().tracerStarted(defaultTracer);
token.expire();
defaultTracer.finish(Opcodes.RETURN, 0);
rootTracer.finish(Opcodes.RETURN, 0);
waitForTransaction();
Assert.assertNotNull(data);
Assert.assertNotNull(stats);
Assert.assertEquals(1, data.getTransactionActivities().size());
Collection<Tracer> tracers = data.getTracers();
Assert.assertEquals(2, tracers.size() + 1);
Iterator<Tracer> it = tracers.iterator();
while (it.hasNext()) {
Tracer t = it.next();
Assert.assertEquals("Custom/mymethod", t.getMetricName());
}
Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod");
Assert.assertEquals(1, sb.getCallCount());
sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
Assert.assertEquals(1, sb.getCallCount());
}
use of com.newrelic.agent.stats.ResponseTimeStatsImpl in project newrelic-java-agent by newrelic.
the class DatastoreForTransaction method checkDatastores.
protected static Collection<DatastoreRequestImpl> checkDatastores(boolean isWeb, TransactionStats stats) {
int totalCount = 0;
// Datastore/all
// Datastore/allWeb or Datastore/allOther
Multimap<String, DatastoreRequestImpl> currentbyDatastore = HashMultimap.create();
for (Entry<String, StatsBase> current : stats.getScopedStats().getStatsMap().entrySet()) {
if (current.getKey().startsWith("Datastore/")) {
DatastoreRequestImpl impl = DatastoreRequestImpl.checkAndMakeDatastore(current.getKey());
if (impl != null) {
currentbyDatastore.put(impl.getDatastore(), impl);
totalCount++;
}
}
}
// check that unscoped metrics are correct
if (totalCount > 0) {
Map<String, StatsBase> unscoped = stats.getUnscopedStats().getStatsMap();
ResponseTimeStatsImpl all = (ResponseTimeStatsImpl) unscoped.get(ALL);
ResponseTimeStatsImpl allWebOther = (ResponseTimeStatsImpl) (isWeb ? unscoped.get(ALL_WEB) : unscoped.get(ALL_OTHER));
if ((all != null) && (all.getCallCount() == totalCount) && (allWebOther != null) && (allWebOther.getCallCount() == totalCount)) {
// then check the host metrics
Iterator<Entry<String, Collection<DatastoreRequestImpl>>> it = currentbyDatastore.asMap().entrySet().iterator();
Entry<String, Collection<DatastoreRequestImpl>> current;
while (it.hasNext()) {
current = it.next();
String prefix = MessageFormat.format(STORE_ALL, current.getKey());
ResponseTimeStatsImpl hostAll = (ResponseTimeStatsImpl) unscoped.get(prefix);
ResponseTimeStatsImpl hostWebOther = (ResponseTimeStatsImpl) (isWeb ? unscoped.get(prefix + "Web") : unscoped.get(prefix + "Other"));
if (hostAll == null || hostWebOther == null || hostAll.getCallCount() != current.getValue().size() || hostWebOther.getCallCount() != current.getValue().size()) {
it.remove();
}
}
return currentbyDatastore.values();
}
}
return Collections.emptyList();
}
use of com.newrelic.agent.stats.ResponseTimeStatsImpl in project newrelic-java-agent by newrelic.
the class JsonMetric method validateMetricExists.
public void validateMetricExists(StatsBase stats) {
// these two have already been verified
// Assert.assertEquals(transactionName, scope);
// Assert.assertEquals(mName, metricName);
Assert.assertTrue(stats instanceof ResponseTimeStatsImpl);
ResponseTimeStatsImpl impl = (ResponseTimeStatsImpl) stats;
String name = fileName + ", \"" + testName + "\", " + metricName + ", Invalid ";
Assert.assertEquals(name + "call count", count, impl.getCallCount());
Assert.assertEquals(name + "total time", totalTimeMs, impl.getTotal() * TimeConversion.MILLISECONDS_PER_SECOND, .001);
Assert.assertEquals(name + "exclusive time", exclusivetimeMs, impl.getTotalExclusiveTime() * TimeConversion.MILLISECONDS_PER_SECOND, .001);
if (minMs != null) {
Assert.assertEquals(name + "min time", minMs, impl.getMinCallTime() * TimeConversion.MILLISECONDS_PER_SECOND, .001);
} else if (impl.getCallCount() == 1) {
Assert.assertEquals(name + "min time", totalTimeMs, impl.getMinCallTime() * TimeConversion.MILLISECONDS_PER_SECOND, .001);
}
if (maxMs != null) {
Assert.assertEquals(name + "max time", maxMs, impl.getMaxCallTime() * TimeConversion.MILLISECONDS_PER_SECOND, .001);
} else if (impl.getCallCount() == 1) {
Assert.assertEquals(name + "max time", totalTimeMs, impl.getMaxCallTime() * TimeConversion.MILLISECONDS_PER_SECOND, .001);
}
}
use of com.newrelic.agent.stats.ResponseTimeStatsImpl in project newrelic-java-agent by newrelic.
the class TransactionAsyncEdgeCaseTest method testLinkSameThreadAfterWorkFinishes.
@Test
public void testLinkSameThreadAfterWorkFinishes() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "outer-hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token = (TokenImpl) tx.getToken();
Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod1");
tx.getTransactionActivity().tracerStarted(defaultTracer);
defaultTracer.finish(Opcodes.RETURN, 0);
rootTracer.finish(Opcodes.RETURN, 0);
Transaction.clearTransaction();
TransactionActivity.clear();
TransactionActivity.create(null, 0);
rootTracer = TransactionAsyncUtility.createOtherTracer("inner-hi");
TransactionActivity.get().tracerStarted(rootTracer);
Assert.assertTrue(Transaction.linkTxOnThread(token));
defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod2");
tx.getTransactionActivity().tracerStarted(defaultTracer);
token.expire();
defaultTracer.finish(Opcodes.RETURN, 0);
rootTracer.finish(Opcodes.RETURN, 0);
waitForTransaction();
Assert.assertNotNull(data);
Assert.assertNotNull(stats);
Assert.assertEquals(2, data.getTransactionActivities().size());
Collection<Tracer> tracers = data.getTracers();
Assert.assertEquals(4, tracers.size() + 1);
Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod1");
Assert.assertEquals(1, sb.getCallCount());
sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod2");
Assert.assertEquals(1, sb.getCallCount());
sb = (ResponseTimeStatsImpl) metrics.get("Java/java.lang.Object/inner-hi");
Assert.assertEquals(1, sb.getCallCount());
sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
Assert.assertEquals(1, sb.getCallCount());
}
Aggregations