Search in sources :

Example 6 with MockRPMService

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());
    }
}
Also used : MockCoreService(com.newrelic.agent.MockCoreService) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 7 with MockRPMService

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());
}
Also used : MockCoreService(com.newrelic.agent.MockCoreService) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 8 with MockRPMService

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;
}
Also used : JSONParser(org.json.simple.parser.JSONParser) List(java.util.List) StartProfilerCommand(com.newrelic.agent.profile.StartProfilerCommand) MockRPMService(com.newrelic.agent.MockRPMService)

Example 9 with MockRPMService

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());
    }
}
Also used : MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 10 with MockRPMService

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());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) JSONObject(org.json.simple.JSONObject) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

MockRPMService (com.newrelic.agent.MockRPMService)97 Test (org.junit.Test)59 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)44 MockServiceManager (com.newrelic.agent.MockServiceManager)39 MockHarvestService (com.newrelic.agent.MockHarvestService)30 HashMap (java.util.HashMap)28 TransactionService (com.newrelic.agent.TransactionService)26 ConfigService (com.newrelic.agent.config.ConfigService)21 MockCoreService (com.newrelic.agent.MockCoreService)20 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)18 HarvestService (com.newrelic.agent.HarvestService)17 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 ThreadService (com.newrelic.agent.ThreadService)15 StatsService (com.newrelic.agent.stats.StatsService)15 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)15 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)15 SqlTracer (com.newrelic.agent.tracers.SqlTracer)15 Tracer (com.newrelic.agent.tracers.Tracer)15 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)15 TransactionData (com.newrelic.agent.TransactionData)14