use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method multipleTransactions.
@Test
public void multipleTransactions() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run another transaction
requestDispatcherTracer = startDispatcherTracer();
long duration2 = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
startSqlTracer("select * from dude where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
startSqlTracer("select * from duderino where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a harvest
MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(3, sqlTraces.size());
long expectedDuration = TimeUnit.MILLISECONDS.convert(duration, TimeUnit.NANOSECONDS);
long expectedDuration2 = TimeUnit.MILLISECONDS.convert(duration2, TimeUnit.NANOSECONDS);
String expectedSql = "select * from dude where somevalue = ?";
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
long expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
SqlTrace sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(4, sqlTrace.getCallCount());
Assert.assertEquals((expectedDuration * 2) + (expectedDuration2 * 2), sqlTrace.getTotal());
Assert.assertEquals(expectedDuration, sqlTrace.getMin());
Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
expectedSql = "select * from dudette where somevalue = ?";
expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(2, sqlTrace.getCallCount());
Assert.assertEquals(expectedDuration + expectedDuration2, sqlTrace.getTotal());
Assert.assertEquals(expectedDuration, sqlTrace.getMin());
Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
expectedSql = "select * from duderino where somevalue = ?";
expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(1, sqlTrace.getCallCount());
Assert.assertEquals(expectedDuration2, sqlTrace.getTotal());
Assert.assertEquals(expectedDuration2, sqlTrace.getMin());
Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method multipleApps.
@Test
public void multipleApps() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
// run a transaction in "Test" app
Tracer requestDispatcherTracer = startDispatcherTracer("Test");
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
Transaction.getTransaction().setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, "Test");
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a transaction in "Test2" app
requestDispatcherTracer = startDispatcherTracer("Test2");
startSqlTracer("select * from dude2 where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude2 where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette2 where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
Transaction.getTransaction().setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, "Test2");
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a harvest for "Test"
MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
mockharvestService.runHarvest("Test", new StatsEngineImpl());
MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService("Test");
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(2, sqlTraces.size());
// run a harvest for "Test2"
mockharvestService.runHarvest("Test2", new StatsEngineImpl());
mockRPMService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService("Test2");
sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(2, sqlTraces.size());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method overSqlLimit.
@Test
public void overSqlLimit() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
int sqlLimit = SlowQueryAggregatorImpl.SLOW_QUERY_LIMIT_PER_REPORTING_PERIOD;
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
for (int i = 0; i < sqlLimit * 2; i++) {
String sql = "select * from dude where column" + i + " = 'cool'";
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1 + i, TimeUnit.MILLISECONDS);
startSqlTracer(sql, duration).finish(Opcodes.RETURN, null);
}
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a harvest
MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(sqlLimit, sqlTraces.size());
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
for (int i = sqlLimit; i < sqlLimit * 2; i++) {
String expectedSql = "select * from dude where column" + i + " = ?";
long expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
SqlTrace sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
long expectedDuration = getExplainThresholdInMillis() + 1 + i;
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(1, sqlTrace.getCallCount());
Assert.assertEquals(expectedDuration, sqlTrace.getTotal());
Assert.assertEquals(expectedDuration, sqlTrace.getMin());
Assert.assertEquals(expectedDuration, sqlTrace.getMax());
}
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method transactionTracerNotEnabled.
@Test
public void transactionTracerNotEnabled() throws Exception {
Map<String, Object> configMap = createStagingMap();
Map<String, Object> ttConfigMap = new HashMap<>();
configMap.put("transaction_tracer", ttConfigMap);
ttConfigMap.put("enabled", false);
createServiceManager(configMap);
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a harvest
MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(0, sqlTraces.size());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method notOverExplainThreshold.
@Test
public void notOverExplainThreshold() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis(), TimeUnit.MILLISECONDS);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a harvest
MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(0, sqlTraces.size());
}
Aggregations