Search in sources :

Example 36 with MockRPMService

use of com.newrelic.agent.MockRPMService 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)

Example 37 with MockRPMService

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

the class ProfilerServiceTest method testOneSampleProfile.

@Test
public void testOneSampleProfile() throws Exception {
    MockServiceManager serviceManager = createServiceManager(createAgentConfig(true));
    MockRPMService rpmService = new MockRPMService();
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    ProfilerParameters parameters = new ProfilerParameters(5L, 500L, 500L, false, false, false, null, null);
    ProfilerService profilerService = serviceManager.getProfilerService();
    profilerService.startProfiler(parameters);
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(1, rpmService.getProfiles().size());
    ProfileTree profileTree = rpmService.getProfiles().get(0).getProfileTree(ThreadType.BasicThreadType.AGENT_INSTRUMENTATION);
    Assert.assertEquals(0, profileTree.getRootSegments().size());
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 38 with MockRPMService

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

the class ProfilerServiceTest method stopProfiler.

@Test
public void stopProfiler() throws Exception {
    MockServiceManager serviceManager = createServiceManager(createAgentConfig(true));
    MockRPMService rpmService = new MockRPMService();
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    rpmService.setApplicationName("Unit Test");
    rpmServiceManager.setRPMService(rpmService);
    long profileId = 5;
    ProfilerParameters parameters = new ProfilerParameters(profileId, 100L, 200000L, false, false, false, null, null);
    ProfilerService profilerService = serviceManager.getProfilerService();
    profilerService.startProfiler(parameters);
    Thread.sleep(1000);
    profilerService.stopProfiler(profileId, false);
    LatchingRunnable.drain(profilerService.getScheduledExecutorService());
    Assert.assertNull(profilerService.getCurrentSession());
    Assert.assertEquals(0, 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 39 with MockRPMService

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

the class EventTestHelper method createServiceManager.

public static void createServiceManager(Map<String, Object> config) throws Exception {
    if (APP_NAME == null || APP_NAME.isEmpty()) {
        APP_NAME = "Unit Test";
    }
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), config);
    serviceManager.setConfigService(configService);
    StatsService statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    TransactionService txService = new TransactionService();
    serviceManager.setTransactionService(txService);
    TransactionTraceService ttService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(ttService);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmServiceManager.setRPMService(rpmService);
    ErrorServiceImpl errorService = new ErrorServiceImpl(APP_NAME);
    rpmService.setErrorService(errorService);
    AttributesService attService = new AttributesService();
    serviceManager.setAttributesService(attService);
    serviceManager.setDistributedTraceService(new DistributedTraceServiceImpl());
    serviceManager.setRPMServiceManager(rpmServiceManager);
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 40 with MockRPMService

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

the class InsightsServiceImplTest method testTransactionHarvest.

@Test
public void testTransactionHarvest() throws Exception {
    final Map<String, Object> config = createConfig(true, 2);
    InsightsServiceImpl insights = createService(config);
    insights.addHarvestableToService(appName);
    TransactionInsights txInsights = new TransactionInsights(AgentConfigImpl.createAgentConfig(config));
    txInsights.recordCustomEvent("everything", ImmutableMap.<String, Object>of("is", 5, "awesome", true));
    txInsights.recordCustomEvent("class", ImmutableMap.<String, Object>of("name", "Foo", "number", 666));
    txInsights.recordCustomEvent("method", ImmutableMap.of("className", "Foo", "methodName", "getSomething"));
    // Invalid:
    insights.recordCustomEvent("invalid-type", ImmutableMap.<String, Object>of("name", "Foo", "number", 666));
    Map<String, String> m;
    m = Collections.singletonMap("key", "value");
    insights.recordCustomEvent(null, m);
    m = Collections.singletonMap(null, null);
    insights.recordCustomEvent("bothNull", m);
    m = Collections.singletonMap("key", null);
    insights.recordCustomEvent("valueNull", m);
    m = Collections.singletonMap(null, "value");
    insights.recordCustomEvent("keyNull", m);
    m = new HashMap<>();
    m.put("goodKey1", "goodValue");
    m.put("goodKey2", null);
    m.put(null, null);
    insights.recordCustomEvent("AllKeyValueCombos", m);
    MockRPMService analyticsData = new MockRPMService();
    Mockito.when(ServiceFactory.getServiceManager().getRPMServiceManager().getOrCreateRPMService(appName)).thenReturn(analyticsData);
    TransactionData transactionData = Mockito.mock(TransactionData.class);
    Mockito.when(transactionData.getApplicationName()).thenReturn(appName);
    Mockito.when(transactionData.getInsightsData()).thenReturn(txInsights);
    insights.transactionListener.dispatcherTransactionFinished(transactionData, null);
    insights.harvestHarvestables();
    assertEquals(2, analyticsData.getEvents().size());
}
Also used : TransactionInsights(com.newrelic.agent.service.analytics.InsightsServiceImpl.TransactionInsights) TransactionData(com.newrelic.agent.TransactionData) 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