Search in sources :

Example 1 with AgentConfigListener

use of com.newrelic.agent.config.AgentConfigListener in project newrelic-java-agent by newrelic.

the class SpanEventsServiceFactoryTest method testBuildPicksStorageBackend_infiniteTracing.

@Test
public void testBuildPicksStorageBackend_infiniteTracing() throws Exception {
    when(agentConfig.getApplicationName()).thenReturn(APP_NAME);
    when(infiniteTracingConfig.isEnabled()).thenReturn(true);
    when(spanEventsConfig.isEnabled()).thenReturn(true);
    SpanEventsService service = SpanEventsServiceFactory.builder().configService(configService).rpmServiceManager(rpmServiceManager).infiniteTracingConsumer(infTracingConsumer).transactionService(transactionService).build();
    service.storeEvent(event);
    verify(infTracingConsumer).accept(event);
    verify(reservoir, never()).add(event);
    ArgumentCaptor<AgentConfigListener> configListener = ArgumentCaptor.forClass(AgentConfigListener.class);
    ArgumentCaptor<TransactionListener> transactionListener = ArgumentCaptor.forClass(TransactionListener.class);
    verify(configService, times(2)).addIAgentConfigListener(configListener.capture());
    verify(transactionService).addTransactionListener(transactionListener.capture());
    assertSame(configListener.getValue(), service);
    assertSame(transactionListener.getValue(), service);
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) AgentConfigListener(com.newrelic.agent.config.AgentConfigListener) Test(org.junit.Test)

Example 2 with AgentConfigListener

use of com.newrelic.agent.config.AgentConfigListener in project newrelic-java-agent by newrelic.

the class SpanEventsServiceFactoryTest method testBuildPicksStorageBackend_collector.

@Test
public void testBuildPicksStorageBackend_collector() throws Exception {
    when(agentConfig.getApplicationName()).thenReturn(APP_NAME);
    when(infiniteTracingConfig.isEnabled()).thenReturn(false);
    when(spanEventsConfig.isEnabled()).thenReturn(true);
    when(reservoirManager.getOrCreateReservoir(any())).thenReturn(reservoir);
    SpanEventsService service = SpanEventsServiceFactory.builder().configService(configService).rpmServiceManager(rpmServiceManager).infiniteTracingConsumer(infTracingConsumer).transactionService(transactionService).reservoirManager(reservoirManager).build();
    service.storeEvent(event);
    verify(reservoir).add(event);
    verify(infTracingConsumer, never()).accept(event);
    ArgumentCaptor<AgentConfigListener> configListener = ArgumentCaptor.forClass(AgentConfigListener.class);
    ArgumentCaptor<TransactionListener> transactionListener = ArgumentCaptor.forClass(TransactionListener.class);
    verify(configService, times(2)).addIAgentConfigListener(configListener.capture());
    verify(transactionService).addTransactionListener(transactionListener.capture());
    assertSame(configListener.getValue(), service);
    assertSame(transactionListener.getValue(), service);
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) AgentConfigListener(com.newrelic.agent.config.AgentConfigListener) Test(org.junit.Test)

Example 3 with AgentConfigListener

use of com.newrelic.agent.config.AgentConfigListener in project newrelic-java-agent by newrelic.

the class DatabaseServiceTest method configChanged.

@Test
public void configChanged() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    Map<String, Object> ttConfigMap = createMap();
    ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
    configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttConfigMap);
    MockServiceManager serviceManager = createServiceManager(configMap);
    MockConfigService configService = new MockConfigService(null);
    AgentConfig agentConfig = AgentConfigFactory.createAgentConfig(configMap, null, null);
    configService.setAgentConfig(agentConfig);
    serviceManager.setConfigService(configService);
    DatabaseService dbService = ServiceFactory.getDatabaseService();
    SqlObfuscator sqlObfuscator = dbService.getSqlObfuscator(APP_NAME);
    Assert.assertTrue(sqlObfuscator.isObfuscating());
    configMap = createStagingMap();
    ttConfigMap = createMap();
    configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttConfigMap);
    ttConfigMap.put(TransactionTracerConfigImpl.RECORD_SQL, SqlObfuscator.OFF_SETTING);
    agentConfig = AgentConfigFactory.createAgentConfig(configMap, null, null);
    configService.setAgentConfig(agentConfig);
    ((AgentConfigListener) dbService).configChanged(APP_NAME, agentConfig);
    sqlObfuscator = dbService.getSqlObfuscator(APP_NAME);
    Assert.assertFalse(sqlObfuscator.isObfuscating());
    Assert.assertNull(sqlObfuscator.obfuscateSql("select * from employees where id=737366255"));
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) MockServiceManager(com.newrelic.agent.MockServiceManager) DefaultSqlObfuscator(com.newrelic.agent.database.SqlObfuscator.DefaultSqlObfuscator) AgentConfigListener(com.newrelic.agent.config.AgentConfigListener) MockConfigService(com.newrelic.agent.MockConfigService) Test(org.junit.Test)

Aggregations

AgentConfigListener (com.newrelic.agent.config.AgentConfigListener)3 Test (org.junit.Test)3 TransactionListener (com.newrelic.agent.TransactionListener)2 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)2 MockConfigService (com.newrelic.agent.MockConfigService)1 MockServiceManager (com.newrelic.agent.MockServiceManager)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 DefaultSqlObfuscator (com.newrelic.agent.database.SqlObfuscator.DefaultSqlObfuscator)1