Search in sources :

Example 66 with MockServiceManager

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

the class UtilizationServiceTest method before.

@Before
public void before() {
    MockServiceManager mockServiceManager = new MockServiceManager();
    config = mock(AgentConfig.class);
    MockConfigService configService = new MockConfigService(null);
    configService.setAgentConfig(config);
    ServiceFactory.setServiceManager(mockServiceManager);
    mockServiceManager.setConfigService(configService);
    ThreadService mockThreadService = mock(ThreadService.class);
    mockServiceManager.setThreadService(mockThreadService);
    // Do not make AWS/Azure/GCP/PCF calls. Unit tests should work even without internet connection :)
    when(config.getValue(UtilizationService.DETECT_DOCKER_KEY, true)).thenReturn(false);
    when(config.getValue(UtilizationService.DETECT_AWS_KEY, true)).thenReturn(false);
    when(config.getValue(UtilizationService.DETECT_AZURE_KEY, true)).thenReturn(false);
    when(config.getValue(UtilizationService.DETECT_GOOGLE_CLOUD_PROVIDER_KEY, true)).thenReturn(false);
    when(config.getValue(UtilizationService.DETECT_PIVOTAL_CLOUD_FOUNDRY_KEY, true)).thenReturn(false);
    when(config.getValue(UtilizationService.DETECT_KUBERNETES_KEY, true)).thenReturn(false);
    UtilizationDataConfig utilDataConfig = mock(UtilizationDataConfig.class);
    when(config.getUtilizationDataConfig()).thenReturn(utilDataConfig);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ThreadService(com.newrelic.agent.ThreadService) MockServiceManager(com.newrelic.agent.MockServiceManager) MockConfigService(com.newrelic.agent.MockConfigService) UtilizationDataConfig(com.newrelic.agent.config.UtilizationDataConfig) Before(org.junit.Before)

Example 67 with MockServiceManager

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

the class NewRelicApiImplementationTest method mockOutServices.

private void mockOutServices() {
    errorService = Mockito.mock(ErrorService.class);
    IRPMService rpmService = Mockito.mock(IRPMService.class);
    Mockito.when(rpmService.getErrorService()).thenReturn(errorService);
    RPMServiceManager rpmServiceManager = Mockito.mock(RPMServiceManager.class);
    Mockito.when(rpmServiceManager.getRPMService()).thenReturn(rpmService);
    MockServiceManager sm = new MockServiceManager();
    sm.setRPMServiceManager(rpmServiceManager);
    ServiceFactory.setServiceManager(sm);
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) MockServiceManager(com.newrelic.agent.MockServiceManager) IRPMService(com.newrelic.agent.IRPMService) RPMServiceManager(com.newrelic.agent.RPMServiceManager)

Example 68 with MockServiceManager

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

the class CloudUtilityTest method before.

@Before
public void before() {
    MockServiceManager mockServiceManager = new MockServiceManager();
    mockServiceManager.setSamplerService(mock(SamplerService.class));
    mockStatsService = mock(StatsService.class);
    mockServiceManager.setStatsService(mockStatsService);
}
Also used : SamplerService(com.newrelic.agent.samplers.SamplerService) StatsService(com.newrelic.agent.stats.StatsService) MockServiceManager(com.newrelic.agent.MockServiceManager) Before(org.junit.Before)

Example 69 with MockServiceManager

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

the class DockerDataTest method testNoDockerError.

@Test
public void testNoDockerError() throws Exception {
    MockCoreService.getMockAgentAndBootstrapTheServiceManager();
    MockServiceManager mockServiceManager = new MockServiceManager();
    StatsService spy = Mockito.spy(new StatsServiceImpl());
    mockServiceManager.setStatsService(spy);
    ServiceFactory.setServiceManager(mockServiceManager);
    String validDockerID = "47cbd16b77c50cbf71401c069cd2189f0e659af17d5a2daca3bddf59d8a870b2";
    StringReader reader = new StringReader("2:cpu:/docker/" + validDockerID);
    Assert.assertEquals(validDockerID, dockerData.readFile(reader));
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 70 with MockServiceManager

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

the class UtilizationCrossAgentTests method setConfig.

/*
     * Create a mock service manager with a config service with the given utilization values
     */
private static void setConfig(String billingHostname, Long totalRam, Integer logicalProcessors) {
    Map<String, Object> config = new HashMap<>();
    Map<String, Object> values = new HashMap<>();
    values.put("billing_hostname", billingHostname);
    values.put("total_ram_mib", totalRam);
    values.put("logical_processors", logicalProcessors);
    config.put(UtilizationDataConfig.PROPERTY_NAME, values);
    config.put("app_name", "CATs");
    ConfigService configService = new MockConfigService(AgentConfigImpl.createAgentConfig(config));
    MockServiceManager mockServiceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(mockServiceManager);
}
Also used : MockConfigService(com.newrelic.agent.MockConfigService) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) JSONObject(org.json.simple.JSONObject) MockConfigService(com.newrelic.agent.MockConfigService)

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