Search in sources :

Example 16 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method testErrorEventFasterHarvest.

@Test
public void testErrorEventFasterHarvest() throws Exception {
    String appName = ServiceFactory.getRPMService().getApplicationName();
    ServiceManager serviceManager = spy(ServiceFactory.getServiceManager());
    ServiceFactory.setServiceManager(serviceManager);
    HarvestServiceImpl harvestService = spy(new HarvestServiceImpl());
    doReturn(harvestService).when(serviceManager).getHarvestService();
    doReturn(0L).when(harvestService).getInitialDelay();
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    errorService.addHarvestableToService();
    errorService.harvestable.configure(60, 10);
    Assert.assertEquals(10, errorService.getMaxSamplesStored());
    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("error_event_data", 100L);
    connectionInfo.put("event_harvest_config", eventHarvest);
    harvestService.startHarvestables(ServiceFactory.getRPMService(), AgentConfigImpl.createAgentConfig(connectionInfo));
    Thread.sleep(500);
    TracedError error = ThrowableError.builder(ServiceFactory.getConfigService().getErrorCollectorConfig(appName), appName, "metricName", new Throwable(), 100).requestUri("requestUri").errorAttributes(Collections.singletonMap("test_attribute", "value")).build();
    ServiceFactory.getRPMService().getErrorService().reportError(error);
    Thread.sleep(5050);
    checkForEvent();
    ((MockRPMService) ServiceFactory.getRPMService()).clearEvents();
    ServiceFactory.getRPMService().getErrorService().reportError(error);
    Thread.sleep(5050);
    checkForEvent();
}
Also used : HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) HarvestServiceImpl(com.newrelic.agent.HarvestServiceImpl) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 17 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class CircuitBreakerApiTest method tripCircuitBreaker.

private void tripCircuitBreaker() {
    try {
        ApiTestHelper.mockOutServiceManager();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ServiceManager mockServiceManager = ServiceFactory.getServiceManager();
    CircuitBreakerService circuitBreakerService = spy(mockServiceManager.getCircuitBreakerService());
    Mockito.doReturn(true).when(circuitBreakerService).isTripped();
    Mockito.doReturn(true).when(circuitBreakerService).checkAndTrip();
    Mockito.doReturn(circuitBreakerService).when(mockServiceManager).getCircuitBreakerService();
}
Also used : ServiceManager(com.newrelic.agent.service.ServiceManager) CircuitBreakerService(com.newrelic.agent.circuitbreaker.CircuitBreakerService) URISyntaxException(java.net.URISyntaxException)

Example 18 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class LaspHighSecurityTest method laspAndHsmEnabled.

@Test
public void laspAndHsmEnabled() throws ConfigurationException {
    Map<String, Object> settings = createSecurityProps();
    ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
    ServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    AgentConfig agentConfig = AgentConfigFactory.createAgentConfig(settings, null, null);
    assertTrue(agentConfig.laspEnabled());
    assertTrue(agentConfig.isHighSecurity());
    try {
        ConfigServiceFactory.validateConfig(agentConfig);
        fail();
    } catch (ForceDisconnectException ex) {
    }
}
Also used : ForceDisconnectException(com.newrelic.agent.ForceDisconnectException) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 19 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method testLitemode.

@Test
public void testLitemode() {
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(ImmutableMap.<String, Object>of("lite_mode", true, "app_name", "Unit Test"));
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
    ServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    ClassTransformerConfig classTransformerConfig = serviceManager.getConfigService().getDefaultAgentConfig().getClassTransformerConfig();
    assertFalse(classTransformerConfig.isDefaultInstrumentationEnabled());
    assertFalse(classTransformerConfig.isBuiltinExtensionEnabled());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 20 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method testPointcutEnabled.

@Test
public void testPointcutEnabled() {
    Map<String, Object> classTransformerMap = new HashMap<>();
    ClassTransformerConfig config = ClassTransformerConfigImpl.createClassTransformerConfig(classTransformerMap, true, false);
    Map<String, Object> configSettings = new HashMap<>();
    configSettings.put(AgentConfigImpl.CLASS_TRANSFORMER, classTransformerMap);
    configSettings.put(AgentConfigImpl.APP_NAME, "Unit Test");
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configSettings);
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
    ServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    PointCutConfiguration pointCutConfiguration = new PointCutConfiguration("name", null, true, config);
    assertTrue(pointCutConfiguration.isEnabled());
}
Also used : HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) PointCutConfiguration(com.newrelic.agent.instrumentation.PointCutConfiguration) Test(org.junit.Test)

Aggregations

ServiceManager (com.newrelic.agent.service.ServiceManager)31 MockServiceManager (com.newrelic.agent.MockServiceManager)18 Test (org.junit.Test)17 HashMap (java.util.HashMap)12 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)5 ConfigService (com.newrelic.agent.config.ConfigService)5 MockRPMService (com.newrelic.agent.MockRPMService)4 AgentConfig (com.newrelic.agent.config.AgentConfig)4 PointCutConfiguration (com.newrelic.agent.instrumentation.PointCutConfiguration)4 SpringPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut)4 HarvestServiceImpl (com.newrelic.agent.HarvestServiceImpl)3 RPMServiceManager (com.newrelic.agent.RPMServiceManager)3 ServiceManagerImpl (com.newrelic.agent.service.ServiceManagerImpl)2 JSONObject (org.json.simple.JSONObject)2 After (org.junit.After)2 ForceDisconnectException (com.newrelic.agent.ForceDisconnectException)1 IRPMService (com.newrelic.agent.IRPMService)1 RPMService (com.newrelic.agent.RPMService)1 Transaction (com.newrelic.agent.Transaction)1 BrowserServiceImpl (com.newrelic.agent.browser.BrowserServiceImpl)1