Search in sources :

Example 11 with ServiceManager

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);
}
Also used : RPMServiceManager(com.newrelic.agent.RPMServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) RPMServiceManager(com.newrelic.agent.RPMServiceManager) Before(org.junit.Before)

Example 12 with ServiceManager

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();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ServiceManager(com.newrelic.agent.service.ServiceManager) InsightsService(com.newrelic.agent.service.analytics.InsightsService) Test(org.junit.Test)

Example 13 with ServiceManager

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);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) BrowserServiceImpl(com.newrelic.agent.browser.BrowserServiceImpl) MockRPMService(com.newrelic.agent.MockRPMService)

Example 14 with ServiceManager

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);
}
Also used : AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ConfigService(com.newrelic.agent.config.ConfigService) ServiceManager(com.newrelic.agent.service.ServiceManager) TimeUnit(java.util.concurrent.TimeUnit) NoopSamplerService(com.newrelic.agent.samplers.NoopSamplerService) BeforeClass(org.junit.BeforeClass)

Example 15 with 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();
}
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)

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