Search in sources :

Example 31 with MockRPMService

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());
}
Also used : HashMap(java.util.HashMap) TransactionData(com.newrelic.agent.TransactionData) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 32 with MockRPMService

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());
}
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 33 with MockRPMService

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);
}
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 34 with MockRPMService

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));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test) AgentConfigFactoryTest(com.newrelic.agent.config.AgentConfigFactoryTest)

Example 35 with MockRPMService

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());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

MockRPMService (com.newrelic.agent.MockRPMService)97 Test (org.junit.Test)59 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)44 MockServiceManager (com.newrelic.agent.MockServiceManager)39 MockHarvestService (com.newrelic.agent.MockHarvestService)30 HashMap (java.util.HashMap)28 TransactionService (com.newrelic.agent.TransactionService)26 ConfigService (com.newrelic.agent.config.ConfigService)21 MockCoreService (com.newrelic.agent.MockCoreService)20 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)18 HarvestService (com.newrelic.agent.HarvestService)17 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 ThreadService (com.newrelic.agent.ThreadService)15 StatsService (com.newrelic.agent.stats.StatsService)15 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)15 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)15 SqlTracer (com.newrelic.agent.tracers.SqlTracer)15 Tracer (com.newrelic.agent.tracers.Tracer)15 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)15 TransactionData (com.newrelic.agent.TransactionData)14