Search in sources :

Example 41 with MockRPMService

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

Example 42 with MockRPMService

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());
}
Also used : Transaction(com.newrelic.agent.Transaction) TransactionInsights(com.newrelic.agent.service.analytics.InsightsServiceImpl.TransactionInsights) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 43 with MockRPMService

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;
}
Also used : HashMap(java.util.HashMap) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) JSONObject(org.json.simple.JSONObject) ConnectionListener(com.newrelic.agent.ConnectionListener) MockRPMService(com.newrelic.agent.MockRPMService)

Example 44 with MockRPMService

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());
}
Also used : ThreadService(com.newrelic.agent.ThreadService) AgentConfig(com.newrelic.agent.config.AgentConfig) MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockConfigService(com.newrelic.agent.MockConfigService) MockRPMService(com.newrelic.agent.MockRPMService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl) BeforeClass(org.junit.BeforeClass)

Example 45 with MockRPMService

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());
}
Also used : ErrorEvent(com.newrelic.agent.model.ErrorEvent) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService)

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