use of com.newrelic.agent.MockRPMService 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.MockRPMService 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.MockRPMService in project newrelic-java-agent by newrelic.
the class CommandParserThreadProfilerTest method processThreadProfilerCommand.
private Map<Long, Object> processThreadProfilerCommand(String threadProfilerGetCommand) throws Exception {
JSONParser parser = new JSONParser();
Object parsedTPAgentCommand = parser.parse(threadProfilerGetCommand);
Map<?, ?> tpAgentCommandMap = Map.class.cast(parsedTPAgentCommand);
List<List<?>> threadProfilerCommands = (List<List<?>>) tpAgentCommandMap.get("return_value");
commandParser.addCommands(new StartProfilerCommand(profilerService));
MockRPMService rpmService = new MockRPMService();
Map<Long, Object> result = commandParser.processCommands(rpmService, threadProfilerCommands);
return result;
}
use of com.newrelic.agent.MockRPMService 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.MockRPMService in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method connectionListenerAndErrorEvents.
@Test
public void connectionListenerAndErrorEvents() throws Exception {
Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
createServiceManager(configMap);
ConfigService configService = ServiceFactory.getConfigService();
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
// test defaults
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
String appName = rpmService.getApplicationName();
String appName2 = "bogus";
Map<String, Object> data = new HashMap<>();
Map<String, Object> agentData = new HashMap<>();
data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
assertEquals(100, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
// test collector shut off
data.put(ErrorCollectorConfigImpl.COLLECT_EVENTS, false);
connectionConfigListener.connected(rpmService, data);
assertFalse(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
assertEquals(100, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
// test config shut off and max event count
rpmService = new MockRPMService();
rpmService.setApplicationName(appName2);
agentData.put(AgentConfigFactory.CAPTURE_ERROR_EVENTS, false);
agentData.put(AgentConfigFactory.MAX_ERROR_EVENT_SAMPLES_STORED, 20);
connectionConfigListener.connected(rpmService, data);
assertFalse(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
assertFalse(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
assertEquals(20, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
}
Aggregations