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;
}
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();
}
}
}
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;
}
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;
}
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;
}
Aggregations