use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class InsightsServiceImplTest method testCustomEventFasterHarvest.
@Test
public void testCustomEventFasterHarvest() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(AgentConfigImpl.APP_NAME, EventTestHelper.APP_NAME);
EventTestHelper.createServiceManager(config);
String appName = ServiceFactory.getRPMService().getApplicationName();
InsightsServiceImpl insightsService = new InsightsServiceImpl();
((MockServiceManager) ServiceFactory.getServiceManager()).setInsights(insightsService);
ServiceManager serviceManager = spy(ServiceFactory.getServiceManager());
ServiceFactory.setServiceManager(serviceManager);
HarvestServiceImpl harvestService = spy(new HarvestServiceImpl());
doReturn(harvestService).when(serviceManager).getHarvestService();
doReturn(0L).when(harvestService).getInitialDelay();
insightsService.addHarvestableToService(appName);
insightsService.configureHarvestables(60, 10);
assertEquals(10, insightsService.getMaxSamplesStored());
insightsService.start();
Map<String, Object> connectionInfo = new HashMap<>();
Map<String, Object> eventHarvest = new HashMap<>();
Map<String, Object> harvestLimits = new HashMap<>();
// 5 is the lowest allowable value
eventHarvest.put("report_period_ms", 5000L);
eventHarvest.put("harvest_limits", harvestLimits);
harvestLimits.put("custom_event_data", 1L);
connectionInfo.put("event_harvest_config", eventHarvest);
harvestService.startHarvestables(ServiceFactory.getRPMService(), AgentConfigImpl.createAgentConfig(connectionInfo));
Thread.sleep(500);
Map<String, String> m = Collections.singletonMap("key", "value");
insightsService.recordCustomEvent("CustomEvent", m);
Thread.sleep(5050);
checkForEvent();
((MockRPMService) ServiceFactory.getRPMService()).clearEvents();
insightsService.recordCustomEvent("CustomEvent", m);
Thread.sleep(5050);
checkForEvent();
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class InsightsServiceImplTest method testWithTransaction.
@Test
public void testWithTransaction() throws Exception {
Map<String, Object> config = createConfig(true, 2);
config.put(AgentConfigImpl.ASYNC_TIMEOUT, 180);
InsightsServiceImpl insights = createService(config);
Transaction transaction = Mockito.mock(Transaction.class);
Mockito.when(txService.getTransaction(false)).thenReturn(transaction);
TransactionInsights txInsights = new TransactionInsights(AgentConfigImpl.createAgentConfig(Collections.<String, Object>emptyMap()));
Mockito.when(transaction.getInsightsData()).thenReturn(txInsights);
Mockito.when(transaction.getApplicationName()).thenReturn(appName);
Mockito.when(transaction.isInProgress()).thenReturn(true);
insights.recordCustomEvent("everything", ImmutableMap.<String, Object>of("is", 5, "awesome", true));
insights.recordCustomEvent("class", ImmutableMap.<String, Object>of("name", "Foo", "number", 666));
insights.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().getRPMService(appName)).thenReturn(analyticsData);
insights.harvestHarvestables();
assertEquals(0, analyticsData.getEvents().size());
assertEquals(7, txInsights.events.size());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class MetricNormalizerTest method setUrlRules.
private String setUrlRules(JSONArray rules) {
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
List<ConnectionListener> connectionListeners = rpmServiceManager.getConnectionListeners();
ConnectionListener connectionListener = connectionListeners.get(0);
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
String appName = rpmService.getApplicationName();
Map<String, Object> data = new HashMap<>();
data.put(NormalizationRuleConfig.URL_RULES_KEY, rules);
// add a bogus segment term rule to make sure that has no side-effect of breaking stuff
data.put("transaction_segment_terms", Arrays.asList(ImmutableMap.of("prefix", "This/Wont/Match/Anything", "terms", Arrays.asList("of", "endearment"))));
connectionListener.connected(rpmService, AgentConfigImpl.createAgentConfig(data));
return appName;
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class SpringPointCutTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
MockConfigService configService = new MockConfigService(null);
configService.setAgentConfig(config);
serviceManager.setConfigService(configService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName("Unit Test");
rpmServiceManager.setRPMService(rpmService);
serviceManager.setNormalizationService(new NormalizationServiceImpl());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method checkForEvent.
private void checkForEvent() {
StatsEngine statsEngineForHarvest = ServiceFactory.getStatsService().getStatsEngineForHarvest(EventTestHelper.APP_NAME);
Assert.assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_ERROR_SERVICE_TRANSACTION_ERROR_SENT)).hasData());
Assert.assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_ERROR_SERVICE_TRANSACTION_ERROR_SEEN)).hasData());
Assert.assertEquals(1, ((MockRPMService) ServiceFactory.getRPMService()).getEvents().size());
ErrorEvent errorEvent = (ErrorEvent) Iterables.get(((MockRPMService) ServiceFactory.getRPMService()).getEvents(), 0);
Assert.assertEquals(errorEvent.getUserAttributesCopy().get("test_attribute"), "value");
Assert.assertEquals("TransactionError", errorEvent.getType());
}
Aggregations