use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method createServiceManager.
private void createServiceManager(Map<String, Object> configMap) throws Exception {
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(configMap);
MockServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
serviceManager.setHarvestService(new MockHarvestService());
serviceManager.setSqlTraceService(new SqlTraceServiceImpl());
serviceManager.setAttributesService(new AttributesService());
serviceManager.setNormalizationService(new NormalizationServiceImpl());
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(serviceManager.getConfigService().getDefaultAgentConfig().getApplicationName());
rpmService.setEverConnected(true);
rpmService.setIsConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(serviceManager.getConfigService().getDefaultAgentConfig().getApplicationName()));
rpmServiceManager.setRPMService(rpmService);
serviceManager.start();
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method runTracedErrorTest.
public void runTracedErrorTest(RequestUriConfigTransactionTest test) throws Exception {
setupConfig(test);
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer(test.getTxnName());
DefaultTracer defaultTracer = startTracer();
NewRelicApiImplementation.initialize();
AgentBridge.publicApi.noticeError("error");
defaultTracer.finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
MockRPMService mockRPMService = runHarvest();
// verify results
List<TracedError> errorTraces = mockRPMService.getErrorService().getAndClearTracedErrors();
assertFalse(errorTraces.isEmpty());
for (TracedError trace : errorTraces) {
Writer writer = new StringWriter();
trace.writeJSONString(writer);
JSONParser parser = new JSONParser();
JSONArray parsedError = (JSONArray) parser.parse(writer.toString());
matchUri(test.getExpectedUriValues(), (String) ((JSONObject) parsedError.get(4)).get("request_uri"));
}
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method runSqlTest.
public void runSqlTest(RequestUriConfigSqlTest test) throws Exception {
setupConfig(test);
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer(test.getTxnName());
long duration = 501000000;
startSqlTracer(test.sql, duration).finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
MockRPMService mockRPMService = runHarvest();
// verify results
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
matchUri(test.getExpectedUriValues(), sqlTraces.get(0).getUri());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method setupManager.
public void setupManager(boolean captureParams, boolean setSslForHttpToTrue) {
MockServiceManager manager = new MockServiceManager();
ServiceFactory.setServiceManager(manager);
Map<String, Object> params = new HashMap<>();
if (captureParams || setSslForHttpToTrue) {
Map<String, Object> bProps = new HashMap<>();
params.put("browser_monitoring", bProps);
if (captureParams) {
Map<String, Object> baProps = new HashMap<>();
bProps.put("attributes", baProps);
baProps.put("enabled", Boolean.TRUE);
}
if (setSslForHttpToTrue) {
bProps.put("ssl_for_http", Boolean.TRUE);
}
}
params.put("license_key", LICENSE_KEY);
ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
params.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(params));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
MockRPMServiceManager rpmServiceMgr = new MockRPMServiceManager();
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setEverConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmServiceMgr.setRPMService(rpmService);
manager.setRPMServiceManager(rpmServiceMgr);
AttributesService attService = new AttributesService();
manager.setAttributesService(attService);
ServiceFactory.setServiceManager(manager);
Transaction.clearTransaction();
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class CommandParserTest method testUpdateDisallowedRestartCommand.
@Test
public void testUpdateDisallowedRestartCommand() throws Exception {
// First test without the disallow
MockRPMService rpmService = new MockRPMService();
for (int i = 0; i < 5; i++) {
List<List<?>> commands = new ArrayList<>();
commands.add(createCommand(1, RestartCommand.COMMAND_NAME));
commandParser.processCommands(rpmService, commands);
}
Assert.assertEquals(5, rpmService.getRestartCount());
Assert.assertEquals(0, agentControl.getShutdownCount());
// Second test with the disallow list (multiple values)
agentControl = new MockCoreService();
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(ImmutableMap.<String, Object>of("command_parser", ImmutableMap.of("disallow", "other_command, restart,some_other_command")));
commandParser.configChanged(null, agentConfig);
rpmService = new MockRPMService();
for (int i = 0; i < 5; i++) {
List<List<?>> commands = new ArrayList<>();
commands.add(createCommand(1, RestartCommand.COMMAND_NAME));
commandParser.processCommands(rpmService, commands);
}
Assert.assertEquals(5, rpmService.getRestartCount());
Assert.assertEquals(0, agentControl.getShutdownCount());
}
Aggregations