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