use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class EnvironmentHolder method setupEnvironment.
public void setupEnvironment() throws Exception {
rpmService.setIsConnected(true);
IRPMService originalRpmService = originalServiceManager.getRPMServiceManager().getRPMService();
rpmService.setApplicationName(originalRpmService.getApplicationName());
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(environmentHolderSettingsGenerator.generateSettings());
Map<String, Object> properties = ImmutableMap.<String, Object>of("agent_config", ((BaseConfig) agentConfig).getProperties(), "collect_span_events", true);
((ConfigServiceImpl) ServiceFactory.getConfigService()).connected(rpmService, properties);
if (agentConfig.getDistributedTracingConfig().isEnabled()) {
((DistributedTraceServiceImpl) ServiceFactory.getDistributedTraceService()).connected(rpmService, agentConfig);
}
config = agentConfig;
// Set up now that new environment is in place
ServiceFactory.getTransactionService().addTransactionListener(transactionList);
transactionList.clear();
// We have to actually start the harvest service, even though typically tests call harvestNow(). This means
// the test will conflict with a real harvest if it takes more than about 30 seconds, possibly leading to
// flickers. We should probably change the design of the harvest service. Better yet, we should implement a
// better way to have custom configurations in functional tests and get rid of this messy class completely.
ServiceFactory.getHarvestService().startHarvest(rpmService);
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method fileChangeAndThenConnectDoesActuallyChangeConfig.
@Test
public void fileChangeAndThenConnectDoesActuallyChangeConfig() throws IOException {
ServiceManager mockServiceManager = mock(ServiceManager.class);
ClassTransformerService mockClassTransformerService = mock(ClassTransformerService.class);
when(mockServiceManager.getClassTransformerService()).thenReturn(mockClassTransformerService);
ServiceFactory.setServiceManager(mockServiceManager);
String appName = "Unit Test";
Map<String, Object> originalMap = ImmutableMap.<String, Object>of("app_name", appName);
File mockConfigFile = File.createTempFile("ConfigServiceTest", null);
try (OutputStream os = new FileOutputStream(mockConfigFile)) {
os.write(JSONObject.toJSONString(Collections.singletonMap("common", originalMap)).getBytes());
}
assertTrue(mockConfigFile.setLastModified(15L));
AgentConfig originalConfig = AgentConfigImpl.createAgentConfig(originalMap);
final Boolean[] circuitBreakerSetting = new Boolean[] { null };
assertTrue("Default circuitbreaker was expected to be true; it was apparently not.", originalConfig.getCircuitBreakerConfig().isEnabled());
ConfigServiceImpl target = new ConfigServiceImpl(originalConfig, mockConfigFile, originalMap, false);
target.addIAgentConfigListener(new AgentConfigListener() {
@Override
public void configChanged(String appName, AgentConfig agentConfig) {
circuitBreakerSetting[0] = agentConfig.getCircuitBreakerConfig().isEnabled();
}
});
// step 1: modify the file.
try (OutputStream os = new FileOutputStream(mockConfigFile)) {
os.write(JSONObject.toJSONString(Collections.singletonMap("common", ImmutableMap.of("app_name", appName, "circuitbreaker", Collections.singletonMap("enabled", false)))).getBytes());
}
assertTrue("unable to set the last modified time on the mock config file.", mockConfigFile.setLastModified(System.currentTimeMillis()));
target.afterHarvest(appName);
assertNotNull("circuitbreaker setting should have been set; it was not", circuitBreakerSetting[0]);
assertFalse("circuitbreaker setting has not changed from true to false; it should have!", circuitBreakerSetting[0]);
circuitBreakerSetting[0] = null;
// step 2: trigger connect.
IRPMService mockRPMService = mock(IRPMService.class);
when(mockRPMService.getApplicationName()).thenReturn(appName);
target.connected(mockRPMService, Collections.<String, Object>emptyMap());
// this should not have reverted to the original contents.
assertNotNull("circuitbreaker setting should have been set; it was not", circuitBreakerSetting[0]);
assertFalse("circuitbreaker setting has changed from false; it should not have!", circuitBreakerSetting[0]);
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class StartProfilerCommandTest method validArgsThreadProfilerV2NullDefaults.
@Test
public void validArgsThreadProfilerV2NullDefaults() throws CommandException {
IRPMService rpmService = null;
final long profileId = 1L;
final long duration = 60000L;
final long samplePeriod = 500L;
final boolean onlyRunnableThreads = true;
final boolean onlyRequestThreads = true;
final String profilerFormat = "v2";
final Object profileAgentCode = null;
Map<String, Object> args = new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put("profile_id", profileId);
put("sample_period", samplePeriod);
put("duration", duration);
put("only_runnable_threads", onlyRunnableThreads);
put("only_request_threads", onlyRequestThreads);
put("profiler_format", profilerFormat);
put("profile_agent_code", profileAgentCode);
}
};
startProfilerCommand.process(rpmService, args);
Assert.assertEquals(duration * 1000L, profilerParameters.getDurationInMillis().longValue());
Assert.assertEquals(samplePeriod * 1000L, profilerParameters.getSamplePeriodInMillis().longValue());
Assert.assertEquals(profileId, profilerParameters.getProfileId().longValue());
Assert.assertEquals(onlyRunnableThreads, profilerParameters.isRunnablesOnly());
Assert.assertEquals(onlyRequestThreads, profilerParameters.isOnlyRequestThreads());
Assert.assertEquals(false, profilerParameters.isProfileAgentThreads());
Assert.assertEquals(profilerFormat, profilerParameters.getProfilerFormat());
Assert.assertNull(profilerParameters.getKeyTransaction());
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class StartProfilerCommandTest method badSamplePeriod.
@Test(expected = CommandException.class)
public void badSamplePeriod() throws CommandException {
IRPMService rpmService = null;
Map<String, Object> args = new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put("profile_id", 1L);
put("duration", 120.0f);
put("sample_period", "dog");
}
};
startProfilerCommand.process(rpmService, args);
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class StartProfilerCommandTest method samplePeriodGreaterThanDuration.
@Test(expected = CommandException.class)
public void samplePeriodGreaterThanDuration() throws CommandException {
IRPMService rpmService = null;
Map<String, Object> args = new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put("profile_id", 1L);
put("duration", 1000L);
put("sample_period", 2000L);
}
};
startProfilerCommand.process(rpmService, args);
}
Aggregations