Search in sources :

Example 21 with MockRPMServiceManager

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

the class ProfilerServiceTest method testOneSampleProfile.

@Test
public void testOneSampleProfile() 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);
    ProfilerParameters parameters = new ProfilerParameters(5L, 500L, 500L, false, false, false, null, null);
    ProfilerService profilerService = serviceManager.getProfilerService();
    profilerService.startProfiler(parameters);
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(1, rpmService.getProfiles().size());
    ProfileTree profileTree = rpmService.getProfiles().get(0).getProfileTree(ThreadType.BasicThreadType.AGENT_INSTRUMENTATION);
    Assert.assertEquals(0, profileTree.getRootSegments().size());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 22 with MockRPMServiceManager

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

the class ProfilerServiceTest method stopProfiler.

@Test
public void stopProfiler() 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, false);
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(0, 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 23 with MockRPMServiceManager

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

the class EventTestHelper method createServiceManager.

public static void createServiceManager(Map<String, Object> config) throws Exception {
    if (APP_NAME == null || APP_NAME.isEmpty()) {
        APP_NAME = "Unit Test";
    }
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), config);
    serviceManager.setConfigService(configService);
    StatsService statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    TransactionService txService = new TransactionService();
    serviceManager.setTransactionService(txService);
    TransactionTraceService ttService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(ttService);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmServiceManager.setRPMService(rpmService);
    ErrorServiceImpl errorService = new ErrorServiceImpl(APP_NAME);
    rpmService.setErrorService(errorService);
    AttributesService attService = new AttributesService();
    serviceManager.setAttributesService(attService);
    serviceManager.setDistributedTraceService(new DistributedTraceServiceImpl());
    serviceManager.setRPMServiceManager(rpmServiceManager);
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 24 with MockRPMServiceManager

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

the class MetricNormalizerTest method setUrlRules.

private String setUrlRules(JSONArray rules) {
    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, rules);
    // add a bogus segment term rule to make sure that has no side-effect of breaking stuff
    data.put("transaction_segment_terms", Arrays.asList(ImmutableMap.of("prefix", "This/Wont/Match/Anything", "terms", Arrays.asList("of", "endearment"))));
    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 25 with MockRPMServiceManager

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

the class SpringPointCutTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
    AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
    MockConfigService configService = new MockConfigService(null);
    configService.setAgentConfig(config);
    serviceManager.setConfigService(configService);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    serviceManager.setNormalizationService(new NormalizationServiceImpl());
}
Also used : ThreadService(com.newrelic.agent.ThreadService) AgentConfig(com.newrelic.agent.config.AgentConfig) MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockConfigService(com.newrelic.agent.MockConfigService) MockRPMService(com.newrelic.agent.MockRPMService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl) BeforeClass(org.junit.BeforeClass)

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