use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class StartProfilerCommandTest method validRequiredArgs.
@Test
public void validRequiredArgs() throws CommandException {
IRPMService rpmService = null;
final long profileId = 1L;
final long duration = 60000L;
final long samplePeriod = 500L;
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);
}
};
startProfilerCommand.process(rpmService, args);
Assert.assertEquals(profileId, profilerParameters.getProfileId().longValue());
Assert.assertEquals(duration * 1000L, profilerParameters.getDurationInMillis().longValue());
Assert.assertEquals(samplePeriod * 1000L, profilerParameters.getSamplePeriodInMillis().longValue());
Assert.assertEquals(false, profilerParameters.isRunnablesOnly());
Assert.assertEquals(false, profilerParameters.isOnlyRequestThreads());
Assert.assertEquals(false, profilerParameters.isProfileAgentThreads());
Assert.assertNull(profilerParameters.getKeyTransaction());
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class StartProfilerCommandTest method missingSamplePeriod.
@Test(expected = CommandException.class)
public void missingSamplePeriod() 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", 1);
}
};
startProfilerCommand.process(rpmService, args);
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class NormalizationServiceImplTest method test.
@Test
public void test() throws IOException, ParseException {
String path = '/' + NormalizationServiceImplTest.class.getPackage().getName().replace('.', '/') + "/segment_terms.txt";
String json = new String(Streams.read(NormalizationServiceImplTest.class.getResourceAsStream(path), true));
Map data = (Map) new JSONParser().parse(json);
NormalizationServiceImpl service = new NormalizationServiceImpl();
IRPMService rpmService = Mockito.mock(IRPMService.class);
AgentConfig config = AgentConfigImpl.createAgentConfig(data);
service.connected(rpmService, config);
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class CoreServiceImpl method jvmShutdown.
private void jvmShutdown(long startTime) {
getLogger().fine("Agent JVM shutdown hook: enter.");
AgentConfig config = ServiceFactory.getConfigService().getDefaultAgentConfig();
// Only add the "transaction wait" shutdown hook if one has been configured
if (config.waitForTransactionsInMillis() > 0) {
getLogger().fine("Agent JVM shutdown hook: waiting for transactions to finish");
// While there are still transactions in progress and we haven't hit the configured timeout keep
// waiting and checking for the transactions to finish before allowing the shutdown to continue.
long finishTime = System.currentTimeMillis() + config.waitForTransactionsInMillis();
TransactionService txService = ServiceFactory.getTransactionService();
while (txService.getTransactionsInProgress() > 0 && System.currentTimeMillis() < finishTime) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
getLogger().fine("Agent JVM shutdown hook: transactions finished");
}
if (config.isSendDataOnExit() && ((System.currentTimeMillis() - startTime) >= config.getSendDataOnExitThresholdInMillis())) {
// Grab all RPMService instances (may be multiple with auto_app_naming enabled) and harvest them
List<IRPMService> rpmServices = ServiceFactory.getRPMServiceManager().getRPMServices();
for (IRPMService rpmService : rpmServices) {
rpmService.harvestNow();
}
}
getLogger().info("JVM is shutting down");
shutdown();
getLogger().fine("Agent JVM shutdown hook: done.");
}
use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.
the class NewRelicApiImplementationTest method mockOutServices.
private void mockOutServices() {
errorService = Mockito.mock(ErrorService.class);
IRPMService rpmService = Mockito.mock(IRPMService.class);
Mockito.when(rpmService.getErrorService()).thenReturn(errorService);
RPMServiceManager rpmServiceManager = Mockito.mock(RPMServiceManager.class);
Mockito.when(rpmServiceManager.getRPMService()).thenReturn(rpmService);
MockServiceManager sm = new MockServiceManager();
sm.setRPMServiceManager(rpmServiceManager);
ServiceFactory.setServiceManager(sm);
}
Aggregations