Search in sources :

Example 1 with MockRPMService

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();
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl)

Example 2 with MockRPMService

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"));
    }
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) TracedError(com.newrelic.agent.errors.TracedError) StringWriter(java.io.StringWriter) JSONObject(org.json.simple.JSONObject) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) MockRPMService(com.newrelic.agent.MockRPMService) Writer(java.io.Writer) StringWriter(java.io.StringWriter)

Example 3 with MockRPMService

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());
}
Also used : SqlTrace(com.newrelic.agent.sql.SqlTrace) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockRPMService(com.newrelic.agent.MockRPMService)

Example 4 with MockRPMService

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();
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 5 with MockRPMService

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

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