Search in sources :

Example 6 with IRPMService

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());
}
Also used : HashMap(java.util.HashMap) IRPMService(com.newrelic.agent.IRPMService) Test(org.junit.Test)

Example 7 with IRPMService

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);
}
Also used : HashMap(java.util.HashMap) IRPMService(com.newrelic.agent.IRPMService) Test(org.junit.Test)

Example 8 with IRPMService

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);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) IRPMService(com.newrelic.agent.IRPMService) JSONParser(org.json.simple.parser.JSONParser) Map(java.util.Map) Test(org.junit.Test)

Example 9 with IRPMService

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.");
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) TransactionService(com.newrelic.agent.TransactionService) IRPMService(com.newrelic.agent.IRPMService)

Example 10 with IRPMService

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);
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) MockServiceManager(com.newrelic.agent.MockServiceManager) IRPMService(com.newrelic.agent.IRPMService) RPMServiceManager(com.newrelic.agent.RPMServiceManager)

Aggregations

IRPMService (com.newrelic.agent.IRPMService)17 Test (org.junit.Test)11 HashMap (java.util.HashMap)9 AgentConfig (com.newrelic.agent.config.AgentConfig)4 MockServiceManager (com.newrelic.agent.MockServiceManager)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)1 RPMServiceManager (com.newrelic.agent.RPMServiceManager)1 TransactionService (com.newrelic.agent.TransactionService)1 ConfigServiceImpl (com.newrelic.agent.config.ConfigServiceImpl)1 ErrorService (com.newrelic.agent.errors.ErrorService)1 ClassTransformerService (com.newrelic.agent.instrumentation.ClassTransformerService)1 ServiceManager (com.newrelic.agent.service.ServiceManager)1 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)1 HttpError (com.newrelic.agent.transport.HttpError)1 JSONException (com.newrelic.agent.util.JSONException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1