use of com.newrelic.agent.MockCoreService 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());
}
use of com.newrelic.agent.MockCoreService in project newrelic-java-agent by newrelic.
the class CommandParserTest method testDisallowedPingCommand.
@Test
public void testDisallowedPingCommand() throws Exception {
createServiceManager(ImmutableMap.<String, Object>of("command_parser", ImmutableMap.of("disallow", PingCommand.COMMAND_NAME)));
agentControl = new MockCoreService();
commandParser = new CommandParser();
commandParser.doStart();
commandParser.addCommands(new ShutdownCommand(agentControl), new RestartCommand());
MockRPMService rpmService = new MockRPMService();
for (int i = 0; i < 5; i++) {
List<List<?>> commands = new ArrayList<>();
commands.add(createCommand(1, PingCommand.COMMAND_NAME));
Map<Long, Object> commandResult = commandParser.processCommands(rpmService, commands);
Assert.assertEquals(0, commandResult.size());
}
}
use of com.newrelic.agent.MockCoreService in project newrelic-java-agent by newrelic.
the class CommandParserTest method testDisallowedShutdownCommand.
@Test
public void testDisallowedShutdownCommand() throws Exception {
createServiceManager(ImmutableMap.<String, Object>of("command_parser", ImmutableMap.of("disallow", "shutdown")));
agentControl = new MockCoreService();
commandParser = new CommandParser();
commandParser.doStart();
commandParser.addCommands(new ShutdownCommand(agentControl), new RestartCommand());
MockRPMService rpmService = new MockRPMService();
for (int i = 0; i < 5; i++) {
List<List<?>> commands = new ArrayList<>();
commands.add(createCommand(1, ShutdownCommand.COMMAND_NAME));
commandParser.processCommands(rpmService, commands);
}
Assert.assertEquals(0, rpmService.getRestartCount());
Assert.assertEquals(5, agentControl.getShutdownCount());
}
use of com.newrelic.agent.MockCoreService in project newrelic-java-agent by newrelic.
the class CommandTest method restart.
@Test
public void restart() throws Exception {
MockRPMService rpmService = new MockRPMService() {
@Override
public void reconnect() {
throw new RuntimeException("restart");
}
};
MockCoreService executor = new MockCoreService();
Assert.assertEquals(Collections.EMPTY_MAP, new ShutdownCommand(executor).process(rpmService, Collections.EMPTY_MAP));
try {
new RestartCommand().process(rpmService, Collections.EMPTY_MAP);
Assert.fail();
} catch (Exception e) {
Assert.assertEquals("restart", e.getMessage());
}
}
use of com.newrelic.agent.MockCoreService 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