Search in sources :

Example 16 with MockRPMServiceManager

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

the class NormalizedTransactionTrace method createServiceManager.

private static void createServiceManager(Map<String, Object> map) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(map), map);
    serviceManager.setConfigService(configService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    AttributesService attrService = new AttributesService();
    serviceManager.setAttributesService(attrService);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    NormalizationService normalizationService = new NormalizationServiceImpl();
    serviceManager.setNormalizationService(normalizationService);
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) TransactionService(com.newrelic.agent.TransactionService) MockServiceManager(com.newrelic.agent.MockServiceManager) AttributesService(com.newrelic.agent.attributes.AttributesService) MockCoreService(com.newrelic.agent.MockCoreService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) NormalizationService(com.newrelic.agent.normalization.NormalizationService) MockRPMService(com.newrelic.agent.MockRPMService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl)

Example 17 with MockRPMServiceManager

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

the class BasicRequestDispatcherTracerTest method requestXQueueHeaderRecordApdexMetrics.

@Test
public void requestXQueueHeaderRecordApdexMetrics() throws Exception {
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    rpmService.setEverConnected(true);
    Map<String, Object> data = new HashMap<>();
    data.put(AgentConfigImpl.APDEX_T, 6.0d);
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    connectionConfigListener.connected(rpmService, data);
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.getTransaction().getRootTracer().finish(0, null);
    StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(APP_NAME);
    ApdexStats apdexStats = statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX));
    Assert.assertEquals(0, apdexStats.getApdexFrustrating());
    apdexStats = statsEngine.getApdexStats(MetricName.create("Apdex/Uri/Unknown"));
    Assert.assertEquals(0, apdexStats.getApdexFrustrating());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) ApdexStats(com.newrelic.agent.stats.ApdexStats) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 18 with MockRPMServiceManager

use of com.newrelic.agent.MockRPMServiceManager 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 19 with MockRPMServiceManager

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

the class ProfileSessionTest method stopSession.

@Test
public void stopSession() throws Exception {
    Map<String, Object> config = ProfilerServiceTest.createAgentConfig(true);
    MockServiceManager serviceManager = createServiceManager(config);
    MockRPMService rpmService = new MockRPMService();
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    ProfilerService profilerService = serviceManager.getProfilerService();
    ProfilerParameters parameters = new ProfilerParameters(5L, 100L, 300000L, false, false, false, null, null);
    ProfileSession session = new ProfileSession(profilerService, parameters);
    session.start();
    Thread.sleep(1000);
    session.stop(true);
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertTrue(session.isDone());
    Assert.assertNotNull(session.getProfile());
    Assert.assertTrue(session.getProfile().getSampleCount() > 1);
    Assert.assertEquals(parameters.getProfileId(), session.getProfileId());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(1, rpmService.getProfiles().size());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 20 with MockRPMServiceManager

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

the class ProfileSessionTest method multiSample.

@Test
public void multiSample() throws Exception {
    Map<String, Object> config = ProfilerServiceTest.createAgentConfig(true);
    MockServiceManager serviceManager = createServiceManager(config);
    MockRPMService rpmService = new MockRPMService();
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    ProfilerService profilerService = serviceManager.getProfilerService();
    ProfilerParameters parameters = new ProfilerParameters(5L, 100L, 500L, false, false, false, null, null);
    ProfileSession session = new ProfileSession(profilerService, parameters);
    session.start();
    Thread.sleep(1000L);
    Assert.assertTrue(session.isDone());
    Assert.assertNotNull(session.getProfile());
    Assert.assertTrue(session.getProfile().getSampleCount() > 1);
    Assert.assertEquals(parameters.getProfileId(), session.getProfileId());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(1, rpmService.getProfiles().size());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)57 MockServiceManager (com.newrelic.agent.MockServiceManager)46 MockRPMService (com.newrelic.agent.MockRPMService)44 TransactionService (com.newrelic.agent.TransactionService)31 ConfigService (com.newrelic.agent.config.ConfigService)29 MockHarvestService (com.newrelic.agent.MockHarvestService)25 HarvestService (com.newrelic.agent.HarvestService)24 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)24 ThreadService (com.newrelic.agent.ThreadService)23 AttributesService (com.newrelic.agent.attributes.AttributesService)22 MockCoreService (com.newrelic.agent.MockCoreService)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)16 HashMap (java.util.HashMap)16 Test (org.junit.Test)16 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)15 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)15 AgentConfig (com.newrelic.agent.config.AgentConfig)14 StatsService (com.newrelic.agent.stats.StatsService)14 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)9