Search in sources :

Example 1 with MockCoreService

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

Example 2 with MockCoreService

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());
    }
}
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 3 with MockCoreService

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());
}
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 4 with MockCoreService

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

Example 5 with MockCoreService

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();
}
Also used : SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ThreadService(com.newrelic.agent.ThreadService) SqlTraceService(com.newrelic.agent.sql.SqlTraceService) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockCoreService(com.newrelic.agent.MockCoreService) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMService(com.newrelic.agent.MockRPMService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl)

Aggregations

MockCoreService (com.newrelic.agent.MockCoreService)29 MockServiceManager (com.newrelic.agent.MockServiceManager)21 MockRPMService (com.newrelic.agent.MockRPMService)20 ConfigService (com.newrelic.agent.config.ConfigService)20 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)19 TransactionService (com.newrelic.agent.TransactionService)19 ThreadService (com.newrelic.agent.ThreadService)17 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)17 HarvestService (com.newrelic.agent.HarvestService)15 MockHarvestService (com.newrelic.agent.MockHarvestService)15 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)13 AttributesService (com.newrelic.agent.attributes.AttributesService)12 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)12 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)12 StatsService (com.newrelic.agent.stats.StatsService)12 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)12 AgentConfig (com.newrelic.agent.config.AgentConfig)9 NormalizationServiceImpl (com.newrelic.agent.normalization.NormalizationServiceImpl)6 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)6 Test (org.junit.Test)6