use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class CrossProcessTransactionStateImplTest method testTransactionHeader.
// The following test used to cover the complex logic that tried to decide when to create and
// send GUIDs based on the old "Beacon" logic. Eventually the Browser product replaced this with
// a new and better implementation, so all the Agent support was ripped out sometime after the
// 3.13.0 release of the Agent. This test was modified to suit; so it compiles and executes now,
// and passes, but it's unclear what it's really testing.
@Test
public void testTransactionHeader() {
String encodingKey = "test";
String incomingId = "1#23";
String transactionHeader = "[\"8cd217491c0264d7\",false]";
String txGuid = "56b0d429ee4730fe";
String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",1.0,0.2,12345,\"" + txGuid + "\",false]", encodingKey);
ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), Obfuscator.obfuscateNameUsingKey(transactionHeader, encodingKey), "12345");
configureTestMocks(encodingKey, txGuid, obfuscatedAppData, request);
CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
crossProcessTransactionState.writeResponseHeaders();
crossProcessTransactionState.writeResponseHeaders();
verifyMocks(obfuscatedAppData);
assertEquals(1, stats.getUnscopedStats().getSize());
ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
assertEquals(1, clientAppStats.getCallCount());
assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class DistributedTraceCrossAgentTest method assertExpectedMetrics.
private void assertExpectedMetrics(ArrayList metrics, TransactionStats transactionStats) {
Assert.assertNotNull(transactionStats);
for (Object metric : metrics) {
ArrayList expectedStats = (ArrayList) metric;
String expectedMetricName = (String) expectedStats.get(0);
Long expectedMetricCount = (Long) ((JSONArray) metric).get(1);
final String message = String.format("Expected call count %d for: %s", expectedMetricCount, expectedMetricName);
if (expectedMetricName.startsWith("Supportability") || expectedMetricName.startsWith("ErrorsByCaller")) {
Stats actualStat = transactionStats.getUnscopedStats().getStats(expectedMetricName);
Assert.assertEquals(message, expectedMetricCount.intValue(), actualStat.getCallCount());
} else {
ResponseTimeStats actualStat = transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(expectedMetricName);
Assert.assertEquals(message, expectedMetricCount.intValue(), actualStat.getCallCount());
}
}
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class ThreadStateSamplerTest method testCpuTimeMetrics.
@Test
public void testCpuTimeMetrics() {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.setStatsService(new StatsServiceImpl());
StatsService statsService = ServiceFactory.getStatsService();
ThreadStateSampler threadStateSampler = new ThreadStateSampler(ManagementFactory.getThreadMXBean(), ThreadNameNormalizerTest.getThreadNameNormalizer());
CpuCalculationThread cpuCalculation = new CpuCalculationThread(threadStateSampler);
cpuCalculation.start();
try {
cpuCalculation.join();
} catch (InterruptedException e) {
}
StatsEngine engine = statsService.getStatsEngineForHarvest(null);
ResponseTimeStats systemTimeStats = engine.getResponseTimeStats("Threads/Time/CPU/CALCULATE_CPU/SystemTime");
ResponseTimeStats userTimeStats = engine.getResponseTimeStats("Threads/Time/CPU/CALCULATE_CPU/UserTime");
ResponseTimeStats totalTimeStats = engine.getResponseTimeStats("Threads/TotalTime/CALCULATE_CPU/CpuTime");
// these are approximate times
float systemTimeSeconds = systemTimeStats.getTotal();
float userTimeSeconds = userTimeStats.getTotal();
float totalTimeSeconds = totalTimeStats.getTotal();
float cpuCalculationTimeSeconds = (float) ((double) cpuCalculation.getCpuTime() / 1000000000) * 10;
assertTrue("CpuTime: " + cpuCalculationTimeSeconds + ", TotalTime: " + totalTimeSeconds, cpuCalculationTimeSeconds >= totalTimeSeconds);
assertTrue("UserTime: " + userTimeSeconds + ", SystemTime: " + systemTimeSeconds, userTimeSeconds > systemTimeSeconds);
// This test is prone to flickering due to high load scenarios and rounding errors, hence the modifier added to totalTimeSeconds
assertTrue("TotalTime: " + totalTimeSeconds + ", SystemTime: " + systemTimeSeconds + ", UserTime: " + userTimeSeconds, // account for rounding error
totalTimeSeconds + 4.0 >= systemTimeSeconds + userTimeSeconds);
// Since we can't guarantee the exact total time, it should be
// between 1 and 5 (since we had a busywork loop for ~5000ms)
assertTrue(totalTimeSeconds > 1.0f);
assertTrue(totalTimeSeconds < 6.0f);
}
Aggregations