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();
}
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();
}
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) {
}
}
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());
}
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());
}
Aggregations