Search in sources :

Example 26 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class AgentHelper method mockAgentConfig.

public static AgentConfig mockAgentConfig() {
    ServiceManager serviceManger = Mockito.spy(ServiceFactory.getServiceManager());
    ConfigService configService = Mockito.spy(serviceManger.getConfigService());
    Mockito.doReturn(configService).when(serviceManger).getConfigService();
    ServiceFactory.setServiceManager(serviceManger);
    AgentConfig agentConfig = Mockito.spy(configService.getDefaultAgentConfig());
    Mockito.doReturn(agentConfig).when(configService).getDefaultAgentConfig();
    Mockito.doReturn(agentConfig).when(configService).getAgentConfig(anyString());
    return agentConfig;
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) ServiceManager(com.newrelic.agent.service.ServiceManager)

Example 27 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class AgentHelper method mockAgentConfig.

public static AgentConfig mockAgentConfig(TransactionTracerConfig transactionTracerConfig) {
    ServiceManager serviceManger = Mockito.spy(ServiceFactory.getServiceManager());
    ConfigService configService = Mockito.spy(serviceManger.getConfigService());
    Mockito.doReturn(configService).when(serviceManger).getConfigService();
    ServiceFactory.setServiceManager(serviceManger);
    AgentConfig agentConfig = Mockito.spy(configService.getDefaultAgentConfig());
    Mockito.doReturn(agentConfig).when(configService).getDefaultAgentConfig();
    Mockito.doReturn(agentConfig).when(configService).getAgentConfig(anyString());
    Mockito.doReturn(transactionTracerConfig).when(configService).getTransactionTracerConfig(anyString());
    return agentConfig;
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) ServiceManager(com.newrelic.agent.service.ServiceManager)

Example 28 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class TracedErrorTest method after.

@AfterClass
public static void after() throws Exception {
    ServiceManager serviceManager = ServiceFactory.getServiceManager();
    if (serviceManager != null) {
        serviceManager.stop();
    }
    ServiceFactory.setServiceManager(null);
}
Also used : ServiceManager(com.newrelic.agent.service.ServiceManager) AfterClass(org.junit.AfterClass)

Example 29 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class DefaultSqlTracerTest method getJSON.

private String getJSON(RecordSql recordSql) {
    MockServiceManager serviceManager = new MockServiceManager();
    serviceManager.setConfigService(new MockConfigService(AgentConfigFactory.createAgentConfig(Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap(), null)));
    ServiceManager originalServiceManager = ServiceFactory.getServiceManager();
    try {
        ServiceFactory.setServiceManager(serviceManager);
        Transaction transaction = mock(Transaction.class);
        TransactionActivity txa = mock(TransactionActivity.class);
        when(transaction.getTransactionActivity()).thenReturn(txa);
        when(txa.getTransaction()).thenReturn(transaction);
        TransactionTracerConfig ttConfig = mock(TransactionTracerConfig.class);
        when(ttConfig.getRecordSql()).thenReturn(recordSql.toString());
        when(transaction.getTransactionTracerConfig()).thenReturn(ttConfig);
        ClassMethodSignature sig = new ClassMethodSignature("", "", "");
        DefaultSqlTracer tracer = new DefaultSqlTracer(transaction, sig, new Object(), new SimpleMetricNameFormat("BoundedConcurrentCacheTest"), TracerFlags.GENERATE_SCOPED_METRIC);
        tracer.setRawSql("select * from user where ssn = ?");
        tracer.setParams(new Object[] { 666666666 });
        Object sqlObject = tracer.getSql();
        return sqlObject.toString();
    } finally {
        ServiceFactory.setServiceManager(originalServiceManager);
    }
}
Also used : ServiceManager(com.newrelic.agent.service.ServiceManager) JSONObject(org.json.simple.JSONObject) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 30 with ServiceManager

use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.

the class BasicRequestDispatcherTracerTest method statusCodePolicyProperty.

@Test
public void statusCodePolicyProperty() throws Exception {
    ServiceManager old = ServiceFactory.getServiceManager();
    Map<String, Object> configMap = createConfigMap(0);
    configMap.put(HiddenProperties.LAST_STATUS_CODE_POLICY, false);
    createServiceManager(AgentConfigImpl.createAgentConfig(configMap), configMap);
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.setStatus(404);
    dispatcher.setStatus(200);
    Assert.assertEquals(404, dispatcher.getStatus());
    ServiceFactory.getServiceManager().stop();
    ServiceFactory.setServiceManager(old);
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Aggregations

ServiceManager (com.newrelic.agent.service.ServiceManager)31 MockServiceManager (com.newrelic.agent.MockServiceManager)18 Test (org.junit.Test)17 HashMap (java.util.HashMap)12 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)5 ConfigService (com.newrelic.agent.config.ConfigService)5 MockRPMService (com.newrelic.agent.MockRPMService)4 AgentConfig (com.newrelic.agent.config.AgentConfig)4 PointCutConfiguration (com.newrelic.agent.instrumentation.PointCutConfiguration)4 SpringPointCut (com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut)4 HarvestServiceImpl (com.newrelic.agent.HarvestServiceImpl)3 RPMServiceManager (com.newrelic.agent.RPMServiceManager)3 ServiceManagerImpl (com.newrelic.agent.service.ServiceManagerImpl)2 JSONObject (org.json.simple.JSONObject)2 After (org.junit.After)2 ForceDisconnectException (com.newrelic.agent.ForceDisconnectException)1 IRPMService (com.newrelic.agent.IRPMService)1 RPMService (com.newrelic.agent.RPMService)1 Transaction (com.newrelic.agent.Transaction)1 BrowserServiceImpl (com.newrelic.agent.browser.BrowserServiceImpl)1