use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class CommandTest method shutdown.
@Test
public void shutdown() throws Exception {
MockRPMService rpmService = new MockRPMService();
MockCoreService executor = new MockCoreService() {
@Override
public void shutdownAsync() {
throw new RuntimeException("shutdown");
}
};
Assert.assertEquals(Collections.EMPTY_MAP, new RestartCommand().process(rpmService, Collections.EMPTY_MAP));
try {
new ShutdownCommand(executor).process(rpmService, Collections.EMPTY_MAP);
Assert.fail();
} catch (Exception e) {
Assert.assertEquals("shutdown", e.getMessage());
}
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method badServerData.
@Test
public void badServerData() throws Exception {
Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
createServiceManager(configMap);
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
Map<String, Object> data = new HashMap<>();
Map<String, Object> agentData = new HashMap<>();
data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
data.put(AgentConfigImpl.APDEX_T, 0.5d);
data.put(AgentConfigFactory.COLLECT_TRACES, true);
agentData.put(AgentConfigFactory.TRANSACTION_TRACER_PREFIX + TransactionTracerConfigImpl.ENABLED, "bad");
agentData.put(AgentConfigFactory.ERROR_COLLECTOR_PREFIX + ErrorCollectorConfigImpl.ENABLED, !ErrorCollectorConfigImpl.DEFAULT_ENABLED);
connectionConfigListener.connected(rpmService, data);
ConfigService configService = ServiceFactory.getConfigService();
assertFalse(configService.getAgentConfig(null).getTransactionTracerConfig().isEnabled());
assertEquals(ErrorCollectorConfigImpl.DEFAULT_ENABLED, configService.getAgentConfig(null).getErrorCollectorConfig().isEnabled());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method checkForEvent.
private void checkForEvent() {
assertEquals(1, ((MockRPMService) ServiceFactory.getRPMService()).getEvents().size());
StatsEngine statsEngineForHarvest = ServiceFactory.getStatsService().getStatsEngineForHarvest(EventTestHelper.APP_NAME);
assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_TRANSACTION_EVENT_SERVICE_TRANSACTION_EVENT_SEEN)).hasData());
assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_TRANSACTION_EVENT_SERVICE_TRANSACTION_EVENT_SENT)).hasData());
((MockRPMService) ServiceFactory.getRPMService()).clearEvents();
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class LogSenderServiceImplTest method testWithTransaction.
@Test
public void testWithTransaction() throws Exception {
LogSenderServiceImpl logSenderService = createService(createConfig(null, 180));
Transaction transaction = Mockito.mock(Transaction.class);
when(ServiceFactory.getTransactionService().getTransaction(false)).thenReturn(transaction);
LogSenderServiceImpl.TransactionLogs logs = new LogSenderServiceImpl.TransactionLogs(AgentConfigImpl.createAgentConfig(Collections.emptyMap()));
when(transaction.getLogEventData()).thenReturn(logs);
when(transaction.getApplicationName()).thenReturn(appName);
when(transaction.isInProgress()).thenReturn(true);
logSenderService.recordLogEvent(ImmutableMap.of("field", "value"));
logSenderService.recordLogEvent(ImmutableMap.of("field2", "value2"));
logSenderService.recordLogEvent(ImmutableMap.of("field3", "value3"));
MockRPMService analyticsData = new MockRPMService();
when(ServiceFactory.getServiceManager().getRPMServiceManager().getOrCreateRPMService(appName)).thenReturn(analyticsData);
logSenderService.harvestHarvestables();
assertEquals(0, analyticsData.getEvents().size());
assertEquals(3, logs.events.size());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class LogSenderServiceImplTest method testTransactionHarvest.
@Test
public void testTransactionHarvest() throws Exception {
LogSenderServiceImpl logSenderService = createService(createConfig(null, 180));
logSenderService.addHarvestableToService(appName);
Transaction transaction = Mockito.mock(Transaction.class);
when(ServiceFactory.getTransactionService().getTransaction(false)).thenReturn(transaction);
LogSenderServiceImpl.TransactionLogs logs = new LogSenderServiceImpl.TransactionLogs(AgentConfigImpl.createAgentConfig(Collections.emptyMap()));
when(transaction.getLogEventData()).thenReturn(logs);
when(transaction.getApplicationName()).thenReturn(appName);
when(transaction.isInProgress()).thenReturn(true);
logSenderService.recordLogEvent(ImmutableMap.of("field", "value"));
logSenderService.recordLogEvent(ImmutableMap.of("field2", "value2"));
logSenderService.recordLogEvent(ImmutableMap.of("field3", "value3"));
// these should be filtered out
logSenderService.recordLogEvent(null);
logSenderService.recordLogEvent(Collections.emptyMap());
MockRPMService analyticsData = new MockRPMService();
when(ServiceFactory.getServiceManager().getRPMServiceManager().getOrCreateRPMService(appName)).thenReturn(analyticsData);
TransactionData transactionData = Mockito.mock(TransactionData.class);
when(transactionData.getApplicationName()).thenReturn(appName);
when(transactionData.getLogEventData()).thenReturn(logs);
logSenderService.transactionListener.dispatcherTransactionFinished(transactionData, null);
logSenderService.harvestHarvestables();
logSenderService.harvestHarvestables();
assertEquals(3, analyticsData.getEvents().size());
}
Aggregations