use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method createServiceManager.
private void createServiceManager(Map<String, Object> configMap) throws Exception {
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(configMap);
MockServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName("Unit Test");
rpmServiceManager.setRPMService(rpmService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
configService.start();
serviceManager.start();
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method connectionListener.
@Test
public void connectionListener() throws Exception {
Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
createServiceManager(configMap);
ConfigService configService = ServiceFactory.getConfigService();
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
String appName = rpmService.getApplicationName();
String appName2 = "bogus";
Map<String, Object> data = new HashMap<>();
Map<String, Object> agentData = new HashMap<>();
data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
data.put(AgentConfigImpl.APDEX_T, 0.500d);
data.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
data.put(ErrorCollectorConfigImpl.COLLECT_ERRORS, true);
agentData.put(AgentConfigFactory.TRANSACTION_TRACER_PREFIX + TransactionTracerConfigImpl.ENABLED, true);
agentData.put(AgentConfigFactory.ERROR_COLLECTOR_PREFIX + ErrorCollectorConfigImpl.ENABLED, true);
assertFalse(configService.getAgentConfig(appName).getTransactionTracerConfig().isEnabled());
assertFalse(configService.getAgentConfig(appName2).getTransactionTracerConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEnabled());
connectionConfigListener.connected(rpmService, data);
assertEquals(500L, configService.getAgentConfig(appName).getApdexTInMillis());
assertEquals(1000L, configService.getAgentConfig(appName2).getApdexTInMillis());
assertTrue(configService.getAgentConfig(appName).getTransactionTracerConfig().isEnabled());
assertFalse(configService.getAgentConfig(appName2).getTransactionTracerConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEnabled());
data.put(AgentConfigImpl.APDEX_T, 1.500d);
connectionConfigListener.connected(rpmService, data);
assertEquals(1500L, configService.getAgentConfig(appName).getApdexTInMillis());
assertEquals(1000L, configService.getAgentConfig(appName2).getApdexTInMillis());
rpmService = new MockRPMService();
rpmService.setApplicationName(appName2);
data.put(AgentConfigImpl.APDEX_T, 2.000d);
connectionConfigListener.connected(rpmService, data);
assertEquals(1500L, configService.getAgentConfig(appName).getApdexTInMillis());
assertEquals(2000L, configService.getAgentConfig(appName2).getApdexTInMillis());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class TransactionTraceServiceTest method createServiceManager.
private void createServiceManager(Map<String, Object> configMap) throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(configMap), configMap);
serviceManager.setConfigService(configService);
DatabaseService dbService = new DatabaseService();
serviceManager.setDatabaseService(dbService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setIsConnected(true);
rpmServiceManager.setRPMService(rpmService);
CommandParser commandParser = new CommandParser();
serviceManager.setCommandParser(commandParser);
AttributesService attService = new AttributesService();
serviceManager.setAttributesService(attService);
TransactionTraceService ttService = new TransactionTraceService();
serviceManager.setTransactionTraceService(ttService);
ttService.start();
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class TransactionTraceServiceTest method transactionSamplers.
@Test
public void transactionSamplers() throws Exception {
Map<String, Object> configMap = createConfigMap();
Map<String, Object> ttConfigMap = new HashMap<>();
configMap.put("transaction_tracer", ttConfigMap);
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
createServiceManager(configMap);
TransactionTraceService ttService = ServiceFactory.getTransactionTraceService();
ITransactionSampler transactionSampler = new ITransactionSampler() {
private final List<TransactionData> tds = new ArrayList<>();
@Override
public boolean noticeTransaction(TransactionData td) {
tds.add(td);
return true;
}
@Override
public List<TransactionTrace> harvest(String appName) {
List<TransactionTrace> traces = new ArrayList<>();
for (TransactionData td : tds) {
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
traces.add(trace);
}
return traces;
}
@Override
public void stop() {
tds.clear();
}
};
ITransactionSampler transactionSampler2 = new ITransactionSampler() {
private final List<TransactionData> tds = new ArrayList<>();
@Override
public boolean noticeTransaction(TransactionData td) {
tds.add(td);
return true;
}
@Override
public List<TransactionTrace> harvest(String appName) {
List<TransactionTrace> traces = new ArrayList<>();
for (TransactionData td : tds) {
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
traces.add(trace);
}
return traces;
}
@Override
public void stop() {
tds.clear();
}
};
ttService.addTransactionTraceSampler(transactionSampler);
ttService.addTransactionTraceSampler(transactionSampler2);
TransactionData td = createTransactionData("/en/betting/Baseball/*", APP_NAME, 100L);
ttService.dispatcherTransactionFinished(td, null);
ttService.afterHarvest(APP_NAME);
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService(APP_NAME);
List<TransactionTrace> traces = rpmService.getTraces();
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/en/betting/Baseball/*", traces.get(0).getRequestUri());
Assert.assertEquals(100L, traces.get(0).getDuration());
traces.clear();
traces = rpmService.getTraces();
Assert.assertEquals(0, traces.size());
ttService.removeTransactionTraceSampler(transactionSampler);
ttService.removeTransactionTraceSampler(transactionSampler2);
ttService.dispatcherTransactionFinished(td, null);
ttService.afterHarvest(APP_NAME);
Assert.assertEquals(0, transactionSampler.harvest(APP_NAME).size());
Assert.assertEquals(0, transactionSampler2.harvest(APP_NAME).size());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method setup.
private void setup(boolean enabled, boolean isAttsEnabled, int size) throws Exception {
MockServiceManager manager = new MockServiceManager();
ServiceFactory.setServiceManager(manager);
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
Map<String, Object> events = new HashMap<>();
settings.put("transaction_events", events);
events.put("max_samples_stored", size);
events.put("enabled", enabled);
Map<String, Object> atts = new HashMap<>();
settings.put("attributes", atts);
atts.put("enabled", isAttsEnabled);
Map<String, Object> distributedTracing = new HashMap<>();
distributedTracing.put("enabled", true);
settings.put("distributed_tracing", distributedTracing);
Map<String, Object> spanConfig = new HashMap<>();
spanConfig.put("collect_span_events", true);
settings.put("span_events", spanConfig);
iAgentConfig = AgentConfigImpl.createAgentConfig(settings);
configService = ConfigServiceFactory.createConfigService(iAgentConfig, settings);
manager.setConfigService(configService);
TransactionTraceService transactionTraceService = new TransactionTraceService();
manager.setTransactionTraceService(transactionTraceService);
environmentService = new EnvironmentServiceImpl();
manager.setEnvironmentService(environmentService);
AttributesService attService = new AttributesService();
manager.setAttributesService(attService);
TransactionService transactionService = new TransactionService();
manager.setTransactionService(transactionService);
StatsService statsService = new StatsServiceImpl();
manager.setStatsService(statsService);
HarvestService harvestService = new MockHarvestService();
manager.setHarvestService(harvestService);
// manager.setTransactionEventsService(new TransactionEventsService(mockDistributedTraceIntrinsics));
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
Map<String, Object> connectInfo = new HashMap<>();
connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "1acct234");
connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "67890");
AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
distributedTraceService.connected(null, agentConfig);
manager.setDistributedTraceService(distributedTraceService);
rpmServiceManager = new MockRPMServiceManager();
rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmServiceManager.setRPMService(rpmService);
ErrorServiceImpl errorService = new ErrorServiceImpl(APP_NAME);
rpmService.setErrorService(errorService);
rpmServiceAppName2 = (MockRPMService) rpmServiceManager.getOrCreateRPMService(APP_NAME_2);
rpmServiceAppName2.setErrorService(new ErrorServiceImpl(APP_NAME_2));
mockDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
service = new TransactionEventsService(mockDistributedTraceIntrinsics);
manager.setTransactionEventsService(service);
manager.setRPMServiceManager(rpmServiceManager);
service.addHarvestableToService(APP_NAME);
service.doStart();
}
Aggregations