Search in sources :

Example 1 with RPMServiceManager

use of com.newrelic.agent.RPMServiceManager in project newrelic-java-agent by newrelic.

the class NoticeErrorAttributesTest method testNoticeErrorAPIFirstCallWins.

@Test
public void testNoticeErrorAPIFirstCallWins() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("test.foo", "1");
        impl.noticeError("hello", atts);
        Map<String, String> atts2 = new HashMap<>();
        atts.put("test.bar", "2");
        impl.noticeError("hello", atts2);
        Set<String> expected = Sets.newHashSet("test.foo");
        verifyOutput(t.getErrorAttributes(), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 2 with RPMServiceManager

use of com.newrelic.agent.RPMServiceManager in project newrelic-java-agent by newrelic.

the class HighSecurityAttributesTest method testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIMessage.

@Test
public void testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIMessage() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        settings.put("high_security", Boolean.TRUE);
        enableBrowser(settings);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("abc.thread", "1");
        atts.put("request.many", "1");
        atts.put("message.many", "1");
        atts.put("request.parameters.foo", "1");
        atts.put("request.parameters.bar", "1");
        atts.put("message.parameters.foo", "1");
        atts.put("message.parameters.bar", "1");
        impl.noticeError("hello", atts);
        // user attributes should be off
        Set<String> expected = new HashSet<>();
        verifyOutput(service.filterErrorEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionTraceAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterBrowserAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterSpanEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionSegmentAttributes(APP_NAME, t.getErrorAttributes()), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with RPMServiceManager

use of com.newrelic.agent.RPMServiceManager in project newrelic-java-agent by newrelic.

the class JarCollectorServiceImplTest method before.

@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    RPMServiceManager rpmServiceManager = mock(RPMServiceManager.class);
    when(rpmServiceManager.getOrCreateRPMService(anyString())).thenReturn(rpmService);
    ServiceManager mockServiceManager = mock(ServiceManager.class);
    when(mockServiceManager.getRPMServiceManager()).thenReturn(rpmServiceManager);
    ServiceFactory.setServiceManager(mockServiceManager);
}
Also used : RPMServiceManager(com.newrelic.agent.RPMServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) RPMServiceManager(com.newrelic.agent.RPMServiceManager) Before(org.junit.Before)

Example 4 with RPMServiceManager

use of com.newrelic.agent.RPMServiceManager 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)

Example 5 with RPMServiceManager

use of com.newrelic.agent.RPMServiceManager in project newrelic-java-agent by newrelic.

the class HighSecurityAttributesTest method testHighSecurityOffWithOtherDefaultsThroughNoticeErrorAPIMessage.

@Test
public void testHighSecurityOffWithOtherDefaultsThroughNoticeErrorAPIMessage() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        settings.put("high_security", Boolean.FALSE);
        enableBrowser(settings);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("abc.thread", "1");
        atts.put("request.many", "1");
        atts.put("message.many", "1");
        atts.put("request.parameters.foo", "1");
        atts.put("request.parameters.bar", "1");
        atts.put("message.parameters.foo", "1");
        atts.put("message.parameters.bar", "1");
        impl.noticeError("hello", atts);
        // user attributes should be off
        Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many");
        verifyOutput(service.filterErrorEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionTraceAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterBrowserAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterSpanEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionSegmentAttributes(APP_NAME, t.getErrorAttributes()), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Aggregations

RPMServiceManager (com.newrelic.agent.RPMServiceManager)7 RPMService (com.newrelic.agent.RPMService)5 ErrorService (com.newrelic.agent.errors.ErrorService)5 Test (org.junit.Test)5 Transaction (com.newrelic.agent.Transaction)4 TransactionService (com.newrelic.agent.TransactionService)4 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)4 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)4 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)4 NewRelicApiImplementation (com.newrelic.api.agent.NewRelicApiImplementation)4 HashMap (java.util.HashMap)4 MockServiceManager (com.newrelic.agent.MockServiceManager)2 IRPMService (com.newrelic.agent.IRPMService)1 ServiceManager (com.newrelic.agent.service.ServiceManager)1 JfrRecorderException (com.newrelic.jfr.daemon.JfrRecorderException)1 Java10IncompatibleTest (com.newrelic.test.marker.Java10IncompatibleTest)1 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)1 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1