Search in sources :

Example 11 with EnvironmentService

use of com.newrelic.agent.environment.EnvironmentService in project newrelic-java-agent by newrelic.

the class TransactionTimesTest method createServiceManager.

private static void createServiceManager(Map<String, Object> map) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, map, Collections.<String, Object>emptyMap());
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, map);
    serviceManager.setConfigService(configService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    HarvestService harvestService = new MockHarvestService();
    serviceManager.setHarvestService(harvestService);
    EnvironmentService envService = new EnvironmentServiceImpl();
    serviceManager.setEnvironmentService(envService);
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    StatsServiceImpl statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
    serviceManager.setSqlTraceService(sqlTraceService);
    serviceManager.setAttributesService(new AttributesService());
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    serviceManager.setDistributedTraceService(distributedTraceService);
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
    serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
}
Also used : SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) TransactionService(com.newrelic.agent.TransactionService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) ThreadService(com.newrelic.agent.ThreadService) AgentConfig(com.newrelic.agent.config.AgentConfig) SqlTraceService(com.newrelic.agent.sql.SqlTraceService) ConfigService(com.newrelic.agent.config.ConfigService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) MockCoreService(com.newrelic.agent.MockCoreService) MockHarvestService(com.newrelic.agent.MockHarvestService) EnvironmentService(com.newrelic.agent.environment.EnvironmentService)

Example 12 with EnvironmentService

use of com.newrelic.agent.environment.EnvironmentService in project newrelic-java-agent by newrelic.

the class TransactionServiceTest method createServiceManager.

private MockServiceManager createServiceManager(Map<String, Object> map) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(map), map);
    serviceManager.setConfigService(configService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    HarvestService harvestService = new MockHarvestService();
    serviceManager.setHarvestService(harvestService);
    TransactionService transactionService = new TransactionService();
    transactionService.start();
    serviceManager.setTransactionService(transactionService);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    ExtensionService extensionService = new ExtensionService(configService, ExtensionsLoadedListener.NOOP);
    serviceManager.setExtensionService(extensionService);
    TracerService tracerService = new TracerService();
    serviceManager.setTracerService(tracerService);
    StatsService statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    EnvironmentService environmentService = new EnvironmentServiceImpl();
    serviceManager.setEnvironmentService(environmentService);
    AttributesService attributesService = new AttributesService();
    serviceManager.setAttributesService(attributesService);
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    serviceManager.setDistributedTraceService(distributedTraceService);
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
    serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
    return serviceManager;
}
Also used : ExtensionService(com.newrelic.agent.extension.ExtensionService) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) ConfigService(com.newrelic.agent.config.ConfigService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) EnvironmentService(com.newrelic.agent.environment.EnvironmentService)

Example 13 with EnvironmentService

use of com.newrelic.agent.environment.EnvironmentService in project newrelic-java-agent by newrelic.

the class TransactionAppNamingTest method createServiceManager.

@Before
public void createServiceManager() throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    // Needed by TransactionService
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    // Needed by TransactionTraceService
    Map<String, Object> configMap = createConfigMap();
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(configMap), configMap);
    serviceManager.setConfigService(configService);
    // Needed by Transaction
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    EnvironmentService envService = new EnvironmentServiceImpl();
    serviceManager.setEnvironmentService(envService);
    // Null pointers if not set
    serviceManager.setStatsService(Mockito.mock(StatsService.class));
    // Needed by Transaction
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    serviceManager.setAttributesService(new AttributesService());
    // Needed by Transaction
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
    rpmServiceManager.setRPMService(rpmService);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) AttributesService(com.newrelic.agent.attributes.AttributesService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ConfigService(com.newrelic.agent.config.ConfigService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) Before(org.junit.Before)

Example 14 with EnvironmentService

use of com.newrelic.agent.environment.EnvironmentService in project newrelic-java-agent by newrelic.

the class SpanEventsServiceTest method before.

@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    serviceManager = new MockServiceManager();
    Map<String, Object> localSettings = new HashMap<>();
    localSettings.put(AgentConfigImpl.APP_NAME, APP_NAME);
    localSettings.put("distributed_tracing", Collections.singletonMap("enabled", true));
    localSettings.put("span_events", Collections.singletonMap("collect_span_events", true));
    when(spanEventCreationDecider.shouldCreateSpans(any(TransactionData.class))).thenReturn(true);
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, localSettings, new HashMap<String, Object>());
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, localSettings);
    serviceManager.setConfigService(configService);
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.setTransactionService(new TransactionService());
    serviceManager.setThreadService(new ThreadService());
    final MockSpanEventReservoirManager reservoirManager = new MockSpanEventReservoirManager(configService);
    Consumer<SpanEvent> backendConsumer = spanEvent -> reservoirManager.getOrCreateReservoir(APP_NAME).add(spanEvent);
    SpanErrorBuilder defaultSpanErrorBuilder = new SpanErrorBuilder(new ErrorAnalyzerImpl(agentConfig.getErrorCollectorConfig()), new ErrorMessageReplacer(agentConfig.getStripExceptionConfig()));
    Map<String, SpanErrorBuilder> map = new HashMap<>();
    map.put(agentConfig.getApplicationName(), defaultSpanErrorBuilder);
    EnvironmentService environmentService = mock(EnvironmentService.class, RETURNS_DEEP_STUBS);
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
    when(transactionDataToDistributedTraceIntrinsics.buildDistributedTracingIntrinsics(any(TransactionData.class), anyBoolean())).thenReturn(Collections.<String, Object>emptyMap());
    TracerToSpanEvent tracerToSpanEvent = new TracerToSpanEvent(map, environmentService, transactionDataToDistributedTraceIntrinsics, defaultSpanErrorBuilder);
    SpanEventsServiceImpl spanEventsService = SpanEventsServiceImpl.builder().agentConfig(agentConfig).reservoirManager(reservoirManager).collectorSender(mock(CollectorSpanEventSender.class)).eventBackendStorage(backendConsumer).spanEventCreationDecider(spanEventCreationDecider).tracerToSpanEvent(tracerToSpanEvent).build();
    serviceManager.setSpansEventService(spanEventsService);
    serviceManager.setAttributesService(new AttributesService());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) AttributesService(com.newrelic.agent.attributes.AttributesService) TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) MockitoAnnotations(org.mockito.MockitoAnnotations) After(org.junit.After) Map(java.util.Map) Before(org.junit.Before) ErrorMessageReplacer(com.newrelic.agent.errors.ErrorMessageReplacer) Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test) SpanEvent(com.newrelic.agent.model.SpanEvent) com.newrelic.agent.config(com.newrelic.agent.config) com.newrelic.agent(com.newrelic.agent) Mockito(org.mockito.Mockito) ErrorAnalyzerImpl(com.newrelic.agent.errors.ErrorAnalyzerImpl) SERVER_SPAN_HARVEST_CONFIG(com.newrelic.agent.config.SpanEventsConfig.SERVER_SPAN_HARVEST_CONFIG) SamplingPriorityQueue(com.newrelic.agent.interfaces.SamplingPriorityQueue) Consumer(com.newrelic.agent.interfaces.backport.Consumer) SpanCategory(com.newrelic.agent.model.SpanCategory) Collections(java.util.Collections) ServiceFactory(com.newrelic.agent.service.ServiceFactory) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) ErrorAnalyzerImpl(com.newrelic.agent.errors.ErrorAnalyzerImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) SpanEvent(com.newrelic.agent.model.SpanEvent) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) ErrorMessageReplacer(com.newrelic.agent.errors.ErrorMessageReplacer) Before(org.junit.Before)

Example 15 with EnvironmentService

use of com.newrelic.agent.environment.EnvironmentService in project newrelic-java-agent by newrelic.

the class RPMConnectionServiceTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    AgentHelper.initializeConfig();
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
    AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
    Environment env = new Environment(config, "c:\\test\\log");
    EnvironmentService envService = Mockito.mock(EnvironmentService.class, new Returns(env));
    serviceManager.setEnvironmentService(envService);
    ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
    serviceManager.setConfigService(configService);
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    rpmConnectionService = new TestRPMConnectionService();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) Returns(org.mockito.internal.stubbing.answers.Returns) ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) MockServiceManager(com.newrelic.agent.MockServiceManager) Environment(com.newrelic.agent.environment.Environment) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) BeforeClass(org.junit.BeforeClass)

Aggregations

EnvironmentService (com.newrelic.agent.environment.EnvironmentService)17 ConfigService (com.newrelic.agent.config.ConfigService)14 EnvironmentServiceImpl (com.newrelic.agent.environment.EnvironmentServiceImpl)13 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)13 AttributesService (com.newrelic.agent.attributes.AttributesService)12 TransactionDataToDistributedTraceIntrinsics (com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics)9 TransactionEventsService (com.newrelic.agent.service.analytics.TransactionEventsService)9 StatsService (com.newrelic.agent.stats.StatsService)9 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)9 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)8 MockServiceManager (com.newrelic.agent.MockServiceManager)7 ThreadService (com.newrelic.agent.ThreadService)7 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)7 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)7 HarvestService (com.newrelic.agent.HarvestService)6 TransactionService (com.newrelic.agent.TransactionService)6 AgentConfig (com.newrelic.agent.config.AgentConfig)5 Before (org.junit.Before)5 MockCoreService (com.newrelic.agent.MockCoreService)4 MockHarvestService (com.newrelic.agent.MockHarvestService)4