Search in sources :

Example 86 with MockServiceManager

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());
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) DeadlockDetectorService(com.newrelic.agent.deadlock.DeadlockDetectorService) Test(org.junit.Test)

Example 87 with MockServiceManager

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));
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) Field(java.lang.reflect.Field) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) DeadlockDetectorService(com.newrelic.agent.deadlock.DeadlockDetectorService) Test(org.junit.Test)

Example 88 with MockServiceManager

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());
}
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 89 with MockServiceManager

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();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) Returns(org.mockito.internal.stubbing.answers.Returns) ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) MockServiceManager(com.newrelic.agent.MockServiceManager) Environment(com.newrelic.agent.environment.Environment) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) BeforeClass(org.junit.BeforeClass)

Example 90 with MockServiceManager

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);
}
Also used : ThreadService(com.newrelic.agent.ThreadService) AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) BeforeClass(org.junit.BeforeClass)

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