Search in sources :

Example 6 with ConnectionConfigListener

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

the class DatabaseTest method usePreparedStatement.

@Test
public void usePreparedStatement() throws Exception {
    final String applicationName = "App";
    ((ConnectionConfigListener) ServiceFactory.getConfigService()).connected(ServiceFactory.getRPMServiceManager().getRPMService(), new HashMap<String, Object>() {

        {
            put("transaction_tracer.record_sql", "raw");
        }
    });
    AgentConfig agentConfig = ServiceFactory.getConfigService().getAgentConfig(null);
    Assert.assertEquals(SqlObfuscator.RAW_SETTING, agentConfig.getTransactionTracerConfig().getRecordSql());
    Assert.assertEquals(SqlObfuscator.RAW_SETTING, agentConfig.getRequestTransactionTracerConfig().getRecordSql());
    HttpServlet servlet = new PreparedStatementServlet();
    AgentHelper.invokeServlet(servlet, "", applicationName, "/database/test");
    AgentHelper.verifyDatastoreMetrics(AgentHelper.getMetrics(), DatastoreVendor.Derby, "test", "select");
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) HttpServlet(javax.servlet.http.HttpServlet) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) Test(org.junit.Test)

Example 7 with ConnectionConfigListener

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

the class ConfigServiceTest method badServerData.

@Test
public void badServerData() throws Exception {
    Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
    createServiceManager(configMap);
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    Map<String, Object> data = new HashMap<>();
    Map<String, Object> agentData = new HashMap<>();
    data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
    data.put(AgentConfigImpl.APDEX_T, 0.5d);
    data.put(AgentConfigFactory.COLLECT_TRACES, true);
    agentData.put(AgentConfigFactory.TRANSACTION_TRACER_PREFIX + TransactionTracerConfigImpl.ENABLED, "bad");
    agentData.put(AgentConfigFactory.ERROR_COLLECTOR_PREFIX + ErrorCollectorConfigImpl.ENABLED, !ErrorCollectorConfigImpl.DEFAULT_ENABLED);
    connectionConfigListener.connected(rpmService, data);
    ConfigService configService = ServiceFactory.getConfigService();
    assertFalse(configService.getAgentConfig(null).getTransactionTracerConfig().isEnabled());
    assertEquals(ErrorCollectorConfigImpl.DEFAULT_ENABLED, configService.getAgentConfig(null).getErrorCollectorConfig().isEnabled());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) JSONObject(org.json.simple.JSONObject) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 8 with ConnectionConfigListener

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

the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordApdexMetrics.

@Test
public void requestXStartHeaderRecordApdexMetrics() throws Exception {
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    rpmService.setEverConnected(true);
    Map<String, Object> data = new HashMap<>();
    data.put(AgentConfigImpl.APDEX_T, 6.0d);
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    connectionConfigListener.connected(rpmService, data);
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 24005));
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.getTransaction().getRootTracer().finish(0, null);
    StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(APP_NAME);
    ApdexStats apdexStats = statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX));
    Assert.assertEquals(1, apdexStats.getApdexFrustrating());
    apdexStats = statsEngine.getApdexStats(MetricName.create("Apdex/Uri/Unknown"));
    Assert.assertEquals(1, apdexStats.getApdexFrustrating());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) ApdexStats(com.newrelic.agent.stats.ApdexStats) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

ConnectionConfigListener (com.newrelic.agent.ConnectionConfigListener)8 Test (org.junit.Test)8 MockRPMService (com.newrelic.agent.MockRPMService)6 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)6 HashMap (java.util.HashMap)5 JSONObject (org.json.simple.JSONObject)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)2 ApdexStats (com.newrelic.agent.stats.ApdexStats)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 HttpServlet (javax.servlet.http.HttpServlet)2 MockHarvestService (com.newrelic.agent.MockHarvestService)1 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1