Search in sources :

Example 46 with MockServiceManager

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

the class CPUSamplerTest 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) ProfilerService(com.newrelic.agent.profile.ProfilerService)

Example 47 with MockServiceManager

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

the class CustomInsightsEventsConfigUtilsTest method testEnabled.

@Test
public void testEnabled() {
    // setup
    Map<String, Object> root = new HashMap<>();
    Map<String, Object> customEvents = new HashMap<>();
    root.put("custom_insights_events", customEvents);
    customEvents.put(InsightsConfigImpl.MAX_SAMPLES_STORED_PROP, 10);
    MockServiceManager mockServiceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(mockServiceManager);
    mockServiceManager.setConfigService(Mockito.mock(ConfigService.class));
    // start with the default
    AgentConfig config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertTrue(config.getInsightsConfig().isEnabled());
    // high security enabled
    root.put(AgentConfigImpl.HIGH_SECURITY, true);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertFalse(config.getInsightsConfig().isEnabled());
    // high security disabled
    root.put(AgentConfigImpl.HIGH_SECURITY, false);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertTrue(config.getInsightsConfig().isEnabled());
    // no samples
    customEvents.put(InsightsConfigImpl.MAX_SAMPLES_STORED_PROP, 0);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertFalse(config.getInsightsConfig().isEnabled());
    customEvents.put(InsightsConfigImpl.MAX_SAMPLES_STORED_PROP, 10);
    // go through both properties
    customEvents.clear();
    customEvents.put(InsightsConfigImpl.ENABLED_PROP, false);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertFalse(config.getInsightsConfig().isEnabled());
    // Transaction Events feature gate should have no effect.
    customEvents.clear();
    customEvents.put("collect_analytics_events", false);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertTrue(config.getInsightsConfig().isEnabled());
    // Test Custom Events feature gate:
    customEvents.clear();
    customEvents.put("collect_custom_events", false);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertFalse(config.getInsightsConfig().isEnabled());
    // set both
    customEvents.clear();
    customEvents.put(InsightsConfigImpl.ENABLED_PROP, true);
    customEvents.put("collect_custom_events", false);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertFalse(config.getInsightsConfig().isEnabled());
    customEvents.clear();
    customEvents.put(InsightsConfigImpl.ENABLED_PROP, false);
    customEvents.put("collect_custom_events", true);
    config = AgentConfigImpl.createAgentConfig(root);
    Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
    Assert.assertFalse(config.getInsightsConfig().isEnabled());
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 48 with MockServiceManager

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

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

the class InsightsServiceImplTest method testCustomEventFasterHarvest.

@Test
public void testCustomEventFasterHarvest() throws Exception {
    Map<String, Object> config = new HashMap<>();
    config.put(AgentConfigImpl.APP_NAME, EventTestHelper.APP_NAME);
    EventTestHelper.createServiceManager(config);
    String appName = ServiceFactory.getRPMService().getApplicationName();
    InsightsServiceImpl insightsService = new InsightsServiceImpl();
    ((MockServiceManager) ServiceFactory.getServiceManager()).setInsights(insightsService);
    ServiceManager serviceManager = spy(ServiceFactory.getServiceManager());
    ServiceFactory.setServiceManager(serviceManager);
    HarvestServiceImpl harvestService = spy(new HarvestServiceImpl());
    doReturn(harvestService).when(serviceManager).getHarvestService();
    doReturn(0L).when(harvestService).getInitialDelay();
    insightsService.addHarvestableToService(appName);
    insightsService.configureHarvestables(60, 10);
    assertEquals(10, insightsService.getMaxSamplesStored());
    insightsService.start();
    Map<String, Object> connectionInfo = new HashMap<>();
    Map<String, Object> eventHarvest = new HashMap<>();
    Map<String, Object> harvestLimits = new HashMap<>();
    // 5 is the lowest allowable value
    eventHarvest.put("report_period_ms", 5000L);
    eventHarvest.put("harvest_limits", harvestLimits);
    harvestLimits.put("custom_event_data", 1L);
    connectionInfo.put("event_harvest_config", eventHarvest);
    harvestService.startHarvestables(ServiceFactory.getRPMService(), AgentConfigImpl.createAgentConfig(connectionInfo));
    Thread.sleep(500);
    Map<String, String> m = Collections.singletonMap("key", "value");
    insightsService.recordCustomEvent("CustomEvent", m);
    Thread.sleep(5050);
    checkForEvent();
    ((MockRPMService) ServiceFactory.getRPMService()).clearEvents();
    insightsService.recordCustomEvent("CustomEvent", m);
    Thread.sleep(5050);
    checkForEvent();
}
Also used : HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) RPMServiceManager(com.newrelic.agent.RPMServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) HarvestServiceImpl(com.newrelic.agent.HarvestServiceImpl) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 50 with MockServiceManager

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

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