use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class DeadlockServiceTest method testServiceEnabledByDefault.
@Test
public void testServiceEnabledByDefault() {
MockServiceManager mockServiceManager = new MockServiceManager();
ServiceFactory.setServiceManager(mockServiceManager);
mockServiceManager.setConfigService(Mockito.mock(ConfigService.class));
Map<String, Object> root = new HashMap<>();
AgentConfig config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
DeadlockDetectorService dds = new DeadlockDetectorService();
Assert.assertTrue(dds.isEnabled());
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class DeadlockServiceTest method testServiceDisabled.
@Test
public void testServiceDisabled() throws Exception {
MockServiceManager mockServiceManager = new MockServiceManager();
ServiceFactory.setServiceManager(mockServiceManager);
mockServiceManager.setConfigService(Mockito.mock(ConfigService.class));
Map<String, Object> root = new HashMap<>();
Map<String, Object> deadlockDetector = new HashMap<>();
deadlockDetector.put("enabled", false);
root.put("deadlock_detector", deadlockDetector);
AgentConfig config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
DeadlockDetectorService dds = new DeadlockDetectorService();
Assert.assertFalse(dds.isEnabled());
// Check that when the service is disabled, we don't allocate internal state
Class<?> ddsClass = dds.getClass();
Field scheduledExecutorField = ddsClass.getDeclaredField("scheduledExecutor");
scheduledExecutorField.setAccessible(true);
Assert.assertNull(scheduledExecutorField.get(dds));
Field deadlockTaskField = ddsClass.getDeclaredField("deadlockTask");
deadlockTaskField.setAccessible(true);
Assert.assertNull(deadlockTaskField.get(dds));
}
use of com.newrelic.agent.MockServiceManager 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());
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class RPMConnectionServiceTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
AgentHelper.initializeConfig();
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
Environment env = new Environment(config, "c:\\test\\log");
EnvironmentService envService = Mockito.mock(EnvironmentService.class, new Returns(env));
serviceManager.setEnvironmentService(envService);
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
serviceManager.setConfigService(configService);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
rpmConnectionService = new TestRPMConnectionService();
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class KeyTransactionProfileTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
Map<String, Object> map = new HashMap<>();
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(map);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, map);
serviceManager.setConfigService(configService);
}
Aggregations