Make connections always close on test case completion.
MODIFY
dd-java-agent/instrumentation/jdbc/jdbc.gradle
dd-java-agent/instrumentation/jdbc/jdbc.gradle
@@ -20,7 +20,6 @@ dependencies {
// jdbc unit testing
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
testCompile group: 'org.apache.derby', name: 'derby', version: '10.12.1.1'
- // not using hsqldb 2.4 because org/hsqldb/jdbc/JDBCDriver : Unsupported major.minor version 52.0
testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.+'
testCompile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '7.0.19'
@@ -34,7 +33,6 @@ configurations.latestDepTestCompile {
resolutionStrategy {
force group: 'com.h2database', name: 'h2', version: '+'
force group: 'org.apache.derby', name: 'derby', version: '+'
- // not using hsqldb 2.4 because org/hsqldb/jdbc/JDBCDriver : Unsupported major.minor version 52.0
force group: 'org.hsqldb', name: 'hsqldb', version: '+'
force group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '+'

MODIFY
dd-java-agent/instrumentation/jdbc/src/test/groovy/JDBCInstrumentationTest.groovy
dd-java-agent/instrumentation/jdbc/src/test/groovy/JDBCInstrumentationTest.groovy
@@ -37,9 +37,6 @@ class JDBCInstrumentationTest extends AgentTestRunner {
hsqldb: "org.hsqldb.jdbc.JDBCDriver"
]
- @Shared
- private Map<String, Connection> connections
-
@Shared
private Map<String, String> jdbcUserNames = [
h2 : null,
@@ -128,22 +125,9 @@ class JDBCInstrumentationTest extends AgentTestRunner {
def setupSpec() {
prepareConnectionPoolDatasources()
-
- Connection h2Connection = new Driver().connect(jdbcUrls.get("h2"), null)
- Connection hsqlConnection = new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null)
- Connection derbyConnection = new EmbeddedDriver().connect(jdbcUrls.get("derby"), null)
-
- connections = [
- h2 : h2Connection,
- derby : derbyConnection,
- hsqldb: hsqlConnection,
- ]
}
def cleanupSpec() {
- connections.values().each {
- it.close()
- }
cpDatasources.values().each {
it.values().each {
datasource ->
@@ -189,24 +173,22 @@ class JDBCInstrumentationTest extends AgentTestRunner {
cleanup:
statement.close()
- if (closeConection) {
connection.close()
- }
where:
- driver | connection | username | query | closeConection
- "h2" | connections.get("h2") | null | "SELECT 3" | false
- "derby" | connections.get("derby") | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | false
- "hsqldb" | connections.get("hsqldb") | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | false
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
- "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection()| "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | true
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
- "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection()| "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | true
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
- "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | true
+ 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" | 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"
}
@Unroll
@@ -245,20 +227,18 @@ class JDBCInstrumentationTest extends AgentTestRunner {
cleanup:
statement.close()
- if (closeConection) {
connection.close()
- }
where:
- driver | connection | username | query | closeConection
- "h2" | connections.get("h2") | null | "SELECT 3" | false
- "derby" | connections.get("derby") | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | false
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection()| "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("hikari").get("derby").getConnection()| "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
+ 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"
}
@Unroll
@@ -296,20 +276,18 @@ class JDBCInstrumentationTest extends AgentTestRunner {
cleanup:
statement.close()
- if (closeConection) {
connection.close()
- }
where:
- driver | connection | username | query | closeConection
- "h2" | connections.get("h2") | null | "SELECT 3" | false
- "derby" | connections.get("derby") | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | false
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection()| "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("hikari").get("derby").getConnection()| "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | true
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | true
+ 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"
}
@Unroll
@@ -347,24 +325,22 @@ class JDBCInstrumentationTest extends AgentTestRunner {
cleanup:
statement.close()
- if (closeConection) {
connection.close()
- }
where:
- driver | connection | username | query | closeConection
- "h2" | connections.get("h2") | null | "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | false
- "derby" | connections.get("derby") | "APP" | "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | false
- "hsqldb" | connections.get("hsqldb") | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))" | false
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection()| "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))"| true
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection()| "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))"| true
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
+ 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 ))"
}
@Unroll
@@ -401,20 +377,18 @@ class JDBCInstrumentationTest extends AgentTestRunner {
cleanup:
statement.close()
- if (closeConection) {
connection.close()
- }
where:
- driver | connection | username | query | closeConection
- "h2" | connections.get("h2") | null | "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | false
- "derby" | connections.get("derby") | "APP" | "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | false
- "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
- "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | true
+ 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 ))"
}

Make connections always close on test case completion.