Add Oracle support and fix muzzle.

This commit is contained in:
Tyler Benson 2019-06-06 18:03:56 -07:00
parent 6100443443
commit ec60d679d6
7 changed files with 397 additions and 174 deletions

View File

@ -260,7 +260,10 @@ public class ReferenceCreator extends ClassVisitor {
// * DONE field-source class (descriptor)
// * DONE field-source visibility from this point (PRIVATE?)
final Type ownerType = Type.getType("L" + owner + ";");
final Type ownerType =
owner.startsWith("[")
? underlyingType(Type.getType(owner))
: Type.getType("L" + owner + ";");
final Type fieldType = Type.getType(descriptor);
final List<Reference.Flag> fieldFlags = new ArrayList<>();
@ -334,7 +337,10 @@ public class ReferenceCreator extends ClassVisitor {
}
}
final Type ownerType = Type.getType("L" + owner + ";");
final Type ownerType =
owner.startsWith("[")
? underlyingType(Type.getType(owner))
: Type.getType("L" + owner + ";");
final List<Reference.Flag> methodFlags = new ArrayList<>();
methodFlags.add(

View File

@ -12,6 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import net.bytebuddy.asm.Advice;
@ -33,9 +35,17 @@ public final class DriverInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".JDBCConnectionUrlParser",
};
final JDBCConnectionUrlParser[] parsers = JDBCConnectionUrlParser.values();
final List<String> parserClasses = new ArrayList<>(parsers.length + 3);
parserClasses.add(packageName + ".JDBCMaps");
parserClasses.add(packageName + ".JDBCMaps$DBInfo");
parserClasses.add(packageName + ".JDBCConnectionUrlParser");
for (final JDBCConnectionUrlParser parser : parsers) {
parserClasses.add(parser.getClass().getName());
}
return parserClasses.toArray(new String[0]);
}
@Override

View File

@ -2,6 +2,7 @@ package datadog.trace.instrumentation.jdbc;
import static datadog.trace.instrumentation.jdbc.JDBCMaps.DBInfo.DEFAULT;
import datadog.trace.bootstrap.ExceptionLogger;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
@ -9,6 +10,8 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Structured as an enum instead of a class hierarchy to allow iterating through the parsers, plus
@ -22,13 +25,13 @@ public enum JDBCConnectionUrlParser {
// Attempt generic parsing
final URI uri = new URI(jdbcUrl);
String username = uri.getUserInfo();
String user = uri.getUserInfo();
String databaseName = null;
if (uri.getQuery() != null) {
final Map<String, String> queryParams = splitQuery(uri.getQuery(), "&");
if (username == null) {
username = queryParams.get("user");
if (user == null) {
user = queryParams.get("user");
}
databaseName = queryParams.get("databasename");
}
@ -39,7 +42,7 @@ public enum JDBCConnectionUrlParser {
}
return new JDBCMaps.DBInfo(
uri.getScheme(), null, username, path, databaseName, uri.getHost(), uri.getPort());
uri.getScheme(), null, user, path, databaseName, uri.getHost(), uri.getPort());
} catch (final Exception e) {
return DEFAULT;
}
@ -58,7 +61,7 @@ public enum JDBCConnectionUrlParser {
Integer port = null;
String databaseName = null;
String instanceName = null;
String username = null;
String user = null;
final int hostIndex = jdbcUrl.indexOf("://");
@ -92,7 +95,7 @@ public enum JDBCConnectionUrlParser {
databaseName = urlProps.get("databasename");
}
if (urlProps.containsKey("user")) {
username = urlProps.get("user");
user = urlProps.get("user");
}
}
@ -125,7 +128,7 @@ public enum JDBCConnectionUrlParser {
}
return new JDBCMaps.DBInfo(
type, null, username, instanceName, null /* databaseName */, serverName, port);
type, null, user, instanceName, null /* databaseName */, serverName, port);
} catch (final UnsupportedEncodingException e) {
return DEFAULT;
}
@ -235,6 +238,172 @@ public enum JDBCConnectionUrlParser {
}
},
ORACLE("oracle") {
private static final int DEFAULT_PORT = 1521;
@Override
JDBCMaps.DBInfo doParse(String jdbcUrl, final Properties props) {
final int typeEndIndex = jdbcUrl.indexOf(":", "oracle:".length());
final String type = jdbcUrl.substring(0, typeEndIndex);
jdbcUrl = jdbcUrl.substring(typeEndIndex + 1);
final JDBCMaps.DBInfo dbInfo;
if (jdbcUrl.contains("@")) {
dbInfo = ORACLE_AT.doParse(jdbcUrl, props);
} else {
dbInfo = ORACLE_CONNECT_INFO.doParse(jdbcUrl, props);
}
return new JDBCMaps.DBInfo(
type,
dbInfo.getUrl(),
dbInfo.getUser(),
dbInfo.getInstance(),
dbInfo.getDb(),
dbInfo.getHost(),
dbInfo.getPort() == null ? DEFAULT_PORT : dbInfo.getPort());
}
},
ORACLE_CONNECT_INFO() {
@Override
JDBCMaps.DBInfo doParse(final String jdbcUrl, final Properties props) {
final String host;
final Integer port;
final String instance;
final int hostEnd = jdbcUrl.indexOf(":");
final int instanceLoc = jdbcUrl.indexOf("/");
if (hostEnd > 0) {
host = jdbcUrl.substring(0, hostEnd);
final int afterHostEnd = jdbcUrl.indexOf(":", hostEnd + 1);
if (afterHostEnd > 0) {
port = Integer.parseInt(jdbcUrl.substring(hostEnd + 1, afterHostEnd));
instance = jdbcUrl.substring(afterHostEnd + 1);
} else {
if (instanceLoc > 0) {
instance = jdbcUrl.substring(instanceLoc + 1);
port = Integer.parseInt(jdbcUrl.substring(hostEnd + 1, instanceLoc));
} else {
final String portOrInstance = jdbcUrl.substring(hostEnd + 1);
Integer parsedPort = null;
try {
parsedPort = Integer.parseInt(portOrInstance);
} catch (final NumberFormatException e) {
}
if (parsedPort == null) {
port = null;
instance = portOrInstance;
} else {
port = parsedPort;
instance = null;
}
}
}
} else {
if (instanceLoc > 0) {
host = jdbcUrl.substring(0, instanceLoc);
port = null;
instance = jdbcUrl.substring(instanceLoc + 1);
} else {
if (jdbcUrl.isEmpty()) {
return DEFAULT;
} else {
host = null;
port = null;
instance = jdbcUrl;
}
}
}
return new JDBCMaps.DBInfo(null, null, null, instance, null, host, port);
}
},
ORACLE_AT() {
@Override
JDBCMaps.DBInfo doParse(final String jdbcUrl, final Properties props) {
if (jdbcUrl.contains("@(description")) {
return ORACLE_AT_DESCRIPTION.doParse(jdbcUrl, props);
}
final String user;
final String[] atSplit = jdbcUrl.split("@", 2);
final int userInfoLoc = atSplit[0].indexOf("/");
if (userInfoLoc > 0) {
user = atSplit[0].substring(0, userInfoLoc);
} else {
user = null;
}
final String connectInfo = atSplit[1];
final int hostStart;
if (connectInfo.startsWith("//")) {
hostStart = "//".length();
} else if (connectInfo.startsWith("ldap://")) {
hostStart = "ldap://".length();
} else {
hostStart = 0;
}
final JDBCMaps.DBInfo dbInfo =
ORACLE_CONNECT_INFO.doParse(connectInfo.substring(hostStart), props);
return new JDBCMaps.DBInfo(
null,
dbInfo.getUrl(),
user,
dbInfo.getInstance(),
dbInfo.getDb(),
dbInfo.getHost(),
dbInfo.getPort());
}
},
ORACLE_AT_DESCRIPTION() {
private final Pattern HOST_REGEX = Pattern.compile("\\(\\s*host\\s*=\\s*([^ )]+)\\s*\\)");
private final Pattern PORT_REGEX = Pattern.compile("\\(\\s*port\\s*=\\s*([\\d]+)\\s*\\)");
private final Pattern INSTANCE_REGEX =
Pattern.compile("\\(\\s*service_name\\s*=\\s*([^ )]+)\\s*\\)");
@Override
JDBCMaps.DBInfo doParse(final String jdbcUrl, final Properties props) {
final String user;
final String host;
final Integer port;
final String instance;
final String[] atSplit = jdbcUrl.split("@", 2);
final int userInfoLoc = atSplit[0].indexOf("/");
if (userInfoLoc > 0) {
user = atSplit[0].substring(0, userInfoLoc);
} else {
user = null;
}
final String description = atSplit[1];
final Matcher hostMatcher = HOST_REGEX.matcher(description);
final Matcher portMatcher = PORT_REGEX.matcher(description);
final Matcher instanceMatcher = INSTANCE_REGEX.matcher(description);
if (hostMatcher.find()) {
host = hostMatcher.group(1);
} else {
host = null;
}
if (portMatcher.find()) {
port = Integer.parseInt(portMatcher.group(1));
} else {
port = null;
}
if (instanceMatcher.find()) {
instance = instanceMatcher.group(1);
} else {
instance = null;
}
return new JDBCMaps.DBInfo(null, null, user, instance, null, host, port);
}
},
H2("h2") {
private static final int DEFAULT_PORT = 8082;
@ -390,8 +559,8 @@ public enum JDBCConnectionUrlParser {
String user = DEFAULT_USER;
if (props != null) {
instance = props.getProperty("databasename");
user = props.getProperty("user");
instance = props.getProperty("databasename", instance);
user = props.getProperty("user", user);
}
final String derbyUrl = jdbcUrl.substring("derby:".length());
final String[] split = derbyUrl.split(";", 2);
@ -510,11 +679,16 @@ public enum JDBCConnectionUrlParser {
final String baseType = jdbcUrl.substring(0, typeLoc);
try {
if (typeParsers.containsKey(baseType)) {
// Delegate to specific parser
return typeParsers.get(baseType).doParse(jdbcUrl, props);
}
return GENERIC_URL_LIKE.doParse(connectionUrl, props);
} catch (final Exception e) {
ExceptionLogger.LOGGER.debug("Error parsing URL", e);
return DEFAULT;
}
}
// Source: https://stackoverflow.com/a/13592567

View File

@ -20,6 +20,8 @@ import io.opentracing.noop.NoopScopeManager;
import io.opentracing.util.GlobalTracer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@ -40,15 +42,23 @@ public final class PreparedStatementInstrumentation extends Instrumenter.Default
@Override
public String[] helperClassNames() {
return new String[] {
"datadog.trace.agent.decorator.BaseDecorator",
"datadog.trace.agent.decorator.ClientDecorator",
"datadog.trace.agent.decorator.DatabaseClientDecorator",
packageName + ".JDBCDecorator",
packageName + ".JDBCMaps",
packageName + ".JDBCMaps$DBInfo",
packageName + ".JDBCUtils",
};
final JDBCConnectionUrlParser[] parsers = JDBCConnectionUrlParser.values();
final List<String> parserClasses = new ArrayList<>(parsers.length + 8);
parserClasses.add(packageName + ".JDBCUtils");
parserClasses.add(packageName + ".JDBCMaps");
parserClasses.add(packageName + ".JDBCMaps$DBInfo");
parserClasses.add(packageName + ".JDBCConnectionUrlParser");
parserClasses.add("datadog.trace.agent.decorator.BaseDecorator");
parserClasses.add("datadog.trace.agent.decorator.ClientDecorator");
parserClasses.add("datadog.trace.agent.decorator.DatabaseClientDecorator");
parserClasses.add(packageName + ".JDBCDecorator");
for (final JDBCConnectionUrlParser parser : parsers) {
parserClasses.add(parser.getClass().getName());
}
return parserClasses.toArray(new String[0]);
}
@Override

View File

@ -20,6 +20,8 @@ import io.opentracing.noop.NoopScopeManager;
import io.opentracing.util.GlobalTracer;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@ -40,15 +42,23 @@ public final class StatementInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {
"datadog.trace.agent.decorator.BaseDecorator",
"datadog.trace.agent.decorator.ClientDecorator",
"datadog.trace.agent.decorator.DatabaseClientDecorator",
packageName + ".JDBCDecorator",
packageName + ".JDBCMaps",
packageName + ".JDBCMaps$DBInfo",
packageName + ".JDBCUtils",
};
final JDBCConnectionUrlParser[] parsers = JDBCConnectionUrlParser.values();
final List<String> parserClasses = new ArrayList<>(parsers.length + 8);
parserClasses.add(packageName + ".JDBCUtils");
parserClasses.add(packageName + ".JDBCMaps");
parserClasses.add(packageName + ".JDBCMaps$DBInfo");
parserClasses.add(packageName + ".JDBCConnectionUrlParser");
parserClasses.add("datadog.trace.agent.decorator.BaseDecorator");
parserClasses.add("datadog.trace.agent.decorator.ClientDecorator");
parserClasses.add("datadog.trace.agent.decorator.DatabaseClientDecorator");
parserClasses.add(packageName + ".JDBCDecorator");
for (final JDBCConnectionUrlParser parser : parsers) {
parserClasses.add(parser.getClass().getName());
}
return parserClasses.toArray(new String[0]);
}
@Override

View File

@ -51,10 +51,23 @@ class JDBCConnectionUrlParserTest extends Specification {
"jdbc:sqlserver://sshost;serverName=althost;DatabaseName=ssdb;" | "sqlserver" | null | "sshost" | 1433 | "MSSQLSERVER"
"jdbc:microsoft:sqlserver://sshost:44;DatabaseName=ssdb;user=ssuser;password=pw;user=ssuser2;" | "sqlserver" | "ssuser" | "sshost" | 44 | "MSSQLSERVER"
// TODO:
// "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= localhost )(PORT= 1521))" +
// "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))" | "oracle" | "orcluser" | "orclhost" | 55 | "orcldb"
// "jdbc:oracle:drivertype:orcluser/PW@orclhost:55/orcldb" | "oracle" | "orcluser" | "orclhost" | 55 | "orcldb"
// https://docs.oracle.com/cd/B28359_01/java.111/b31224/urls.htm
// https://docs.oracle.com/cd/B28359_01/java.111/b31224/jdbcthin.htm
"jdbc:oracle:thin:orcluser/PW@localhost:55:orclsn" | "oracle:thin" | "orcluser" | "localhost" | 55 | "orclsn"
"jdbc:oracle:thin:orcluser/PW@//orclhost:55/orclsn" | "oracle:thin" | "orcluser" | "orclhost" | 55 | "orclsn"
"jdbc:oracle:thin:orcluser/PW@127.0.0.1:orclsn" | "oracle:thin" | "orcluser" | "127.0.0.1" | 1521 | "orclsn"
"jdbc:oracle:thin:orcluser/PW@//orclhost/orclsn" | "oracle:thin" | "orcluser" | "orclhost" | 1521 | "orclsn"
"jdbc:oracle:thin:@//orclhost:55/orclsn" | "oracle:thin" | null | "orclhost" | 55 | "orclsn"
"jdbc:oracle:thin:@ldap://orclhost:55/some,cn=OracleContext,dc=com" | "oracle:thin" | null | "orclhost" | 55 | "some,cn=oraclecontext,dc=com"
"jdbc:oracle:thin:127.0.0.1:orclsn" | "oracle:thin" | null | "127.0.0.1" | 1521 | "orclsn"
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= 127.0.0.1 )(POR T= 666))" +
"(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orclsn)))" | "oracle:thin" | null | "127.0.0.1" | 1521 | "orclsn"
// https://docs.oracle.com/cd/B28359_01/java.111/b31224/instclnt.htm
"jdbc:oracle:drivertype:orcluser/PW@orclhost:55/orclsn" | "oracle:drivertype" | "orcluser" | "orclhost" | 55 | "orclsn"
"jdbc:oracle:oci8:@" | "oracle:oci8" | null | null | 1521 | null
"jdbc:oracle:oci8:@orclsn" | "oracle:oci8" | null | null | 1521 | "orclsn"
"jdbc:oracle:oci:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)( HOST = orclhost )" +
"( PORT = 55 ))(CONNECT_DATA=(SERVICE_NAME =orclsn )))" | "oracle:oci" | null | "orclhost" | 55 | "orclsn"
// https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/java/src/tpc/imjcc_tjvjcccn.html
// https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_r0052342.html

View File

@ -26,23 +26,23 @@ class JDBCInstrumentationTest extends AgentTestRunner {
@Shared
private Map<String, String> jdbcUrls = [
h2 : "jdbc:h2:mem:$dbName",
derby : "jdbc:derby:memory:$dbName",
hsqldb: "jdbc:hsqldb:mem:$dbName",
"h2:mem" : "jdbc:h2:mem:$dbName",
"derby:memory": "jdbc:derby:memory:$dbName",
"hsqldb:mem" : "jdbc:hsqldb:mem:$dbName",
]
@Shared
private Map<String, String> jdbcDriverClassNames = [
h2 : "org.h2.Driver",
derby : "org.apache.derby.jdbc.EmbeddedDriver",
hsqldb: "org.hsqldb.jdbc.JDBCDriver",
"h2:mem" : "org.h2.Driver",
"derby:memory": "org.apache.derby.jdbc.EmbeddedDriver",
"hsqldb:mem" : "org.hsqldb.jdbc.JDBCDriver",
]
@Shared
private Map<String, String> jdbcUserNames = [
h2 : null,
derby : "APP",
hsqldb: "SA",
"h2:mem" : null,
"derby:memory": "APP",
"hsqldb:mem" : "SA",
]
@Shared
@ -76,7 +76,7 @@ class JDBCInstrumentationTest extends AgentTestRunner {
def createTomcatDS(String dbType, String jdbcUrl) {
DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource()
def jdbcUrlToSet = dbType == "derby" ? jdbcUrl + ";create=true" : jdbcUrl
def jdbcUrlToSet = dbType == "derby:memory" ? jdbcUrl + ";create=true" : jdbcUrl
ds.setUrl(jdbcUrlToSet)
ds.setDriverClassName(jdbcDriverClassNames.get(dbType))
String username = jdbcUserNames.get(dbType)
@ -91,7 +91,7 @@ class JDBCInstrumentationTest extends AgentTestRunner {
def createHikariDS(String dbType, String jdbcUrl) {
HikariConfig config = new HikariConfig()
def jdbcUrlToSet = dbType == "derby" ? jdbcUrl + ";create=true" : jdbcUrl
def jdbcUrlToSet = dbType == "derby:memory" ? jdbcUrl + ";create=true" : jdbcUrl
config.setJdbcUrl(jdbcUrlToSet)
String username = jdbcUserNames.get(dbType)
if (username != null) {
@ -109,7 +109,7 @@ class JDBCInstrumentationTest extends AgentTestRunner {
def createC3P0DS(String dbType, String jdbcUrl) {
DataSource ds = new ComboPooledDataSource()
ds.setDriverClass(jdbcDriverClassNames.get(dbType))
def jdbcUrlToSet = dbType == "derby" ? jdbcUrl + ";create=true" : jdbcUrl
def jdbcUrlToSet = dbType == "derby:memory" ? jdbcUrl + ";create=true" : jdbcUrl
ds.setJdbcUrl(jdbcUrlToSet)
String username = jdbcUserNames.get(dbType)
if (username != null) {
@ -194,21 +194,21 @@ class JDBCInstrumentationTest extends AgentTestRunner {
where:
driver | connection | username | query
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3"
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | "SELECT 3"
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2:mem" | new Driver().connect(jdbcUrls.get("h2:mem"), null) | null | "SELECT 3"
"derby:memory" | new EmbeddedDriver().connect(jdbcUrls.get("derby:memory"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb:mem" | new JDBCDriver().connect(jdbcUrls.get("hsqldb:mem"), null) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2:mem" | new Driver().connect(jdbcUrls.get("h2:mem"), connectionProps) | null | "SELECT 3"
"derby:memory" | new EmbeddedDriver().connect(jdbcUrls.get("derby:memory"), connectionProps) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb:mem" | new JDBCDriver().connect(jdbcUrls.get("hsqldb:mem"), connectionProps) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2:mem" | cpDatasources.get("tomcat").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("tomcat").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb:mem" | cpDatasources.get("tomcat").get("hsqldb:mem").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2:mem" | cpDatasources.get("hikari").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("hikari").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb:mem" | cpDatasources.get("hikari").get("hsqldb:mem").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
"h2:mem" | cpDatasources.get("c3p0").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("c3p0").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"hsqldb:mem" | cpDatasources.get("c3p0").get("hsqldb:mem").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
}
@Unroll
@ -257,14 +257,14 @@ class JDBCInstrumentationTest extends AgentTestRunner {
where:
driver | connection | username | query
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3"
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | new Driver().connect(jdbcUrls.get("h2:mem"), null) | null | "SELECT 3"
"derby:memory" | new EmbeddedDriver().connect(jdbcUrls.get("derby:memory"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("tomcat").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("tomcat").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("hikari").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("hikari").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("c3p0").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("c3p0").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
}
@Unroll
@ -312,14 +312,14 @@ class JDBCInstrumentationTest extends AgentTestRunner {
where:
driver | connection | username | query
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3"
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | new Driver().connect(jdbcUrls.get("h2:mem"), null) | null | "SELECT 3"
"derby:memory" | new EmbeddedDriver().connect(jdbcUrls.get("derby:memory"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("tomcat").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("tomcat").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("hikari").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("hikari").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("c3p0").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("c3p0").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
}
@Unroll
@ -367,14 +367,14 @@ class JDBCInstrumentationTest extends AgentTestRunner {
where:
driver | connection | username | query
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3"
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3"
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | new Driver().connect(jdbcUrls.get("h2:mem"), null) | null | "SELECT 3"
"derby:memory" | new EmbeddedDriver().connect(jdbcUrls.get("derby:memory"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("tomcat").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("tomcat").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("hikari").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("hikari").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
"h2:mem" | cpDatasources.get("c3p0").get("h2:mem").getConnection() | null | "SELECT 3"
"derby:memory" | cpDatasources.get("c3p0").get("derby:memory").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
}
@Unroll
@ -422,18 +422,18 @@ class JDBCInstrumentationTest extends AgentTestRunner {
where:
driver | connection | username | query
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | new Driver().connect(jdbcUrls.get("h2:mem"), null) | null | "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | new EmbeddedDriver().connect(jdbcUrls.get("derby:memory"), null) | "APP" | "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb:mem" | new JDBCDriver().connect(jdbcUrls.get("hsqldb:mem"), null) | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | cpDatasources.get("tomcat").get("h2:mem").getConnection() | null | "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | cpDatasources.get("tomcat").get("derby:memory").getConnection() | "APP" | "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb:mem" | cpDatasources.get("tomcat").get("hsqldb:mem").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | cpDatasources.get("hikari").get("h2:mem").getConnection() | null | "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | cpDatasources.get("hikari").get("derby:memory").getConnection() | "APP" | "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb:mem" | cpDatasources.get("hikari").get("hsqldb:mem").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | cpDatasources.get("c3p0").get("h2:mem").getConnection() | null | "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | cpDatasources.get("c3p0").get("derby:memory").getConnection() | "APP" | "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"hsqldb:mem" | cpDatasources.get("c3p0").get("hsqldb:mem").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
}
@Unroll
@ -480,14 +480,14 @@ class JDBCInstrumentationTest extends AgentTestRunner {
where:
driver | connection | username | query
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | new Driver().connect(jdbcUrls.get("h2:mem"), null) | null | "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | new EmbeddedDriver().connect(jdbcUrls.get("derby:memory"), null) | "APP" | "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | cpDatasources.get("tomcat").get("h2:mem").getConnection() | null | "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | cpDatasources.get("tomcat").get("derby:memory").getConnection() | "APP" | "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | cpDatasources.get("hikari").get("h2:mem").getConnection() | null | "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | cpDatasources.get("hikari").get("derby:memory").getConnection() | "APP" | "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"
"h2:mem" | cpDatasources.get("c3p0").get("h2:mem").getConnection() | null | "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
"derby:memory" | cpDatasources.get("c3p0").get("derby:memory").getConnection() | "APP" | "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))"
}
@ -559,16 +559,16 @@ class JDBCInstrumentationTest extends AgentTestRunner {
where:
prepareStatement | driver | driverClass | url | username | query
true | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;"
true | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
false | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;"
false | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
true | "h2:mem" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;"
true | "derby:memory" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
false | "h2:mem" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;"
false | "derby:memory" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
}
@Unroll
def "#connectionPoolName connections should be cached in case of wrapped connections"() {
setup:
String dbType = "hsqldb"
String dbType = "hsqldb:mem"
DataSource ds = createDS(connectionPoolName, dbType, jdbcUrls.get(dbType))
String query = "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
int numQueries = 5