Search in sources :

Example 56 with MockRPMService

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());
    }
}
Also used : MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 57 with MockRPMService

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

Example 58 with MockRPMService

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

Example 59 with MockRPMService

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

Example 60 with MockRPMService

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());
}
Also used : Transaction(com.newrelic.agent.Transaction) 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