use of com.newrelic.agent.MockHarvestService 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.MockHarvestService 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.MockHarvestService 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());
}
use of com.newrelic.agent.MockHarvestService in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method serverConfigChanges.
@Test
public void serverConfigChanges() throws Exception {
Map<String, Object> configMap = createStagingMap();
Map<String, Object> sqlMap = createMap();
sqlMap.put("enabled", true);
configMap.put(AgentConfigImpl.SLOW_SQL, sqlMap);
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(2, sqlTraces.size());
Map<String, Object> serverData = createMap();
Map<String, Object> agentMap = createMap();
serverData.put(AgentConfigFactory.AGENT_CONFIG, agentMap);
agentMap.put(AgentConfigFactory.SLOW_SQL_PREFIX + "enabled", false);
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
connectionConfigListener.connected(mockRPMService, serverData);
// run a transaction
requestDispatcherTracer = startDispatcherTracer();
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.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(0, sqlTraces.size());
serverData = createMap();
agentMap = createMap();
serverData.put(AgentConfigFactory.AGENT_CONFIG, agentMap);
agentMap.put(AgentConfigFactory.SLOW_SQL_PREFIX + "enabled", true);
connectionConfigListener.connected(mockRPMService, serverData);
// run a transaction
requestDispatcherTracer = startDispatcherTracer();
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.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(2, sqlTraces.size());
}
use of com.newrelic.agent.MockHarvestService in project newrelic-java-agent by newrelic.
the class RumStreamParserTest method createServiceManager.
private static void createServiceManager(Map<String, Object> map) throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(map), map);
serviceManager.setConfigService(configService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
serviceManager.setSqlTraceService(sqlTraceService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmServiceManager.setRPMService(rpmService);
configService.start();
serviceManager.setNormalizationService(new NormalizationServiceImpl());
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
statsService.start();
}
Aggregations