use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class TransactionTraceServiceTest method randomTransactionSampler.
@Test
public void randomTransactionSampler() throws Exception {
Map<String, Object> configMap = createConfigMap();
Map<String, Object> ttConfigMap = new HashMap<>();
configMap.put("transaction_tracer", ttConfigMap);
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
ttConfigMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 1000f);
createServiceManager(configMap);
TransactionTraceService ttService = ServiceFactory.getTransactionTraceService();
TransactionData td = createTransactionData("/en/betting/Baseball/*", APP_NAME, 10L);
ttService.dispatcherTransactionFinished(td, null);
ttService.afterHarvest(APP_NAME);
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService(APP_NAME);
List<TransactionTrace> traces = rpmService.getTraces();
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/en/betting/Baseball/*", traces.get(0).getRequestUri());
Assert.assertEquals(10L, traces.get(0).getDuration());
}
use of com.newrelic.agent.MockRPMService 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.MockRPMService 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.MockRPMService in project newrelic-java-agent by newrelic.
the class RPMConnectionServiceTest method appServerPortNotAvailable.
@Test
public void appServerPortNotAvailable() throws Exception {
ServiceFactory.getEnvironmentService().getEnvironment().setServerPort(null);
rpmConnectionService.setAppServerPortTimeout(0L);
CountDownLatch latch = new CountDownLatch(1);
MockRPMService rpmService = new MockRPMService(latch);
rpmConnectionService.connect(rpmService);
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.newrelic.agent.MockRPMService 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());
}
Aggregations