use of com.newrelic.agent.bridge.datastore.ConnectionFactory in project newrelic-java-agent by newrelic.
the class DatabaseServiceTest method createConnectionFactory.
private ConnectionFactory createConnectionFactory(final Connection connection) {
final JdbcDatabaseVendor jdbcDatabaseVendor = new JdbcDatabaseVendor("MySQL", "database", true) {
@Override
public DatastoreVendor getDatastoreVendor() {
return DatastoreVendor.MySQL;
}
};
ConnectionFactory connectionFactory = new ConnectionFactory() {
@Override
public Connection getConnection() throws SQLException {
return connection;
}
@Override
public DatabaseVendor getDatabaseVendor() {
return jdbcDatabaseVendor;
}
};
return connectionFactory;
}
use of com.newrelic.agent.bridge.datastore.ConnectionFactory 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 com.newrelic.agent.bridge.datastore.ConnectionFactory in project newrelic-java-agent by newrelic.
the class DatabaseService method runExplainPlan.
public void runExplainPlan(SqlTracer sqlTracer) {
ExplainPlanExecutor explainExecutor = sqlTracer.getExplainPlanExecutor();
ConnectionFactory connectionFactory = sqlTracer.getConnectionFactory();
if (explainExecutor == null || connectionFactory == null) {
Agent.LOG.finest("Unable to execute query for explain plan");
return;
}
if (sqlTracer.hasExplainPlan()) {
return;
}
runExplainPlan(explainExecutor, connectionFactory);
}
use of com.newrelic.agent.bridge.datastore.ConnectionFactory in project newrelic-java-agent by newrelic.
the class DatabaseServiceTest method instanceSlowSqlAttribute.
@Test
public void instanceSlowSqlAttribute() throws Exception {
Map<String, Object> configMap = createStagingMap();
Map<String, Object> ttConfigMap = createMap();
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
ttConfigMap.put(TransactionTracerConfigImpl.EXPLAIN_THRESHOLD, 0);
configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttConfigMap);
Map<String, Object> dsConfigMap = createMap();
dsConfigMap.put(DatastoreConfigImpl.INSTANCE_REPORTING, true);
configMap.put(AgentConfigImpl.DATASTORE_TRACER, dsConfigMap);
Map<String, Object> stConfigMap = createMap();
stConfigMap.put(SqlTraceConfigImpl.ENABLED, true);
configMap.put(AgentConfigImpl.SLOW_SQL, stConfigMap);
createServiceManager(configMap);
final Connection connection = Mockito.mock(Connection.class);
final String databaseName = "myDatabase";
Mockito.when(connection.getCatalog()).thenReturn(databaseName);
DatastoreInstanceDetection.detectConnectionAddress();
InetSocketAddress address = new InetSocketAddress("address", 8080);
DatastoreInstanceDetection.associateAddress(connection, address);
DatastoreInstanceDetection.stopDetectingConnectionAddress();
Transaction transaction = Transaction.getTransaction(true);
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
TestDefaultSqlTracer tracer = new TestDefaultSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
tracer.setRawSql("select * from metrics");
tracer.provideConnection(connection);
ConnectionFactory connectionFactory = createConnectionFactory(connection);
tracer.setConnectionFactory(connectionFactory);
AgentHelper.setLastTracer(tracer);
tracer.finish(Opcodes.ARETURN, new DummyResultSet());
Assert.assertEquals(address.getHostName(), tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_HOST));
Assert.assertEquals(String.valueOf(address.getPort()), tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_PORT_PATH_OR_ID));
Assert.assertEquals(databaseName, tracer.getAgentAttribute(DatastoreMetrics.DB_INSTANCE));
Transaction.clearTransaction();
}
Aggregations