use of com.newrelic.agent.HarvestService in project newrelic-java-agent by newrelic.
the class SameOrHigherPriorityTransactionNamingPolicyTest method createServiceManager.
private MockServiceManager createServiceManager() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
Map<String, Object> settings = new HashMap<>();
settings.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(settings), settings);
serviceManager.setConfigService(configService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
serviceManager.setSqlTraceService(sqlTraceService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
return serviceManager;
}
use of com.newrelic.agent.HarvestService in project newrelic-java-agent by newrelic.
the class SegmentTest method createServiceManager.
private static void createServiceManager(Map<String, Object> map, ExpirationService expirationService) 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);
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
AsyncTransactionService asyncTxService = new AsyncTransactionService();
serviceManager.setAsyncTransactionService(asyncTxService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
EnvironmentService envService = new EnvironmentServiceImpl();
serviceManager.setEnvironmentService(envService);
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);
serviceManager.setExpirationService(expirationService);
}
use of com.newrelic.agent.HarvestService 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);
}
use of com.newrelic.agent.HarvestService in project newrelic-java-agent by newrelic.
the class InsightsServiceImplTest method testWithTransaction_JAVA2614Regression.
@Test
public void testWithTransaction_JAVA2614Regression() throws Exception {
String appName = "Dude";
Map<String, Object> config = new HashMap<>();
config.put(AgentConfigImpl.APP_NAME, appName);
config.put("custom_insights_events.max_samples_stored", 2);
config.put("token_timeout", 180);
HarvestService harvestService = Mockito.mock(HarvestService.class);
ServiceFactory.setServiceManager(Mockito.mock(ServiceManager.class));
Mockito.when(ServiceFactory.getServiceManager().getHarvestService()).thenReturn(harvestService);
TransactionService txService = Mockito.mock(TransactionService.class);
Mockito.when(ServiceFactory.getServiceManager().getTransactionService()).thenReturn(txService);
Mockito.when(ServiceFactory.getServiceManager().getRPMServiceManager()).thenReturn(Mockito.mock(RPMServiceManager.class));
Mockito.when(ServiceFactory.getServiceManager().getRPMServiceManager().getRPMService()).thenReturn(Mockito.mock(RPMService.class));
Mockito.when(ServiceFactory.getServiceManager().getConfigService()).thenReturn(Mockito.mock(ConfigService.class));
Mockito.when(ServiceFactory.getServiceManager().getConfigService().getDefaultAgentConfig()).thenReturn(AgentConfigImpl.createAgentConfig(config));
Mockito.when(ServiceFactory.getServiceManager().getRPMServiceManager().getRPMService().getApplicationName()).thenReturn(appName);
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);
InsightsServiceImpl insights = new InsightsServiceImpl();
insights.start();
insights.recordCustomEvent("everything", ImmutableMap.<String, Object>of("is", 5, "awesome", true, "key1", Whatever.ONE_THING, "key2", Whatever.ANOTHER_THING));
// JAVA-2614 - null values as recordCustomEvent arguments for eventType or the attribute Map's key/value result
// in an NPE being thrown. The following five API calls will cause an NPE if we have reintroduced the problem.
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);
assertEquals(0, analyticsData.getEvents().size());
assertEquals(5, txInsights.events.size());
CustomInsightsEvent customEvent = txInsights.events.poll();
assertNotNull(customEvent);
assertEquals(Whatever.ONE_THING.toString(), customEvent.getUserAttributesCopy().get("key1"));
Writer writer = new StringWriter();
customEvent.writeJSONString(writer);
String json = writer.toString();
assertNotNull(json);
// JAVA-2614 - through 3.33, attribute values that were not JSON types would cause the Agent
// to generate invalid JSON. We check for this by attempting to parse the JSON. If an exception
// occurs in the line below, we have reintroduced the problem and are generating invalid JSON.
// The assert may be useful, but is really just to ensure the parse actually occurs. N.B.: we
// need to make the outer JSON look like a JSON object for the GSON parser to accept it.
json = "{ 'x':" + json + "}";
Reader reader = new InputStreamReader(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)));
assertNotNull(new Gson().fromJson(reader, Object.class));
}
use of com.newrelic.agent.HarvestService in project newrelic-java-agent by newrelic.
the class TransactionNamingTest 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);
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(map), map);
serviceManager.setConfigService(configService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
serviceManager.setSqlTraceService(sqlTraceService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName("Unit Test");
rpmServiceManager.setRPMService(rpmService);
NormalizationService normalizationService = new NormalizationServiceImpl();
serviceManager.setNormalizationService(normalizationService);
AttributesService attributeService = new AttributesService();
serviceManager.setAttributesService(attributeService);
}
Aggregations