Search in sources :

Example 1 with DummyConnection

use of sql.DummyConnection in project newrelic-java-agent by newrelic.

the class SqlTraceServiceTest method startSqlTracer.

private SqlTracer startSqlTracer(final String sql, final long duration) throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {

        @Override
        public long getDuration() {
            return duration;
        }

        @Override
        public Object getSql() {
            return sql;
        }
    };
    sqlTracer.setConnectionFactory(new ConnectionFactory() {

        @Override
        public Connection getConnection() throws SQLException {
            return null;
        }

        @Override
        public DatabaseVendor getDatabaseVendor() {
            return UnknownDatabaseVendor.INSTANCE;
        }
    });
    sqlTracer.setRawSql(sql);
    tx.getTransactionActivity().tracerStarted(sqlTracer);
    return sqlTracer;
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) UnknownDatabaseVendor(com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 2 with DummyConnection

use of sql.DummyConnection in project newrelic-java-agent by newrelic.

the class DatabaseTest method show.

@Test
public void show() throws Exception {
    Statement stmt = new DummyStatement(new DummyConnection());
    stmt.executeQuery("show tables");
    Set<String> metrics = AgentHelper.getMetrics(AgentHelper.getDefaultStatsEngine());
    for (String metric : metrics) {
        if (metric.startsWith("Database") && metric.endsWith("show")) {
            Assert.fail();
        }
    }
}
Also used : DummyStatement(sql.DummyStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) DummyStatement(sql.DummyStatement) Test(org.junit.Test)

Example 3 with DummyConnection

use of sql.DummyConnection in project newrelic-java-agent by newrelic.

the class RequestUriConfigTests method startSqlTracer.

private SqlTracer startSqlTracer(final String sql, final long duration) throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {

        @Override
        public long getDuration() {
            return duration;
        }

        @Override
        public Object getSql() {
            return sql;
        }
    };
    sqlTracer.setConnectionFactory(new ConnectionFactory() {

        @Override
        public Connection getConnection() {
            return null;
        }

        @Override
        public DatabaseVendor getDatabaseVendor() {
            return UnknownDatabaseVendor.INSTANCE;
        }
    });
    sqlTracer.setRawSql(sql);
    tx.getTransactionActivity().tracerStarted(sqlTracer);
    return sqlTracer;
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) UnknownDatabaseVendor(com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 4 with DummyConnection

use of sql.DummyConnection in project newrelic-java-agent by newrelic.

the class RequestUriConfigTests method startTracer.

private DefaultTracer startTracer() throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    DefaultTracer tracer = new OtherRootTracer(tx, sig, statement, new SimpleMetricNameFormat("metric", "segment", "some uri")) {

        @Override
        public long getDuration() {
            return 100000;
        }
    };
    tx.getTransactionActivity().tracerStarted(tracer);
    return tracer;
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 5 with DummyConnection

use of sql.DummyConnection in project newrelic-java-agent by newrelic.

the class DefaultSqlTracerTest method newTracer.

private DefaultSqlTracer newTracer(String sql) throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction transaction = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    DefaultSqlTracer result = new DefaultSqlTracer(transaction, sig, statement, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
    result.setRawSql(sql);
    // prevent "Inconsistent state! ..." errors
    AgentHelper.setLastTracer(result);
    return result;
}
Also used : Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Aggregations

Statement (java.sql.Statement)5 DummyConnection (sql.DummyConnection)5 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)4 Transaction (com.newrelic.agent.Transaction)3 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)3 ConnectionFactory (com.newrelic.agent.bridge.datastore.ConnectionFactory)2 DatabaseVendor (com.newrelic.agent.bridge.datastore.DatabaseVendor)2 UnknownDatabaseVendor (com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor)2 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)2 SqlTracer (com.newrelic.agent.tracers.SqlTracer)2 Connection (java.sql.Connection)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Test (org.junit.Test)1 DummyStatement (sql.DummyStatement)1