use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class JarCollectorServiceImplTest method before.
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
RPMServiceManager rpmServiceManager = mock(RPMServiceManager.class);
when(rpmServiceManager.getOrCreateRPMService(anyString())).thenReturn(rpmService);
ServiceManager mockServiceManager = mock(ServiceManager.class);
when(mockServiceManager.getRPMServiceManager()).thenReturn(rpmServiceManager);
ServiceFactory.setServiceManager(mockServiceManager);
}
use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class InstrumentationTransactionTest method testExceptionInTransactionInitialization.
@Test
public void testExceptionInTransactionInitialization() {
ServiceManager serviceManager = Mockito.spy(ServiceFactory.getServiceManager());
InsightsService insightsService = Mockito.spy(serviceManager.getInsights());
Mockito.when(serviceManager.getInsights()).thenReturn(insightsService);
// Force throw an exception in the Transaction constructor
Mockito.doThrow(new RuntimeException()).when(insightsService).getTransactionInsights(Mockito.any(AgentConfig.class));
ServiceFactory.setServiceManager(serviceManager);
// Tracing the current test method doesn't allow us to use the
// mocked RuntimeException so we'll put it on a dummy method instead
doNothing();
}
use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class ApiTestHelper method mockOutServiceManager.
static void mockOutServiceManager(Map<String, Object> connectionResponse) {
ServiceManager mgr = Mockito.spy(ServiceFactory.getServiceManager());
ServiceFactory.setServiceManager(mgr);
MockRPMServiceManager rpmServiceMgr = new MockRPMServiceManager();
MockRPMService rpmService = new MockRPMService();
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmService.setApplicationName(APP_NAME);
rpmServiceMgr.setRPMService(rpmService);
Mockito.doReturn(rpmServiceMgr).when(mgr).getRPMServiceManager();
BrowserServiceImpl beaconService = new BrowserServiceImpl();
Mockito.doReturn(beaconService).when(mgr).getBrowserService();
StatsService statsService = new StatsServiceImpl();
Mockito.doReturn(statsService).when(mgr).getStatsService();
AgentConfig config = AgentConfigImpl.createAgentConfig(connectionResponse);
beaconService.connected(rpmService, config);
}
use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class HibernateStatsTest method beforeClass.
@BeforeClass
public static void beforeClass() {
final NoopSamplerService samplerService = new NoopSamplerService() {
@Override
public Closeable addSampler(Runnable sampler, long period, TimeUnit timeUnit) {
samplers.add(sampler);
return null;
}
};
ConfigService configService = spy(ServiceFactory.getConfigService());
AgentConfigImpl agentConfig = spy((AgentConfigImpl) configService.getDefaultAgentConfig());
doReturn(true).when(agentConfig).getValue("instrumentation.hibernate.stats_sampler.enabled", false);
doReturn(agentConfig).when(configService).getDefaultAgentConfig();
ServiceManager serviceManager = spy(ServiceFactory.getServiceManager());
doReturn(samplerService).when(serviceManager).getSamplerService();
doReturn(configService).when(serviceManager).getConfigService();
ServiceFactory.setServiceManager(serviceManager);
}
use of com.newrelic.agent.service.ServiceManager 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();
}
Aggregations