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