Search in sources :

Example 66 with MockRPMService

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

the class RPMConnectionServiceTest method syncStartup.

@Test
public void syncStartup() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put(AgentConfigImpl.APP_NAME, "MyApplication");
    map.put(AgentConfigImpl.SYNC_STARTUP, true);
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(map);
    MockServiceManager serviceManager = (MockServiceManager) ServiceFactory.getServiceManager();
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, map);
    serviceManager.setConfigService(configService);
    CountDownLatch latch = new CountDownLatch(1);
    MockRPMService rpmService = new MockRPMService(latch);
    rpmService.setApplicationName("MyApplication");
    rpmConnectionService.connect(rpmService);
    Assert.assertEquals(0, latch.getCount());
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) CountDownLatch(java.util.concurrent.CountDownLatch) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test) AgentConfigFactoryTest(com.newrelic.agent.config.AgentConfigFactoryTest)

Example 67 with MockRPMService

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

the class RPMConnectionServiceTest method connectImmediate.

@Test
public void connectImmediate() throws Exception {
    ServiceFactory.getEnvironmentService().getEnvironment().setServerPort(null);
    CountDownLatch latch = new CountDownLatch(1);
    MockRPMService rpmService = new MockRPMService(latch);
    rpmConnectionService.setAppServerPortTimeout(RPMConnectionServiceImpl.APP_SERVER_PORT_TIMEOUT);
    rpmConnectionService.setInitialAppServerPortDelay(RPMConnectionServiceImpl.INITIAL_APP_SERVER_PORT_DELAY);
    rpmConnectionService.connectImmediate(rpmService);
    Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test) AgentConfigFactoryTest(com.newrelic.agent.config.AgentConfigFactoryTest)

Example 68 with MockRPMService

use of com.newrelic.agent.MockRPMService 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 69 with MockRPMService

use of com.newrelic.agent.MockRPMService 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 70 with MockRPMService

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

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