Search in sources :

Example 21 with MockRPMService

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

the class SqlTraceServiceTest method multipleTransactions.

@Test
public void multipleTransactions() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    createServiceManager(configMap);
    // run a transaction
    Tracer requestDispatcherTracer = startDispatcherTracer();
    long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run another transaction
    requestDispatcherTracer = startDispatcherTracer();
    long duration2 = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from duderino where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest
    MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
    List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(3, sqlTraces.size());
    long expectedDuration = TimeUnit.MILLISECONDS.convert(duration, TimeUnit.NANOSECONDS);
    long expectedDuration2 = TimeUnit.MILLISECONDS.convert(duration2, TimeUnit.NANOSECONDS);
    String expectedSql = "select * from dude where somevalue = ?";
    SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
    long expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
    SqlTrace sqlTrace = getSqlTrace(expectedId, sqlTraces);
    Assert.assertNotNull(sqlTrace);
    Assert.assertEquals(expectedId, sqlTrace.getId());
    Assert.assertEquals(expectedSql, sqlTrace.getQuery());
    Assert.assertEquals(4, sqlTrace.getCallCount());
    Assert.assertEquals((expectedDuration * 2) + (expectedDuration2 * 2), sqlTrace.getTotal());
    Assert.assertEquals(expectedDuration, sqlTrace.getMin());
    Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
    expectedSql = "select * from dudette where somevalue = ?";
    expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
    sqlTrace = getSqlTrace(expectedId, sqlTraces);
    Assert.assertNotNull(sqlTrace);
    Assert.assertEquals(expectedId, sqlTrace.getId());
    Assert.assertEquals(expectedSql, sqlTrace.getQuery());
    Assert.assertEquals(2, sqlTrace.getCallCount());
    Assert.assertEquals(expectedDuration + expectedDuration2, sqlTrace.getTotal());
    Assert.assertEquals(expectedDuration, sqlTrace.getMin());
    Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
    expectedSql = "select * from duderino where somevalue = ?";
    expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
    sqlTrace = getSqlTrace(expectedId, sqlTraces);
    Assert.assertNotNull(sqlTrace);
    Assert.assertEquals(expectedId, sqlTrace.getId());
    Assert.assertEquals(expectedSql, sqlTrace.getQuery());
    Assert.assertEquals(1, sqlTrace.getCallCount());
    Assert.assertEquals(expectedDuration2, sqlTrace.getTotal());
    Assert.assertEquals(expectedDuration2, sqlTrace.getMin());
    Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) MockHarvestService(com.newrelic.agent.MockHarvestService) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 22 with MockRPMService

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

the class SqlTraceServiceTest method multipleApps.

@Test
public void multipleApps() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    createServiceManager(configMap);
    // run a transaction in "Test" app
    Tracer requestDispatcherTracer = startDispatcherTracer("Test");
    long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    Transaction.getTransaction().setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, "Test");
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a transaction in "Test2" app
    requestDispatcherTracer = startDispatcherTracer("Test2");
    startSqlTracer("select * from dude2 where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude2 where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette2 where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    Transaction.getTransaction().setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, "Test2");
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest for "Test"
    MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
    mockharvestService.runHarvest("Test", new StatsEngineImpl());
    MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService("Test");
    List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(2, sqlTraces.size());
    // run a harvest for "Test2"
    mockharvestService.runHarvest("Test2", new StatsEngineImpl());
    mockRPMService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService("Test2");
    sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(2, sqlTraces.size());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 23 with MockRPMService

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

the class SqlTraceServiceTest method overSqlLimit.

@Test
public void overSqlLimit() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    createServiceManager(configMap);
    int sqlLimit = SlowQueryAggregatorImpl.SLOW_QUERY_LIMIT_PER_REPORTING_PERIOD;
    // run a transaction
    Tracer requestDispatcherTracer = startDispatcherTracer();
    for (int i = 0; i < sqlLimit * 2; i++) {
        String sql = "select * from dude where column" + i + " = 'cool'";
        long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1 + i, TimeUnit.MILLISECONDS);
        startSqlTracer(sql, duration).finish(Opcodes.RETURN, null);
    }
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest
    MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
    List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(sqlLimit, sqlTraces.size());
    SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
    for (int i = sqlLimit; i < sqlLimit * 2; i++) {
        String expectedSql = "select * from dude where column" + i + " = ?";
        long expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
        SqlTrace sqlTrace = getSqlTrace(expectedId, sqlTraces);
        Assert.assertNotNull(sqlTrace);
        long expectedDuration = getExplainThresholdInMillis() + 1 + i;
        Assert.assertEquals(expectedId, sqlTrace.getId());
        Assert.assertEquals(expectedSql, sqlTrace.getQuery());
        Assert.assertEquals(1, sqlTrace.getCallCount());
        Assert.assertEquals(expectedDuration, sqlTrace.getTotal());
        Assert.assertEquals(expectedDuration, sqlTrace.getMin());
        Assert.assertEquals(expectedDuration, sqlTrace.getMax());
    }
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) MockHarvestService(com.newrelic.agent.MockHarvestService) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 24 with MockRPMService

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

the class SqlTraceServiceTest method transactionTracerNotEnabled.

@Test
public void transactionTracerNotEnabled() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    Map<String, Object> ttConfigMap = new HashMap<>();
    configMap.put("transaction_tracer", ttConfigMap);
    ttConfigMap.put("enabled", false);
    createServiceManager(configMap);
    // run a transaction
    Tracer requestDispatcherTracer = startDispatcherTracer();
    long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest
    MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
    List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(0, sqlTraces.size());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 25 with MockRPMService

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

the class SqlTraceServiceTest method notOverExplainThreshold.

@Test
public void notOverExplainThreshold() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    createServiceManager(configMap);
    // run a transaction
    Tracer requestDispatcherTracer = startDispatcherTracer();
    long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis(), TimeUnit.MILLISECONDS);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest
    MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
    List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(0, sqlTraces.size());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

MockRPMService (com.newrelic.agent.MockRPMService)97 Test (org.junit.Test)59 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)44 MockServiceManager (com.newrelic.agent.MockServiceManager)39 MockHarvestService (com.newrelic.agent.MockHarvestService)30 HashMap (java.util.HashMap)28 TransactionService (com.newrelic.agent.TransactionService)26 ConfigService (com.newrelic.agent.config.ConfigService)21 MockCoreService (com.newrelic.agent.MockCoreService)20 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)18 HarvestService (com.newrelic.agent.HarvestService)17 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 ThreadService (com.newrelic.agent.ThreadService)15 StatsService (com.newrelic.agent.stats.StatsService)15 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)15 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)15 SqlTracer (com.newrelic.agent.tracers.SqlTracer)15 Tracer (com.newrelic.agent.tracers.Tracer)15 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)15 TransactionData (com.newrelic.agent.TransactionData)14