Search in sources :

Example 31 with MockRPMServiceManager

use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.

the class ConfigServiceTest method badServerData.

@Test
public void badServerData() throws Exception {
    Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
    createServiceManager(configMap);
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    Map<String, Object> data = new HashMap<>();
    Map<String, Object> agentData = new HashMap<>();
    data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
    data.put(AgentConfigImpl.APDEX_T, 0.5d);
    data.put(AgentConfigFactory.COLLECT_TRACES, true);
    agentData.put(AgentConfigFactory.TRANSACTION_TRACER_PREFIX + TransactionTracerConfigImpl.ENABLED, "bad");
    agentData.put(AgentConfigFactory.ERROR_COLLECTOR_PREFIX + ErrorCollectorConfigImpl.ENABLED, !ErrorCollectorConfigImpl.DEFAULT_ENABLED);
    connectionConfigListener.connected(rpmService, data);
    ConfigService configService = ServiceFactory.getConfigService();
    assertFalse(configService.getAgentConfig(null).getTransactionTracerConfig().isEnabled());
    assertEquals(ErrorCollectorConfigImpl.DEFAULT_ENABLED, configService.getAgentConfig(null).getErrorCollectorConfig().isEnabled());
}
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)

Example 32 with MockRPMServiceManager

use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.

the class TransactionNamingTest method setUrlRules.

private String setUrlRules(JSONArray urlRules) {
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    List<ConnectionListener> connectionListeners = rpmServiceManager.getConnectionListeners();
    ConnectionListener connectionListener = connectionListeners.get(0);
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    String appName = rpmService.getApplicationName();
    Map<String, Object> data = new HashMap<>();
    data.put(NormalizationRuleConfig.URL_RULES_KEY, urlRules);
    connectionListener.connected(rpmService, AgentConfigImpl.createAgentConfig(data));
    return appName;
}
Also used : HashMap(java.util.HashMap) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) JSONObject(org.json.simple.JSONObject) ConnectionListener(com.newrelic.agent.ConnectionListener) MockRPMService(com.newrelic.agent.MockRPMService)

Example 33 with MockRPMServiceManager

use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.

the class ProfileSessionTest method singleSample.

@Test
public void singleSample() throws Exception {
    Map<String, Object> config = ProfilerServiceTest.createAgentConfig(true);
    MockServiceManager serviceManager = createServiceManager(config);
    MockRPMService rpmService = new MockRPMService();
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    ProfilerService profilerService = serviceManager.getProfilerService();
    ProfilerParameters parameters = new ProfilerParameters(5L, 100L, 100L, false, false, false, null, null);
    ProfileSession session = new ProfileSession(profilerService, parameters);
    session.start();
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertTrue(session.isDone());
    Assert.assertNotNull(session.getProfile());
    Assert.assertEquals(1, session.getProfile().getSampleCount());
    Assert.assertEquals(parameters.getProfileId(), session.getProfileId());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(1, rpmService.getProfiles().size());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 34 with MockRPMServiceManager

use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.

the class ProfileSessionTest method stopSessionNoReport.

@Test
public void stopSessionNoReport() throws Exception {
    Map<String, Object> config = ProfilerServiceTest.createAgentConfig(true);
    MockServiceManager serviceManager = createServiceManager(config);
    MockRPMService rpmService = new MockRPMService();
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    ProfilerService profilerService = serviceManager.getProfilerService();
    ProfilerParameters parameters = new ProfilerParameters(5L, 100L, 300000L, false, false, false, null, null);
    ProfileSession session = new ProfileSession(profilerService, parameters);
    session.start();
    Thread.sleep(1000);
    session.stop(false);
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertTrue(session.isDone());
    Assert.assertNotNull(session.getProfile());
    Assert.assertTrue(session.getProfile().getSampleCount() > 1);
    Assert.assertEquals(parameters.getProfileId(), session.getProfileId());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertTrue(rpmService.getProfiles().isEmpty());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 35 with MockRPMServiceManager

use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.

the class ProfilerServiceTest method stopProfilerAndReportData.

@Test
public void stopProfilerAndReportData() throws Exception {
    MockServiceManager serviceManager = createServiceManager(createAgentConfig(true));
    MockRPMService rpmService = new MockRPMService();
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    long profileId = 5;
    ProfilerParameters parameters = new ProfilerParameters(profileId, 100L, 200000L, false, false, false, null, null);
    ProfilerService profilerService = serviceManager.getProfilerService();
    profilerService.startProfiler(parameters);
    Thread.sleep(1000);
    profilerService.stopProfiler(profileId, true);
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(1, rpmService.getProfiles().size());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)57 MockServiceManager (com.newrelic.agent.MockServiceManager)46 MockRPMService (com.newrelic.agent.MockRPMService)44 TransactionService (com.newrelic.agent.TransactionService)31 ConfigService (com.newrelic.agent.config.ConfigService)29 MockHarvestService (com.newrelic.agent.MockHarvestService)25 HarvestService (com.newrelic.agent.HarvestService)24 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)24 ThreadService (com.newrelic.agent.ThreadService)23 AttributesService (com.newrelic.agent.attributes.AttributesService)22 MockCoreService (com.newrelic.agent.MockCoreService)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)16 HashMap (java.util.HashMap)16 Test (org.junit.Test)16 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)15 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)15 AgentConfig (com.newrelic.agent.config.AgentConfig)14 StatsService (com.newrelic.agent.stats.StatsService)14 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)9