Search in sources :

Example 91 with MockServiceManager

use of com.newrelic.agent.MockServiceManager 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 92 with MockServiceManager

use of com.newrelic.agent.MockServiceManager 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 93 with MockServiceManager

use of com.newrelic.agent.MockServiceManager 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)

Example 94 with MockServiceManager

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

the class ProfilerServiceTest method createServiceManager.

private MockServiceManager createServiceManager(Map<String, Object> map) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(map), map);
    serviceManager.setConfigService(configService);
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    ProfilerService profilerService = new ProfilerService();
    serviceManager.setProfilerService(profilerService);
    return serviceManager;
}
Also used : ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) TransactionService(com.newrelic.agent.TransactionService) MockServiceManager(com.newrelic.agent.MockServiceManager)

Example 95 with MockServiceManager

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

the class ProfilerServiceTest method testAgentInstrumentationSample.

@Test
public void testAgentInstrumentationSample() 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, true, 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.assertTrue(profileTree.getRootSegments().size() > 0);
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

MockServiceManager (com.newrelic.agent.MockServiceManager)127 ConfigService (com.newrelic.agent.config.ConfigService)61 Test (org.junit.Test)49 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)48 HashMap (java.util.HashMap)44 TransactionService (com.newrelic.agent.TransactionService)42 MockRPMService (com.newrelic.agent.MockRPMService)37 ThreadService (com.newrelic.agent.ThreadService)34 AgentConfig (com.newrelic.agent.config.AgentConfig)34 AttributesService (com.newrelic.agent.attributes.AttributesService)28 HarvestService (com.newrelic.agent.HarvestService)27 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)27 MockHarvestService (com.newrelic.agent.MockHarvestService)26 MockCoreService (com.newrelic.agent.MockCoreService)21 StatsService (com.newrelic.agent.stats.StatsService)21 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)21 Before (org.junit.Before)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)16 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)16 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)15