Search in sources :

Example 31 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class CollectorSpanEventReservoirManagerTest method retryOnHttpErrorWithNoDiscard.

@Test
public void retryOnHttpErrorWithNoDiscard() {
    ConfigService mockConfigService = mock21Samples();
    CollectorSpanEventReservoirManager target = initWith25Tries(mockConfigService);
    ReservoirManager.HarvestResult harvestResult = target.attemptToSendReservoir(APP_NAME, (appName, reservoirSize, eventsSeen, events) -> {
        throw new HttpError("don't discard", 429, 1234);
    }, mock(Logger.class));
    assertNull(harvestResult);
    assertEquals(21, target.getOrCreateReservoir(APP_NAME).size());
    assertEquals(21, target.getOrCreateReservoir(APP_NAME).getNumberOfTries());
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) ReservoirManager(com.newrelic.agent.interfaces.ReservoirManager) HttpError(com.newrelic.agent.transport.HttpError) Logger(com.newrelic.api.agent.Logger) Test(org.junit.Test)

Example 32 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class CollectorSpanEventReservoirManagerTest method mock21Samples.

public ConfigService mock21Samples() {
    ConfigService mockConfigService = Mockito.mock(ConfigService.class);
    AgentConfig mockConfig = Mockito.mock(AgentConfig.class);
    SpanEventsConfig mockSpanEventsConfig = Mockito.mock(SpanEventsConfig.class);
    when(mockConfigService.getDefaultAgentConfig()).thenReturn(mockConfig);
    when(mockConfigService.getAgentConfig(anyString())).thenReturn(mockConfig);
    when(mockConfig.getSpanEventsConfig()).thenReturn(mockSpanEventsConfig);
    when(mockSpanEventsConfig.getMaxSamplesStored()).thenReturn(21);
    return mockConfigService;
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) SpanEventsConfig(com.newrelic.agent.config.SpanEventsConfig)

Example 33 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class CollectorSpanEventReservoirManagerTest method exceptionTriggerDiscard.

@Test
public void exceptionTriggerDiscard() {
    ConfigService mockConfigService = mock21Samples();
    CollectorSpanEventReservoirManager target = initWith25Tries(mockConfigService);
    ReservoirManager.HarvestResult harvestResult = target.attemptToSendReservoir(APP_NAME, (appName, reservoirSize, eventsSeen, events) -> {
        throw new RuntimeException("~~ oops ~~");
    }, mock(Logger.class));
    assertNull(harvestResult);
    assertEquals(0, target.getOrCreateReservoir(APP_NAME).size());
    assertEquals(0, target.getOrCreateReservoir(APP_NAME).getNumberOfTries());
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) ReservoirManager(com.newrelic.agent.interfaces.ReservoirManager) Logger(com.newrelic.api.agent.Logger) Test(org.junit.Test)

Example 34 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class CollectorSpanEventReservoirManagerTest method maxSamplesStoredConfiguredAfterConstruction.

@Test
public void maxSamplesStoredConfiguredAfterConstruction() {
    ConfigService mockConfigService = mock21Samples();
    CollectorSpanEventReservoirManager target = new CollectorSpanEventReservoirManager(mockConfigService);
    assertEquals(21, target.getMaxSamplesStored());
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) Test(org.junit.Test)

Example 35 with ConfigService

use of com.newrelic.agent.config.ConfigService 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);
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService)

Aggregations

ConfigService (com.newrelic.agent.config.ConfigService)95 MockServiceManager (com.newrelic.agent.MockServiceManager)57 TransactionService (com.newrelic.agent.TransactionService)36 AgentConfig (com.newrelic.agent.config.AgentConfig)36 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)32 ThreadService (com.newrelic.agent.ThreadService)31 AttributesService (com.newrelic.agent.attributes.AttributesService)30 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)29 HarvestService (com.newrelic.agent.HarvestService)24 MockHarvestService (com.newrelic.agent.MockHarvestService)23 HashMap (java.util.HashMap)23 StatsService (com.newrelic.agent.stats.StatsService)21 MockCoreService (com.newrelic.agent.MockCoreService)20 MockRPMService (com.newrelic.agent.MockRPMService)20 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)20 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)20 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 Test (org.junit.Test)15 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)14