Search in sources :

Example 1 with NoOpTrackingSqlTracer

use of com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer in project newrelic-java-agent by newrelic.

the class SlowQueryAggregatorImplTest method createTransactionData.

private TransactionData createTransactionData(String appName, String transactionName, long durationInMillis) {
    AgentConfig agentConfig = ServiceFactory.getConfigService().getDefaultAgentConfig();
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(true);
    MockDispatcherTracer rootTracer = new MockDispatcherTracer();
    rootTracer.setDurationInMilliseconds(durationInMillis);
    rootTracer.setStartTime(System.nanoTime());
    rootTracer.setEndTime(rootTracer.getStartTime() + TimeUnit.NANOSECONDS.convert(durationInMillis, TimeUnit.MILLISECONDS));
    TransactionTracerConfig ttconf = Mockito.mock(TransactionTracerConfig.class);
    when(ttconf.isEnabled()).thenReturn(true);
    when(ttconf.getInsertSqlMaxLength()).thenReturn(10 * 1000);
    Transaction tx = mock(Transaction.class);
    TransactionActivity txa = mock(TransactionActivity.class);
    when(txa.getTransaction()).thenReturn(tx);
    when(tx.getTransactionActivity()).thenReturn(txa);
    when(tx.getTransactionTracerConfig()).thenReturn(ttconf);
    List<SlowQueryInfo> tracers = new ArrayList<>(1);
    String sql = "select * from TABLE" + Integer.toString(count.incrementAndGet()) + " where Time = 'nigh'";
    String obfuscatedSql = sqlObfuscator.obfuscateSql(sql);
    SqlTracer sqlTracer = new NoOpTrackingSqlTracer(tx, sql);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(null, sqlTracer, sql, obfuscatedSql, agentConfig.getSqlTraceConfig());
    tracers.add(slowQueryInfo);
    SlowQueryListener slowQueryListener = Mockito.mock(SlowQueryListener.class);
    org.mockito.Mockito.when(slowQueryListener.getSlowQueries()).thenReturn(tracers);
    return new TransactionDataTestBuilder(appName, agentConfig, rootTracer).setTx(tx).setRequestUri(transactionName).setFrontendMetricName(transactionName).setSlowQueryListener(slowQueryListener).build();
}
Also used : MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) ArrayList(java.util.ArrayList) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionActivity(com.newrelic.agent.TransactionActivity) AgentConfig(com.newrelic.agent.config.AgentConfig) Transaction(com.newrelic.agent.Transaction) NoOpTrackingSqlTracer(com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer) NoOpTrackingSqlTracer(com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Aggregations

MockDispatcher (com.newrelic.agent.MockDispatcher)1 MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)1 Transaction (com.newrelic.agent.Transaction)1 TransactionActivity (com.newrelic.agent.TransactionActivity)1 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 TransactionTracerConfig (com.newrelic.agent.config.TransactionTracerConfig)1 NoOpTrackingSqlTracer (com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 ArrayList (java.util.ArrayList)1