From d1d8c32bce42eb17cb619a2c720035875a9c1a8f Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Wed, 28 Aug 2024 20:49:00 +0800 Subject: [PATCH 01/11] convert instrument jdbc test from groovy to java --- .../jdbc/test/JdbcInstrumentationTest.java | 379 +++++++ .../jdbc/AnotherTestDriver.groovy | 51 - .../jdbc/TestCallableStatement.groovy | 587 ----------- .../jdbc/TestConnection.groovy | 317 ------ .../jdbc/TestDatabaseMetaData.groovy | 904 ----------------- .../instrumentation/jdbc/TestDriver.groovy | 51 - .../jdbc/TestPreparedStatement.groovy | 309 ------ .../instrumentation/jdbc/TestStatement.groovy | 244 ----- .../jdbc/AnotherTestDriver.java | 51 + .../jdbc/TestCallableStatement.java | 504 ++++++++++ .../instrumentation/jdbc/TestConnection.java | 293 ++++++ .../jdbc/TestDatabaseMetaData.java | 940 ++++++++++++++++++ .../instrumentation/jdbc/TestDriver.java | 52 + .../jdbc/TestPreparedStatement.java | 221 ++++ .../instrumentation/jdbc/TestStatement.java | 217 ++++ 15 files changed, 2657 insertions(+), 2463 deletions(-) create mode 100644 instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java delete mode 100644 instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.groovy delete mode 100644 instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.groovy delete mode 100644 instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestConnection.groovy delete mode 100644 instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.groovy delete mode 100644 instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDriver.groovy delete mode 100644 instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.groovy delete mode 100644 instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestStatement.groovy create mode 100644 instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.java create mode 100644 instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java create mode 100644 instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java create mode 100644 instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java create mode 100644 instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java create mode 100644 instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java create mode 100644 instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java new file mode 100644 index 000000000000..aad93f2ecbc7 --- /dev/null +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -0,0 +1,379 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jdbc.test; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +import com.mchange.v2.c3p0.ComboPooledDataSource; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import java.beans.PropertyVetoException; +import java.io.Closeable; +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.sql.DataSource; +import org.apache.derby.jdbc.EmbeddedDriver; +import org.h2.Driver; +import org.hsqldb.jdbc.JDBCDriver; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class JdbcInstrumentationTest { + + @RegisterExtension + static InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + private String dbName; + private String dbNameLower; + private Map jdbcUrls; + private Map jdbcDriverClassNames; + private Map jdbcUserNames; + private Properties connectionProps; + // JDBC Connection pool name (i.e. HikariCP) -> Map + private Map> cpDatasources; + + @BeforeAll + public void setUp() { + dbName = "jdbcUnitTest"; + dbNameLower = dbName.toLowerCase(Locale.ROOT); + jdbcUrls = + Collections.unmodifiableMap( + Stream.of( + entry("h2", "jdbc:h2:mem:" + dbName), + entry("derby", "jdbc:derby:memory:" + dbName), + entry("hsqldb", "jdbc:hsqldb:mem:" + dbName)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + + jdbcDriverClassNames = + Collections.unmodifiableMap( + Stream.of( + entry("h2", "org.h2.Driver"), + entry("derby", "org.apache.derby.jdbc.EmbeddedDriver"), + entry("hsqldb", "org.hsqldb.jdbc.JDBCDriver")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + + jdbcUserNames = new HashMap<>(); + jdbcUserNames.put("derby", "APP"); + jdbcUserNames.put("h2", null); + jdbcUserNames.put("hsqldb", "SA"); + + connectionProps = new Properties(); + connectionProps.put("databaseName", "someDb"); + connectionProps.put("OPEN_NEW", "true"); // So H2 doesn't complain about username/password. + + cpDatasources = new HashMap<>(); + + prepareConnectionPoolDatasources(); + System.out.println("before all"); + } + + @AfterAll + public void tearDown() { + System.out.println("after all"); + cpDatasources + .values() + .forEach( + k -> + k.values() + .forEach( + dataSource -> { + if (dataSource instanceof Closeable) { + try { + ((Closeable) dataSource).close(); + } catch (IOException e) { + // ignore + } + } + })); + } + + void prepareConnectionPoolDatasources() { + List connectionPoolNames = asList("tomcat", "hikari", "c3p0"); + connectionPoolNames.forEach( + cpName -> { + Map dbDSMapping = new HashMap<>(); + jdbcUrls.forEach( + (dbType, jdbcUrl) -> dbDSMapping.put(dbType, createDS(cpName, dbType, jdbcUrl))); + cpDatasources.put(cpName, dbDSMapping); + }); + } + + DataSource createTomcatDS(String dbType, String jdbcUrl) { + org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(); + String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; + ds.setUrl(jdbcUrlToSet); + ds.setDriverClassName(jdbcDriverClassNames.get(dbType)); + String username = jdbcUserNames.get(dbType); + if (username != null) { + ds.setUsername(username); + } + ds.setPassword(""); + ds.setMaxActive(1); // to test proper caching, having > 1 max active connection will be hard to + // determine whether the connection is properly cached + return ds; + } + + DataSource createHikariDS(String dbType, String jdbcUrl) { + HikariConfig config = new HikariConfig(); + String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; + config.setJdbcUrl(jdbcUrlToSet); + String username = jdbcUserNames.get(dbType); + if (username != null) { + config.setUsername(username); + } + config.setPassword(""); + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "250"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + config.setMaximumPoolSize(1); + + return new HikariDataSource(config); + } + + DataSource createC3P0DS(String dbType, String jdbcUrl) { + ComboPooledDataSource ds = new ComboPooledDataSource(); + try { + ds.setDriverClass(jdbcDriverClassNames.get(dbType)); + } catch (PropertyVetoException e) { + throw new RuntimeException(e); + } + String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; + ds.setJdbcUrl(jdbcUrlToSet); + String username = jdbcUserNames.get(dbType); + if (username != null) { + ds.setUser(username); + } + ds.setPassword(""); + ds.setMaxPoolSize(1); + return ds; + } + + DataSource createDS(String connectionPoolName, String dbType, String jdbcUrl) { + DataSource ds = null; + if (Objects.equals(connectionPoolName, "tomcat")) { + ds = createTomcatDS(dbType, jdbcUrl); + } + if (Objects.equals(connectionPoolName, "hikari")) { + ds = createHikariDS(dbType, jdbcUrl); + } + if (Objects.equals(connectionPoolName, "c3p0")) { + ds = createC3P0DS(dbType, jdbcUrl); + } + return ds; + } + + Stream basicStatementStream() throws SQLException { + return Stream.of( + Arguments.of( + "h2", + new Driver().connect(jdbcUrls.get("h2"), null), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + new EmbeddedDriver().connect(jdbcUrls.get("derby"), null), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "hsqldb", + new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null), + "SA", + "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT INFORMATION_SCHEMA.SYSTEM_USERS", + "hsqldb:mem:", + "INFORMATION_SCHEMA.SYSTEM_USERS"), + Arguments.of( + "h2", + new Driver().connect(jdbcUrls.get("h2"), connectionProps), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "hsqldb", + new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps), + "SA", + "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT INFORMATION_SCHEMA.SYSTEM_USERS", + "hsqldb:mem:", + "INFORMATION_SCHEMA.SYSTEM_USERS"), + Arguments.of( + "h2", + cpDatasources.get("tomcat").get("h2").getConnection(), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + cpDatasources.get("tomcat").get("derby").getConnection(), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "hsqldb", + cpDatasources.get("tomcat").get("hsqldb").getConnection(), + "SA", + "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT INFORMATION_SCHEMA.SYSTEM_USERS", + "hsqldb:mem:", + "INFORMATION_SCHEMA.SYSTEM_USERS"), + Arguments.of( + "h2", + cpDatasources.get("hikari").get("h2").getConnection(), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + cpDatasources.get("hikari").get("derby").getConnection(), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "hsqldb", + cpDatasources.get("hikari").get("hsqldb").getConnection(), + "SA", + "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT INFORMATION_SCHEMA.SYSTEM_USERS", + "hsqldb:mem:", + "INFORMATION_SCHEMA.SYSTEM_USERS"), + Arguments.of( + "h2", + cpDatasources.get("c3p0").get("h2").getConnection(), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + cpDatasources.get("c3p0").get("derby").getConnection(), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "hsqldb", + cpDatasources.get("c3p0").get("hsqldb").getConnection(), + "SA", + "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS", + "SELECT INFORMATION_SCHEMA.SYSTEM_USERS", + "hsqldb:mem:", + "INFORMATION_SCHEMA.SYSTEM_USERS")); + } + + @SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation + @DisplayName( + "basic statement with #connection.getClass().getCanonicalName() on #system generates spans") + @ParameterizedTest + @MethodSource("basicStatementStream") + public void testBasicStatement( + String system, + Connection connection, + String username, + String query, + String sanitizedQuery, + String spanName, + String url, + String table) + throws SQLException { + Statement statement = connection.createStatement(); + ResultSet resultSet = testing.runWithSpan("parent", () -> statement.executeQuery(query)); + + resultSet.next(); + assertThat(resultSet.getInt(1)).isEqualTo(3); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(username), + v -> assertThat(v).isNull())), + equalTo(DbIncubatingAttributes.DB_CONNECTION_STRING, url), + equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), + equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); + statement.close(); + connection.close(); + } +} diff --git a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.groovy b/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.groovy deleted file mode 100644 index 0658c9bd318c..000000000000 --- a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.jdbc - - -import java.sql.Connection -import java.sql.Driver -import java.sql.DriverPropertyInfo -import java.sql.SQLException -import java.sql.SQLFeatureNotSupportedException -import java.util.logging.Logger - -class AnotherTestDriver implements Driver { - @Override - Connection connect(String url, Properties info) throws SQLException { - return null - } - - @Override - boolean acceptsURL(String url) throws SQLException { - return false - } - - @Override - DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { - return new DriverPropertyInfo[0] - } - - @Override - int getMajorVersion() { - return 0 - } - - @Override - int getMinorVersion() { - return 0 - } - - @Override - boolean jdbcCompliant() { - return false - } - - @Override - Logger getParentLogger() throws SQLFeatureNotSupportedException { - return null - } -} diff --git a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.groovy b/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.groovy deleted file mode 100644 index a39a259fc560..000000000000 --- a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.groovy +++ /dev/null @@ -1,587 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.jdbc - - -import java.sql.Array -import java.sql.Blob -import java.sql.CallableStatement -import java.sql.Clob -import java.sql.Date -import java.sql.NClob -import java.sql.Ref -import java.sql.RowId -import java.sql.SQLException -import java.sql.SQLXML -import java.sql.Time -import java.sql.Timestamp - -class TestCallableStatement extends TestPreparedStatement implements CallableStatement { - @Override - void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { - - } - - @Override - void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { - - } - - @Override - boolean wasNull() throws SQLException { - return false - } - - @Override - String getString(int parameterIndex) throws SQLException { - return null - } - - @Override - boolean getBoolean(int parameterIndex) throws SQLException { - return false - } - - @Override - byte getByte(int parameterIndex) throws SQLException { - return 0 - } - - @Override - short getShort(int parameterIndex) throws SQLException { - return 0 - } - - @Override - int getInt(int parameterIndex) throws SQLException { - return 0 - } - - @Override - long getLong(int parameterIndex) throws SQLException { - return 0 - } - - @Override - float getFloat(int parameterIndex) throws SQLException { - return 0 - } - - @Override - double getDouble(int parameterIndex) throws SQLException { - return 0 - } - - @Override - BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { - return null - } - - @Override - byte[] getBytes(int parameterIndex) throws SQLException { - return new byte[0] - } - - @Override - Date getDate(int parameterIndex) throws SQLException { - return null - } - - @Override - Time getTime(int parameterIndex) throws SQLException { - return null - } - - @Override - Timestamp getTimestamp(int parameterIndex) throws SQLException { - return null - } - - @Override - Object getObject(int parameterIndex) throws SQLException { - return null - } - - @Override - BigDecimal getBigDecimal(int parameterIndex) throws SQLException { - return null - } - - @Override - Object getObject(int parameterIndex, Map> map) throws SQLException { - return null - } - - @Override - Ref getRef(int parameterIndex) throws SQLException { - return null - } - - @Override - Blob getBlob(int parameterIndex) throws SQLException { - return null - } - - @Override - Clob getClob(int parameterIndex) throws SQLException { - return null - } - - @Override - Array getArray(int parameterIndex) throws SQLException { - return null - } - - @Override - Date getDate(int parameterIndex, Calendar cal) throws SQLException { - return null - } - - @Override - Time getTime(int parameterIndex, Calendar cal) throws SQLException { - return null - } - - @Override - Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { - return null - } - - @Override - void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { - - } - - @Override - void registerOutParameter(String parameterName, int sqlType) throws SQLException { - - } - - @Override - void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { - - } - - @Override - void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { - - } - - @Override - URL getURL(int parameterIndex) throws SQLException { - return null - } - - @Override - void setURL(String parameterName, URL val) throws SQLException { - - } - - @Override - void setNull(String parameterName, int sqlType) throws SQLException { - - } - - @Override - void setBoolean(String parameterName, boolean x) throws SQLException { - - } - - @Override - void setByte(String parameterName, byte x) throws SQLException { - - } - - @Override - void setShort(String parameterName, short x) throws SQLException { - - } - - @Override - void setInt(String parameterName, int x) throws SQLException { - - } - - @Override - void setLong(String parameterName, long x) throws SQLException { - - } - - @Override - void setFloat(String parameterName, float x) throws SQLException { - - } - - @Override - void setDouble(String parameterName, double x) throws SQLException { - - } - - @Override - void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { - - } - - @Override - void setString(String parameterName, String x) throws SQLException { - - } - - @Override - void setBytes(String parameterName, byte[] x) throws SQLException { - - } - - @Override - void setDate(String parameterName, Date x) throws SQLException { - - } - - @Override - void setTime(String parameterName, Time x) throws SQLException { - - } - - @Override - void setTimestamp(String parameterName, Timestamp x) throws SQLException { - - } - - @Override - void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException { - - } - - @Override - void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException { - - } - - @Override - void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { - - } - - @Override - void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { - - } - - @Override - void setObject(String parameterName, Object x) throws SQLException { - - } - - @Override - void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException { - - } - - @Override - void setDate(String parameterName, Date x, Calendar cal) throws SQLException { - - } - - @Override - void setTime(String parameterName, Time x, Calendar cal) throws SQLException { - - } - - @Override - void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException { - - } - - @Override - void setNull(String parameterName, int sqlType, String typeName) throws SQLException { - - } - - @Override - String getString(String parameterName) throws SQLException { - return null - } - - @Override - boolean getBoolean(String parameterName) throws SQLException { - return false - } - - @Override - byte getByte(String parameterName) throws SQLException { - return 0 - } - - @Override - short getShort(String parameterName) throws SQLException { - return 0 - } - - @Override - int getInt(String parameterName) throws SQLException { - return 0 - } - - @Override - long getLong(String parameterName) throws SQLException { - return 0 - } - - @Override - float getFloat(String parameterName) throws SQLException { - return 0 - } - - @Override - double getDouble(String parameterName) throws SQLException { - return 0 - } - - @Override - byte[] getBytes(String parameterName) throws SQLException { - return new byte[0] - } - - @Override - Date getDate(String parameterName) throws SQLException { - return null - } - - @Override - Time getTime(String parameterName) throws SQLException { - return null - } - - @Override - Timestamp getTimestamp(String parameterName) throws SQLException { - return null - } - - @Override - Object getObject(String parameterName) throws SQLException { - return null - } - - @Override - BigDecimal getBigDecimal(String parameterName) throws SQLException { - return null - } - - @Override - Object getObject(String parameterName, Map> map) throws SQLException { - return null - } - - @Override - Ref getRef(String parameterName) throws SQLException { - return null - } - - @Override - Blob getBlob(String parameterName) throws SQLException { - return null - } - - @Override - Clob getClob(String parameterName) throws SQLException { - return null - } - - @Override - Array getArray(String parameterName) throws SQLException { - return null - } - - @Override - Date getDate(String parameterName, Calendar cal) throws SQLException { - return null - } - - @Override - Time getTime(String parameterName, Calendar cal) throws SQLException { - return null - } - - @Override - Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { - return null - } - - @Override - URL getURL(String parameterName) throws SQLException { - return null - } - - @Override - RowId getRowId(int parameterIndex) throws SQLException { - return null - } - - @Override - RowId getRowId(String parameterName) throws SQLException { - return null - } - - @Override - void setRowId(String parameterName, RowId x) throws SQLException { - - } - - @Override - void setNString(String parameterName, String value) throws SQLException { - - } - - @Override - void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException { - - } - - @Override - void setNClob(String parameterName, NClob value) throws SQLException { - - } - - @Override - void setClob(String parameterName, Reader reader, long length) throws SQLException { - - } - - @Override - void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { - - } - - @Override - void setNClob(String parameterName, Reader reader, long length) throws SQLException { - - } - - @Override - NClob getNClob(int parameterIndex) throws SQLException { - return null - } - - @Override - NClob getNClob(String parameterName) throws SQLException { - return null - } - - @Override - void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { - - } - - @Override - SQLXML getSQLXML(int parameterIndex) throws SQLException { - return null - } - - @Override - SQLXML getSQLXML(String parameterName) throws SQLException { - return null - } - - @Override - String getNString(int parameterIndex) throws SQLException { - return null - } - - @Override - String getNString(String parameterName) throws SQLException { - return null - } - - @Override - Reader getNCharacterStream(int parameterIndex) throws SQLException { - return null - } - - @Override - Reader getNCharacterStream(String parameterName) throws SQLException { - return null - } - - @Override - Reader getCharacterStream(int parameterIndex) throws SQLException { - return null - } - - @Override - Reader getCharacterStream(String parameterName) throws SQLException { - return null - } - - @Override - void setBlob(String parameterName, Blob x) throws SQLException { - - } - - @Override - void setClob(String parameterName, Clob x) throws SQLException { - - } - - @Override - void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException { - - } - - @Override - void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException { - - } - - @Override - void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException { - - } - - @Override - void setAsciiStream(String parameterName, InputStream x) throws SQLException { - - } - - @Override - void setBinaryStream(String parameterName, InputStream x) throws SQLException { - - } - - @Override - void setCharacterStream(String parameterName, Reader reader) throws SQLException { - - } - - @Override - void setNCharacterStream(String parameterName, Reader value) throws SQLException { - - } - - @Override - void setClob(String parameterName, Reader reader) throws SQLException { - - } - - @Override - void setBlob(String parameterName, InputStream inputStream) throws SQLException { - - } - - @Override - void setNClob(String parameterName, Reader reader) throws SQLException { - - } - - @Override - def T getObject(int parameterIndex, Class type) throws SQLException { - return null - } - - @Override - def T getObject(String parameterName, Class type) throws SQLException { - return null - } -} diff --git a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestConnection.groovy b/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestConnection.groovy deleted file mode 100644 index abee3ad6b9e9..000000000000 --- a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestConnection.groovy +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.jdbc - -import java.sql.Array -import java.sql.Blob -import java.sql.CallableStatement -import java.sql.Clob -import java.sql.Connection -import java.sql.DatabaseMetaData -import java.sql.NClob -import java.sql.PreparedStatement -import java.sql.SQLClientInfoException -import java.sql.SQLException -import java.sql.SQLWarning -import java.sql.SQLXML -import java.sql.Savepoint -import java.sql.Statement -import java.sql.Struct -import java.util.concurrent.Executor - -/** - * A JDBC connection class that optionally throws an exception in the constructor, used to test - */ -class TestConnection implements Connection { - private String url - - TestConnection() { - this(false) - } - - TestConnection(boolean throwException) { - if (throwException) { - throw new IllegalStateException("connection exception") - } - } - - @Override - Statement createStatement() throws SQLException { - return new TestStatement(this) - } - - @Override - Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return new TestStatement(this) - } - - @Override - Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return new TestStatement(this) - } - - @Override - PreparedStatement prepareStatement(String sql) throws SQLException { - return new TestPreparedStatement(this) - } - - @Override - PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return new TestPreparedStatement(this) - } - - @Override - PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return new TestPreparedStatement(this) - } - - @Override - PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - return new TestPreparedStatement(this) - } - - @Override - PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - return new TestPreparedStatement(this) - } - - @Override - PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - return new TestPreparedStatement(this) - } - - @Override - CallableStatement prepareCall(String sql) throws SQLException { - return new TestCallableStatement() - } - - @Override - CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return new TestCallableStatement() - } - - @Override - CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return new TestCallableStatement() - } - - @Override - String nativeSQL(String sql) throws SQLException { - return null - } - - @Override - void setAutoCommit(boolean autoCommit) throws SQLException { - - } - - @Override - boolean getAutoCommit() throws SQLException { - return false - } - - @Override - void commit() throws SQLException { - - } - - @Override - void rollback() throws SQLException { - - } - - @Override - void close() throws SQLException { - - } - - @Override - boolean isClosed() throws SQLException { - return false - } - - @Override - DatabaseMetaData getMetaData() throws SQLException { - if (url) { - return new TestDatabaseMetaData(url) - } - return new TestDatabaseMetaData() - } - - @Override - void setReadOnly(boolean readOnly) throws SQLException { - - } - - @Override - boolean isReadOnly() throws SQLException { - return false - } - - @Override - void setCatalog(String catalog) throws SQLException { - - } - - @Override - String getCatalog() throws SQLException { - return null - } - - @Override - void setTransactionIsolation(int level) throws SQLException { - - } - - @Override - int getTransactionIsolation() throws SQLException { - return 0 - } - - @Override - SQLWarning getWarnings() throws SQLException { - return null - } - - @Override - void clearWarnings() throws SQLException { - - } - - @Override - Map> getTypeMap() throws SQLException { - return null - } - - @Override - void setTypeMap(Map> map) throws SQLException { - - } - - @Override - void setHoldability(int holdability) throws SQLException { - - } - - @Override - int getHoldability() throws SQLException { - return 0 - } - - @Override - Savepoint setSavepoint() throws SQLException { - return null - } - - @Override - Savepoint setSavepoint(String name) throws SQLException { - return null - } - - @Override - void rollback(Savepoint savepoint) throws SQLException { - - } - - @Override - void releaseSavepoint(Savepoint savepoint) throws SQLException { - - } - - @Override - Clob createClob() throws SQLException { - return null - } - - @Override - Blob createBlob() throws SQLException { - return null - } - - @Override - NClob createNClob() throws SQLException { - return null - } - - @Override - SQLXML createSQLXML() throws SQLException { - return null - } - - @Override - boolean isValid(int timeout) throws SQLException { - return false - } - - @Override - void setClientInfo(String name, String value) throws SQLClientInfoException { - - } - - @Override - void setClientInfo(Properties properties) throws SQLClientInfoException { - - } - - @Override - String getClientInfo(String name) throws SQLException { - throw new UnsupportedOperationException("Test 123") - } - - @Override - Properties getClientInfo() throws SQLException { - throw new Throwable("Test 123") - } - - @Override - Array createArrayOf(String typeName, Object[] elements) throws SQLException { - return null - } - - @Override - Struct createStruct(String typeName, Object[] attributes) throws SQLException { - return null - } - - @Override - void setSchema(String schema) throws SQLException { - - } - - @Override - String getSchema() throws SQLException { - return null - } - - @Override - void abort(Executor executor) throws SQLException { - - } - - @Override - void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - - } - - @Override - int getNetworkTimeout() throws SQLException { - return 0 - } - - @Override - def T unwrap(Class iface) throws SQLException { - return null - } - - @Override - boolean isWrapperFor(Class iface) throws SQLException { - return false - } - - void setUrl(String url) { - this.url = url - } -} diff --git a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.groovy b/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.groovy deleted file mode 100644 index a65835f08a9c..000000000000 --- a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.groovy +++ /dev/null @@ -1,904 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.jdbc - -import java.sql.Connection -import java.sql.DatabaseMetaData -import java.sql.ResultSet -import java.sql.RowIdLifetime -import java.sql.SQLException - -class TestDatabaseMetaData implements DatabaseMetaData { - final String url - - TestDatabaseMetaData() { - this("jdbc:postgresql://127.0.0.1:5432/dbname") - } - - TestDatabaseMetaData(String url) { - this.url = url - } - - @Override - boolean allProceduresAreCallable() throws SQLException { - return false - } - - @Override - boolean allTablesAreSelectable() throws SQLException { - return false - } - - @Override - String getURL() throws SQLException { - return url - } - - @Override - String getUserName() throws SQLException { - return null - } - - @Override - boolean isReadOnly() throws SQLException { - return false - } - - @Override - boolean nullsAreSortedHigh() throws SQLException { - return false - } - - @Override - boolean nullsAreSortedLow() throws SQLException { - return false - } - - @Override - boolean nullsAreSortedAtStart() throws SQLException { - return false - } - - @Override - boolean nullsAreSortedAtEnd() throws SQLException { - return false - } - - @Override - String getDatabaseProductName() throws SQLException { - return null - } - - @Override - String getDatabaseProductVersion() throws SQLException { - return null - } - - @Override - String getDriverName() throws SQLException { - return null - } - - @Override - String getDriverVersion() throws SQLException { - return null - } - - @Override - int getDriverMajorVersion() { - return 0 - } - - @Override - int getDriverMinorVersion() { - return 0 - } - - @Override - boolean usesLocalFiles() throws SQLException { - return false - } - - @Override - boolean usesLocalFilePerTable() throws SQLException { - return false - } - - @Override - boolean supportsMixedCaseIdentifiers() throws SQLException { - return false - } - - @Override - boolean storesUpperCaseIdentifiers() throws SQLException { - return false - } - - @Override - boolean storesLowerCaseIdentifiers() throws SQLException { - return false - } - - @Override - boolean storesMixedCaseIdentifiers() throws SQLException { - return false - } - - @Override - boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - return false - } - - @Override - boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - return false - } - - @Override - boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - return false - } - - @Override - boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - return false - } - - @Override - String getIdentifierQuoteString() throws SQLException { - return null - } - - @Override - String getSQLKeywords() throws SQLException { - return null - } - - @Override - String getNumericFunctions() throws SQLException { - return null - } - - @Override - String getStringFunctions() throws SQLException { - return null - } - - @Override - String getSystemFunctions() throws SQLException { - return null - } - - @Override - String getTimeDateFunctions() throws SQLException { - return null - } - - @Override - String getSearchStringEscape() throws SQLException { - return null - } - - @Override - String getExtraNameCharacters() throws SQLException { - return null - } - - @Override - boolean supportsAlterTableWithAddColumn() throws SQLException { - return false - } - - @Override - boolean supportsAlterTableWithDropColumn() throws SQLException { - return false - } - - @Override - boolean supportsColumnAliasing() throws SQLException { - return false - } - - @Override - boolean nullPlusNonNullIsNull() throws SQLException { - return false - } - - @Override - boolean supportsConvert() throws SQLException { - return false - } - - @Override - boolean supportsConvert(int fromType, int toType) throws SQLException { - return false - } - - @Override - boolean supportsTableCorrelationNames() throws SQLException { - return false - } - - @Override - boolean supportsDifferentTableCorrelationNames() throws SQLException { - return false - } - - @Override - boolean supportsExpressionsInOrderBy() throws SQLException { - return false - } - - @Override - boolean supportsOrderByUnrelated() throws SQLException { - return false - } - - @Override - boolean supportsGroupBy() throws SQLException { - return false - } - - @Override - boolean supportsGroupByUnrelated() throws SQLException { - return false - } - - @Override - boolean supportsGroupByBeyondSelect() throws SQLException { - return false - } - - @Override - boolean supportsLikeEscapeClause() throws SQLException { - return false - } - - @Override - boolean supportsMultipleResultSets() throws SQLException { - return false - } - - @Override - boolean supportsMultipleTransactions() throws SQLException { - return false - } - - @Override - boolean supportsNonNullableColumns() throws SQLException { - return false - } - - @Override - boolean supportsMinimumSQLGrammar() throws SQLException { - return false - } - - @Override - boolean supportsCoreSQLGrammar() throws SQLException { - return false - } - - @Override - boolean supportsExtendedSQLGrammar() throws SQLException { - return false - } - - @Override - boolean supportsANSI92EntryLevelSQL() throws SQLException { - return false - } - - @Override - boolean supportsANSI92IntermediateSQL() throws SQLException { - return false - } - - @Override - boolean supportsANSI92FullSQL() throws SQLException { - return false - } - - @Override - boolean supportsIntegrityEnhancementFacility() throws SQLException { - return false - } - - @Override - boolean supportsOuterJoins() throws SQLException { - return false - } - - @Override - boolean supportsFullOuterJoins() throws SQLException { - return false - } - - @Override - boolean supportsLimitedOuterJoins() throws SQLException { - return false - } - - @Override - String getSchemaTerm() throws SQLException { - return null - } - - @Override - String getProcedureTerm() throws SQLException { - return null - } - - @Override - String getCatalogTerm() throws SQLException { - return null - } - - @Override - boolean isCatalogAtStart() throws SQLException { - return false - } - - @Override - String getCatalogSeparator() throws SQLException { - return null - } - - @Override - boolean supportsSchemasInDataManipulation() throws SQLException { - return false - } - - @Override - boolean supportsSchemasInProcedureCalls() throws SQLException { - return false - } - - @Override - boolean supportsSchemasInTableDefinitions() throws SQLException { - return false - } - - @Override - boolean supportsSchemasInIndexDefinitions() throws SQLException { - return false - } - - @Override - boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - return false - } - - @Override - boolean supportsCatalogsInDataManipulation() throws SQLException { - return false - } - - @Override - boolean supportsCatalogsInProcedureCalls() throws SQLException { - return false - } - - @Override - boolean supportsCatalogsInTableDefinitions() throws SQLException { - return false - } - - @Override - boolean supportsCatalogsInIndexDefinitions() throws SQLException { - return false - } - - @Override - boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - return false - } - - @Override - boolean supportsPositionedDelete() throws SQLException { - return false - } - - @Override - boolean supportsPositionedUpdate() throws SQLException { - return false - } - - @Override - boolean supportsSelectForUpdate() throws SQLException { - return false - } - - @Override - boolean supportsStoredProcedures() throws SQLException { - return false - } - - @Override - boolean supportsSubqueriesInComparisons() throws SQLException { - return false - } - - @Override - boolean supportsSubqueriesInExists() throws SQLException { - return false - } - - @Override - boolean supportsSubqueriesInIns() throws SQLException { - return false - } - - @Override - boolean supportsSubqueriesInQuantifieds() throws SQLException { - return false - } - - @Override - boolean supportsCorrelatedSubqueries() throws SQLException { - return false - } - - @Override - boolean supportsUnion() throws SQLException { - return false - } - - @Override - boolean supportsUnionAll() throws SQLException { - return false - } - - @Override - boolean supportsOpenCursorsAcrossCommit() throws SQLException { - return false - } - - @Override - boolean supportsOpenCursorsAcrossRollback() throws SQLException { - return false - } - - @Override - boolean supportsOpenStatementsAcrossCommit() throws SQLException { - return false - } - - @Override - boolean supportsOpenStatementsAcrossRollback() throws SQLException { - return false - } - - @Override - int getMaxBinaryLiteralLength() throws SQLException { - return 0 - } - - @Override - int getMaxCharLiteralLength() throws SQLException { - return 0 - } - - @Override - int getMaxColumnNameLength() throws SQLException { - return 0 - } - - @Override - int getMaxColumnsInGroupBy() throws SQLException { - return 0 - } - - @Override - int getMaxColumnsInIndex() throws SQLException { - return 0 - } - - @Override - int getMaxColumnsInOrderBy() throws SQLException { - return 0 - } - - @Override - int getMaxColumnsInSelect() throws SQLException { - return 0 - } - - @Override - int getMaxColumnsInTable() throws SQLException { - return 0 - } - - @Override - int getMaxConnections() throws SQLException { - return 0 - } - - @Override - int getMaxCursorNameLength() throws SQLException { - return 0 - } - - @Override - int getMaxIndexLength() throws SQLException { - return 0 - } - - @Override - int getMaxSchemaNameLength() throws SQLException { - return 0 - } - - @Override - int getMaxProcedureNameLength() throws SQLException { - return 0 - } - - @Override - int getMaxCatalogNameLength() throws SQLException { - return 0 - } - - @Override - int getMaxRowSize() throws SQLException { - return 0 - } - - @Override - boolean doesMaxRowSizeIncludeBlobs() throws SQLException { - return false - } - - @Override - int getMaxStatementLength() throws SQLException { - return 0 - } - - @Override - int getMaxStatements() throws SQLException { - return 0 - } - - @Override - int getMaxTableNameLength() throws SQLException { - return 0 - } - - @Override - int getMaxTablesInSelect() throws SQLException { - return 0 - } - - @Override - int getMaxUserNameLength() throws SQLException { - return 0 - } - - @Override - int getDefaultTransactionIsolation() throws SQLException { - return 0 - } - - @Override - boolean supportsTransactions() throws SQLException { - return false - } - - @Override - boolean supportsTransactionIsolationLevel(int level) throws SQLException { - return false - } - - @Override - boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { - return false - } - - @Override - boolean supportsDataManipulationTransactionsOnly() throws SQLException { - return false - } - - @Override - boolean dataDefinitionCausesTransactionCommit() throws SQLException { - return false - } - - @Override - boolean dataDefinitionIgnoredInTransactions() throws SQLException { - return false - } - - @Override - ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { - return null - } - - @Override - ResultSet getSchemas() throws SQLException { - return null - } - - @Override - ResultSet getCatalogs() throws SQLException { - return null - } - - @Override - ResultSet getTableTypes() throws SQLException { - return null - } - - @Override - ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException { - return null - } - - @Override - ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { - return null - } - - @Override - ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { - return null - } - - @Override - ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { - return null - } - - @Override - ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { - return null - } - - @Override - ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { - return null - } - - @Override - ResultSet getTypeInfo() throws SQLException { - return null - } - - @Override - ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException { - return null - } - - @Override - boolean supportsResultSetType(int type) throws SQLException { - return false - } - - @Override - boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { - return false - } - - @Override - boolean ownUpdatesAreVisible(int type) throws SQLException { - return false - } - - @Override - boolean ownDeletesAreVisible(int type) throws SQLException { - return false - } - - @Override - boolean ownInsertsAreVisible(int type) throws SQLException { - return false - } - - @Override - boolean othersUpdatesAreVisible(int type) throws SQLException { - return false - } - - @Override - boolean othersDeletesAreVisible(int type) throws SQLException { - return false - } - - @Override - boolean othersInsertsAreVisible(int type) throws SQLException { - return false - } - - @Override - boolean updatesAreDetected(int type) throws SQLException { - return false - } - - @Override - boolean deletesAreDetected(int type) throws SQLException { - return false - } - - @Override - boolean insertsAreDetected(int type) throws SQLException { - return false - } - - @Override - boolean supportsBatchUpdates() throws SQLException { - return false - } - - @Override - ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException { - return null - } - - @Override - Connection getConnection() throws SQLException { - return null - } - - @Override - boolean supportsSavepoints() throws SQLException { - return false - } - - @Override - boolean supportsNamedParameters() throws SQLException { - return false - } - - @Override - boolean supportsMultipleOpenResults() throws SQLException { - return false - } - - @Override - boolean supportsGetGeneratedKeys() throws SQLException { - return false - } - - @Override - ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException { - return null - } - - @Override - boolean supportsResultSetHoldability(int holdability) throws SQLException { - return false - } - - @Override - int getResultSetHoldability() throws SQLException { - return 0 - } - - @Override - int getDatabaseMajorVersion() throws SQLException { - return 0 - } - - @Override - int getDatabaseMinorVersion() throws SQLException { - return 0 - } - - @Override - int getJDBCMajorVersion() throws SQLException { - return 0 - } - - @Override - int getJDBCMinorVersion() throws SQLException { - return 0 - } - - @Override - int getSQLStateType() throws SQLException { - return 0 - } - - @Override - boolean locatorsUpdateCopy() throws SQLException { - return false - } - - @Override - boolean supportsStatementPooling() throws SQLException { - return false - } - - @Override - RowIdLifetime getRowIdLifetime() throws SQLException { - return null - } - - @Override - ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - return null - } - - @Override - boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { - return false - } - - @Override - boolean autoCommitFailureClosesAllResultSets() throws SQLException { - return false - } - - @Override - ResultSet getClientInfoProperties() throws SQLException { - return null - } - - @Override - ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException { - return null - } - - @Override - ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { - return null - } - - @Override - boolean generatedKeyAlwaysReturned() throws SQLException { - return false - } - - @Override - def T unwrap(Class iface) throws SQLException { - return null - } - - @Override - boolean isWrapperFor(Class iface) throws SQLException { - return false - } -} diff --git a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDriver.groovy b/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDriver.groovy deleted file mode 100644 index 033cf445a60a..000000000000 --- a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestDriver.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.jdbc - - -import java.sql.Connection -import java.sql.Driver -import java.sql.DriverPropertyInfo -import java.sql.SQLException -import java.sql.SQLFeatureNotSupportedException -import java.util.logging.Logger - -class TestDriver implements Driver { - @Override - Connection connect(String url, Properties info) throws SQLException { - return new TestConnection() - } - - @Override - boolean acceptsURL(String url) throws SQLException { - return url?.startsWith("jdbc:test:") - } - - @Override - DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { - return [new DriverPropertyInfo("test", "test")] - } - - @Override - int getMajorVersion() { - return 0 - } - - @Override - int getMinorVersion() { - return 0 - } - - @Override - boolean jdbcCompliant() { - return false - } - - @Override - Logger getParentLogger() throws SQLFeatureNotSupportedException { - return null - } -} diff --git a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.groovy b/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.groovy deleted file mode 100644 index c8f21d061beb..000000000000 --- a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.groovy +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.jdbc - -import java.sql.Array -import java.sql.Blob -import java.sql.Clob -import java.sql.Connection -import java.sql.Date -import java.sql.NClob -import java.sql.ParameterMetaData -import java.sql.PreparedStatement -import java.sql.Ref -import java.sql.ResultSet -import java.sql.ResultSetMetaData -import java.sql.RowId -import java.sql.SQLException -import java.sql.SQLXML -import java.sql.Time -import java.sql.Timestamp - -class TestPreparedStatement extends TestStatement implements PreparedStatement { - - TestPreparedStatement() { - super() - } - - TestPreparedStatement(Connection connection) { - super(connection) - } - - @Override - boolean execute() throws SQLException { - return true - } - - @Override - ResultSet executeQuery() throws SQLException { - return null - } - - @Override - int executeUpdate() throws SQLException { - return 0 - } - - @Override - void setNull(int parameterIndex, int sqlType) throws SQLException { - - } - - @Override - void setBoolean(int parameterIndex, boolean x) throws SQLException { - - } - - @Override - void setByte(int parameterIndex, byte x) throws SQLException { - - } - - @Override - void setShort(int parameterIndex, short x) throws SQLException { - - } - - @Override - void setInt(int parameterIndex, int x) throws SQLException { - - } - - @Override - void setLong(int parameterIndex, long x) throws SQLException { - - } - - @Override - void setFloat(int parameterIndex, float x) throws SQLException { - - } - - @Override - void setDouble(int parameterIndex, double x) throws SQLException { - - } - - @Override - void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - - } - - @Override - void setString(int parameterIndex, String x) throws SQLException { - - } - - @Override - void setBytes(int parameterIndex, byte[] x) throws SQLException { - - } - - @Override - void setDate(int parameterIndex, Date x) throws SQLException { - - } - - @Override - void setTime(int parameterIndex, Time x) throws SQLException { - - } - - @Override - void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { - - } - - @Override - void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { - - } - - @Override - void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { - - } - - @Override - void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { - - } - - @Override - void clearParameters() throws SQLException { - - } - - @Override - void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { - - } - - @Override - void setObject(int parameterIndex, Object x) throws SQLException { - - } - - @Override - void addBatch() throws SQLException { - - } - - @Override - void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { - - } - - @Override - void setRef(int parameterIndex, Ref x) throws SQLException { - - } - - @Override - void setBlob(int parameterIndex, Blob x) throws SQLException { - - } - - @Override - void setClob(int parameterIndex, Clob x) throws SQLException { - - } - - @Override - void setArray(int parameterIndex, Array x) throws SQLException { - - } - - @Override - ResultSetMetaData getMetaData() throws SQLException { - return null - } - - @Override - void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { - - } - - @Override - void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { - - } - - @Override - void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { - - } - - @Override - void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { - - } - - @Override - void setURL(int parameterIndex, URL x) throws SQLException { - - } - - @Override - ParameterMetaData getParameterMetaData() throws SQLException { - return null - } - - @Override - void setRowId(int parameterIndex, RowId x) throws SQLException { - - } - - @Override - void setNString(int parameterIndex, String value) throws SQLException { - - } - - @Override - void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { - - } - - @Override - void setNClob(int parameterIndex, NClob value) throws SQLException { - - } - - @Override - void setClob(int parameterIndex, Reader reader, long length) throws SQLException { - - } - - @Override - void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { - - } - - @Override - void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { - - } - - @Override - void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { - - } - - @Override - void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { - - } - - @Override - void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { - - } - - @Override - void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { - - } - - @Override - void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { - - } - - @Override - void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { - - } - - @Override - void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { - - } - - @Override - void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { - - } - - @Override - void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { - - } - - @Override - void setClob(int parameterIndex, Reader reader) throws SQLException { - - } - - @Override - void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { - - } - - @Override - void setNClob(int parameterIndex, Reader reader) throws SQLException { - - } -} diff --git a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestStatement.groovy b/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestStatement.groovy deleted file mode 100644 index 4c833c93358c..000000000000 --- a/instrumentation/jdbc/testing/src/main/groovy/io/opentelemetry/instrumentation/jdbc/TestStatement.groovy +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.jdbc - -import java.sql.Connection -import java.sql.ResultSet -import java.sql.SQLException -import java.sql.SQLWarning -import java.sql.Statement - -class TestStatement implements Statement { - final Connection connection - - TestStatement() { - this.connection = null - } - - TestStatement(Connection connection) { - this.connection = connection - } - - @Override - ResultSet executeQuery(String sql) throws SQLException { - return null - } - - @Override - int executeUpdate(String sql) throws SQLException { - return 0 - } - - @Override - void close() throws SQLException { - - } - - @Override - int getMaxFieldSize() throws SQLException { - return 0 - } - - @Override - void setMaxFieldSize(int max) throws SQLException { - - } - - @Override - int getMaxRows() throws SQLException { - return 0 - } - - @Override - void setMaxRows(int max) throws SQLException { - - } - - @Override - void setEscapeProcessing(boolean enable) throws SQLException { - - } - - @Override - int getQueryTimeout() throws SQLException { - return 0 - } - - @Override - void setQueryTimeout(int seconds) throws SQLException { - - } - - @Override - void cancel() throws SQLException { - - } - - @Override - SQLWarning getWarnings() throws SQLException { - return null - } - - @Override - void clearWarnings() throws SQLException { - - } - - @Override - void setCursorName(String name) throws SQLException { - - } - - @Override - boolean execute(String sql) throws SQLException { - return true - } - - @Override - ResultSet getResultSet() throws SQLException { - return null - } - - @Override - int getUpdateCount() throws SQLException { - return 0 - } - - @Override - boolean getMoreResults() throws SQLException { - return false - } - - @Override - void setFetchDirection(int direction) throws SQLException { - - } - - @Override - int getFetchDirection() throws SQLException { - return 0 - } - - @Override - void setFetchSize(int rows) throws SQLException { - - } - - @Override - int getFetchSize() throws SQLException { - return 0 - } - - @Override - int getResultSetConcurrency() throws SQLException { - return 0 - } - - @Override - int getResultSetType() throws SQLException { - return 0 - } - - @Override - void addBatch(String sql) throws SQLException { - - } - - @Override - void clearBatch() throws SQLException { - - } - - @Override - int[] executeBatch() throws SQLException { - return new int[0] - } - - @Override - Connection getConnection() throws SQLException { - return connection - } - - @Override - boolean getMoreResults(int current) throws SQLException { - return false - } - - @Override - ResultSet getGeneratedKeys() throws SQLException { - return null - } - - @Override - int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - return 0 - } - - @Override - int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - return 0 - } - - @Override - int executeUpdate(String sql, String[] columnNames) throws SQLException { - return 0 - } - - @Override - boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - return true - } - - @Override - boolean execute(String sql, int[] columnIndexes) throws SQLException { - return true - } - - @Override - boolean execute(String sql, String[] columnNames) throws SQLException { - return true - } - - @Override - int getResultSetHoldability() throws SQLException { - return 0 - } - - @Override - boolean isClosed() throws SQLException { - return false - } - - @Override - void setPoolable(boolean poolable) throws SQLException { - - } - - @Override - boolean isPoolable() throws SQLException { - return false - } - - @Override - void closeOnCompletion() throws SQLException { - - } - - @Override - boolean isCloseOnCompletion() throws SQLException { - return false - } - - @Override - def T unwrap(Class iface) throws SQLException { - return null - } - - @Override - boolean isWrapperFor(Class iface) throws SQLException { - return false - } -} diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.java new file mode 100644 index 000000000000..a25b1a3d72c0 --- /dev/null +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/AnotherTestDriver.java @@ -0,0 +1,51 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jdbc; + +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.Properties; +import java.util.logging.Logger; + +class AnotherTestDriver implements Driver { + @Override + public Connection connect(String url, Properties info) throws SQLException { + return null; + } + + @Override + public boolean acceptsURL(String url) throws SQLException { + return false; + } + + @Override + public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { + return new DriverPropertyInfo[0]; + } + + @Override + public int getMajorVersion() { + return 0; + } + + @Override + public int getMinorVersion() { + return 0; + } + + @Override + public boolean jdbcCompliant() { + return false; + } + + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return null; + } +} diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java new file mode 100644 index 000000000000..144a320fb402 --- /dev/null +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java @@ -0,0 +1,504 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jdbc; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Map; + +@SuppressWarnings("UngroupedOverloads") +class TestCallableStatement extends TestPreparedStatement implements CallableStatement { + @Override + public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {} + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, int scale) + throws SQLException {} + + @Override + public boolean wasNull() throws SQLException { + return false; + } + + @Override + public String getString(int parameterIndex) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(int parameterIndex) throws SQLException { + return false; + } + + @Override + public byte getByte(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public short getShort(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public int getInt(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public long getLong(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public float getFloat(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public double getDouble(int parameterIndex) throws SQLException { + return 0; + } + + @Override + @Deprecated + public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { + return null; + } + + @Override + public byte[] getBytes(int parameterIndex) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Time getTime(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(int parameterIndex) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(int parameterIndex, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Blob getBlob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Clob getClob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Array getArray(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Date getDate(int parameterIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(int parameterIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, String typeName) + throws SQLException {} + + @Override + public void registerOutParameter(String parameterName, int sqlType) throws SQLException {} + + @Override + public void registerOutParameter(String parameterName, int sqlType, int scale) + throws SQLException {} + + @Override + public void registerOutParameter(String parameterName, int sqlType, String typeName) + throws SQLException {} + + @Override + public URL getURL(int parameterIndex) throws SQLException { + return null; + } + + @Override + public void setURL(String parameterName, URL val) throws SQLException {} + + @Override + public void setNull(String parameterName, int sqlType) throws SQLException {} + + @Override + public void setBoolean(String parameterName, boolean x) throws SQLException {} + + @Override + public void setByte(String parameterName, byte x) throws SQLException {} + + @Override + public void setShort(String parameterName, short x) throws SQLException {} + + @Override + public void setInt(String parameterName, int x) throws SQLException {} + + @Override + public void setLong(String parameterName, long x) throws SQLException {} + + @Override + public void setFloat(String parameterName, float x) throws SQLException {} + + @Override + public void setDouble(String parameterName, double x) throws SQLException {} + + @Override + public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {} + + @Override + public void setString(String parameterName, String x) throws SQLException {} + + @Override + public void setBytes(String parameterName, byte[] x) throws SQLException {} + + @Override + public void setDate(String parameterName, Date x) throws SQLException {} + + @Override + public void setTime(String parameterName, Time x) throws SQLException {} + + @Override + public void setTimestamp(String parameterName, Timestamp x) throws SQLException {} + + @Override + public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {} + + @Override + public void setBinaryStream(String parameterName, InputStream x, int length) + throws SQLException {} + + @Override + public void setObject(String parameterName, Object x, int targetSqlType, int scale) + throws SQLException {} + + @Override + public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {} + + @Override + public void setObject(String parameterName, Object x) throws SQLException {} + + @Override + public void setCharacterStream(String parameterName, Reader reader, int length) + throws SQLException {} + + @Override + public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {} + + @Override + public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {} + + @Override + public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {} + + @Override + public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {} + + @Override + public String getString(String parameterName) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(String parameterName) throws SQLException { + return false; + } + + @Override + public byte getByte(String parameterName) throws SQLException { + return 0; + } + + @Override + public short getShort(String parameterName) throws SQLException { + return 0; + } + + @Override + public int getInt(String parameterName) throws SQLException { + return 0; + } + + @Override + public long getLong(String parameterName) throws SQLException { + return 0; + } + + @Override + public float getFloat(String parameterName) throws SQLException { + return 0; + } + + @Override + public double getDouble(String parameterName) throws SQLException { + return 0; + } + + @Override + public byte[] getBytes(String parameterName) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(String parameterName) throws SQLException { + return null; + } + + @Override + public Time getTime(String parameterName) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String parameterName) throws SQLException { + return null; + } + + @Override + public Object getObject(String parameterName) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(String parameterName) throws SQLException { + return null; + } + + @Override + public Object getObject(String parameterName, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(String parameterName) throws SQLException { + return null; + } + + @Override + public Blob getBlob(String parameterName) throws SQLException { + return null; + } + + @Override + public Clob getClob(String parameterName) throws SQLException { + return null; + } + + @Override + public Array getArray(String parameterName) throws SQLException { + return null; + } + + @Override + public Date getDate(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public URL getURL(String parameterName) throws SQLException { + return null; + } + + @Override + public RowId getRowId(int parameterIndex) throws SQLException { + return null; + } + + @Override + public RowId getRowId(String parameterName) throws SQLException { + return null; + } + + @Override + public void setRowId(String parameterName, RowId x) throws SQLException {} + + @Override + public void setNString(String parameterName, String value) throws SQLException {} + + @Override + public void setNCharacterStream(String parameterName, Reader value, long length) + throws SQLException {} + + @Override + public void setNClob(String parameterName, NClob value) throws SQLException {} + + @Override + public void setClob(String parameterName, Reader reader, long length) throws SQLException {} + + @Override + public void setBlob(String parameterName, InputStream inputStream, long length) + throws SQLException {} + + @Override + public void setNClob(String parameterName, Reader reader, long length) throws SQLException {} + + @Override + public NClob getNClob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public NClob getNClob(String parameterName) throws SQLException { + return null; + } + + @Override + public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {} + + @Override + public SQLXML getSQLXML(int parameterIndex) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(String parameterName) throws SQLException { + return null; + } + + @Override + public String getNString(int parameterIndex) throws SQLException { + return null; + } + + @Override + public String getNString(String parameterName) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(String parameterName) throws SQLException { + return null; + } + + @Override + public Reader getCharacterStream(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Reader getCharacterStream(String parameterName) throws SQLException { + return null; + } + + @Override + public void setBlob(String parameterName, Blob x) throws SQLException {} + + @Override + public void setClob(String parameterName, Clob x) throws SQLException {} + + @Override + public void setAsciiStream(String parameterName, InputStream x, long length) + throws SQLException {} + + @Override + public void setBinaryStream(String parameterName, InputStream x, long length) + throws SQLException {} + + @Override + public void setCharacterStream(String parameterName, Reader reader, long length) + throws SQLException {} + + @Override + public void setAsciiStream(String parameterName, InputStream x) throws SQLException {} + + @Override + public void setBinaryStream(String parameterName, InputStream x) throws SQLException {} + + @Override + public void setCharacterStream(String parameterName, Reader reader) throws SQLException {} + + @Override + public void setNCharacterStream(String parameterName, Reader value) throws SQLException {} + + @Override + public void setClob(String parameterName, Reader reader) throws SQLException {} + + @Override + public void setBlob(String parameterName, InputStream inputStream) throws SQLException {} + + @Override + public void setNClob(String parameterName, Reader reader) throws SQLException {} + + @Override + public T getObject(int parameterIndex, Class type) throws SQLException { + return null; + } + + @Override + public T getObject(String parameterName, Class type) throws SQLException { + return null; + } +} diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java new file mode 100644 index 000000000000..c5862d353aa5 --- /dev/null +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java @@ -0,0 +1,293 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jdbc; + +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.NClob; +import java.sql.PreparedStatement; +import java.sql.SQLClientInfoException; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Savepoint; +import java.sql.Statement; +import java.sql.Struct; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Executor; + +/** A JDBC connection class that optionally throws an exception in the constructor, used to test */ +public class TestConnection implements Connection { + private String url; + + public TestConnection() { + this(false); + } + + public TestConnection(boolean throwException) { + if (throwException) { + throw new IllegalStateException("connection exception"); + } + } + + @Override + public Statement createStatement() throws SQLException { + return new TestStatement(this); + } + + @Override + public Statement createStatement(int resultSetType, int resultSetConcurrency) + throws SQLException { + return new TestStatement(this); + } + + @Override + public Statement createStatement( + int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { + return new TestStatement(this); + } + + @Override + public PreparedStatement prepareStatement(String sql) throws SQLException { + return new TestPreparedStatement(this); + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return new TestPreparedStatement(this); + } + + @Override + public PreparedStatement prepareStatement( + String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return new TestPreparedStatement(this); + } + + @Override + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { + return new TestPreparedStatement(this); + } + + @Override + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { + return new TestPreparedStatement(this); + } + + @Override + public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { + return new TestPreparedStatement(this); + } + + @Override + public CallableStatement prepareCall(String sql) throws SQLException { + return new TestCallableStatement(); + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return new TestCallableStatement(); + } + + @Override + public CallableStatement prepareCall( + String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return new TestCallableStatement(); + } + + @Override + public String nativeSQL(String sql) throws SQLException { + return null; + } + + @Override + public void setAutoCommit(boolean autoCommit) throws SQLException {} + + @Override + public boolean getAutoCommit() throws SQLException { + return false; + } + + @Override + public void commit() throws SQLException {} + + @Override + public void close() throws SQLException {} + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public DatabaseMetaData getMetaData() throws SQLException { + if (url != null) { + return new TestDatabaseMetaData(url); + } + return new TestDatabaseMetaData(); + } + + @Override + public void setReadOnly(boolean readOnly) throws SQLException {} + + @Override + public boolean isReadOnly() throws SQLException { + return false; + } + + @Override + public void setCatalog(String catalog) throws SQLException {} + + @Override + public String getCatalog() throws SQLException { + return null; + } + + @Override + public void setTransactionIsolation(int level) throws SQLException {} + + @Override + public int getTransactionIsolation() throws SQLException { + return 0; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException {} + + @Override + public Map> getTypeMap() throws SQLException { + return new HashMap<>(); + } + + @Override + public void setTypeMap(Map> map) throws SQLException {} + + @Override + public void setHoldability(int holdability) throws SQLException {} + + @Override + public int getHoldability() throws SQLException { + return 0; + } + + @Override + public Savepoint setSavepoint() throws SQLException { + return null; + } + + @Override + public Savepoint setSavepoint(String name) throws SQLException { + return null; + } + + @Override + public void rollback(Savepoint savepoint) throws SQLException {} + + @Override + public void rollback() throws SQLException {} + + @Override + public void releaseSavepoint(Savepoint savepoint) throws SQLException {} + + @Override + public Clob createClob() throws SQLException { + return null; + } + + @Override + public Blob createBlob() throws SQLException { + return null; + } + + @Override + public NClob createNClob() throws SQLException { + return null; + } + + @Override + public SQLXML createSQLXML() throws SQLException { + return null; + } + + @Override + public boolean isValid(int timeout) throws SQLException { + return false; + } + + @Override + public void setClientInfo(String name, String value) throws SQLClientInfoException {} + + @Override + public void setClientInfo(Properties properties) throws SQLClientInfoException {} + + @Override + public String getClientInfo(String name) throws SQLException { + throw new UnsupportedOperationException("Test 123"); + } + + @Override + public Properties getClientInfo() throws SQLException { + // TODO throwable + throw new UnsupportedOperationException("Test 123"); + } + + @Override + public Array createArrayOf(String typeName, Object[] elements) throws SQLException { + return null; + } + + @Override + public Struct createStruct(String typeName, Object[] attributes) throws SQLException { + return null; + } + + @Override + public void setSchema(String schema) throws SQLException {} + + @Override + public String getSchema() throws SQLException { + return null; + } + + @Override + public void abort(Executor executor) throws SQLException {} + + @Override + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {} + + @Override + public int getNetworkTimeout() throws SQLException { + return 0; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } + + void setUrl(String url) { + this.url = url; + } +} diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java new file mode 100644 index 000000000000..2e478f3b4464 --- /dev/null +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java @@ -0,0 +1,940 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jdbc; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.RowIdLifetime; +import java.sql.SQLException; + +@SuppressWarnings("UngroupedOverloads") +class TestDatabaseMetaData implements DatabaseMetaData { + final String url; + + TestDatabaseMetaData() { + this("jdbc:postgresql://127.0.0.1:5432/dbname"); + } + + TestDatabaseMetaData(String url) { + this.url = url; + } + + @Override + public boolean allProceduresAreCallable() throws SQLException { + return false; + } + + @Override + public boolean allTablesAreSelectable() throws SQLException { + return false; + } + + @Override + public String getURL() throws SQLException { + return url; + } + + @Override + public String getUserName() throws SQLException { + return null; + } + + @Override + public boolean isReadOnly() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedHigh() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedLow() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedAtStart() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedAtEnd() throws SQLException { + return false; + } + + @Override + public String getDatabaseProductName() throws SQLException { + return null; + } + + @Override + public String getDatabaseProductVersion() throws SQLException { + return null; + } + + @Override + public String getDriverName() throws SQLException { + return null; + } + + @Override + public String getDriverVersion() throws SQLException { + return null; + } + + @Override + public int getDriverMajorVersion() { + return 0; + } + + @Override + public int getDriverMinorVersion() { + return 0; + } + + @Override + public boolean usesLocalFiles() throws SQLException { + return false; + } + + @Override + public boolean usesLocalFilePerTable() throws SQLException { + return false; + } + + @Override + public boolean supportsMixedCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesUpperCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesLowerCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesMixedCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public String getIdentifierQuoteString() throws SQLException { + return null; + } + + @Override + public String getSQLKeywords() throws SQLException { + return null; + } + + @Override + public String getNumericFunctions() throws SQLException { + return null; + } + + @Override + public String getStringFunctions() throws SQLException { + return null; + } + + @Override + public String getSystemFunctions() throws SQLException { + return null; + } + + @Override + public String getTimeDateFunctions() throws SQLException { + return null; + } + + @Override + public String getSearchStringEscape() throws SQLException { + return null; + } + + @Override + public String getExtraNameCharacters() throws SQLException { + return null; + } + + @Override + public boolean supportsAlterTableWithAddColumn() throws SQLException { + return false; + } + + @Override + public boolean supportsAlterTableWithDropColumn() throws SQLException { + return false; + } + + @Override + public boolean supportsColumnAliasing() throws SQLException { + return false; + } + + @Override + public boolean nullPlusNonNullIsNull() throws SQLException { + return false; + } + + @Override + public boolean supportsConvert() throws SQLException { + return false; + } + + @Override + public boolean supportsConvert(int fromType, int toType) throws SQLException { + return false; + } + + @Override + public boolean supportsTableCorrelationNames() throws SQLException { + return false; + } + + @Override + public boolean supportsDifferentTableCorrelationNames() throws SQLException { + return false; + } + + @Override + public boolean supportsExpressionsInOrderBy() throws SQLException { + return false; + } + + @Override + public boolean supportsOrderByUnrelated() throws SQLException { + return false; + } + + @Override + public boolean supportsGroupBy() throws SQLException { + return false; + } + + @Override + public boolean supportsGroupByUnrelated() throws SQLException { + return false; + } + + @Override + public boolean supportsGroupByBeyondSelect() throws SQLException { + return false; + } + + @Override + public boolean supportsLikeEscapeClause() throws SQLException { + return false; + } + + @Override + public boolean supportsMultipleResultSets() throws SQLException { + return false; + } + + @Override + public boolean supportsMultipleTransactions() throws SQLException { + return false; + } + + @Override + public boolean supportsNonNullableColumns() throws SQLException { + return false; + } + + @Override + public boolean supportsMinimumSQLGrammar() throws SQLException { + return false; + } + + @Override + public boolean supportsCoreSQLGrammar() throws SQLException { + return false; + } + + @Override + public boolean supportsExtendedSQLGrammar() throws SQLException { + return false; + } + + @Override + public boolean supportsANSI92EntryLevelSQL() throws SQLException { + return false; + } + + @Override + public boolean supportsANSI92IntermediateSQL() throws SQLException { + return false; + } + + @Override + public boolean supportsANSI92FullSQL() throws SQLException { + return false; + } + + @Override + public boolean supportsIntegrityEnhancementFacility() throws SQLException { + return false; + } + + @Override + public boolean supportsOuterJoins() throws SQLException { + return false; + } + + @Override + public boolean supportsFullOuterJoins() throws SQLException { + return false; + } + + @Override + public boolean supportsLimitedOuterJoins() throws SQLException { + return false; + } + + @Override + public String getSchemaTerm() throws SQLException { + return null; + } + + @Override + public String getProcedureTerm() throws SQLException { + return null; + } + + @Override + public String getCatalogTerm() throws SQLException { + return null; + } + + @Override + public boolean isCatalogAtStart() throws SQLException { + return false; + } + + @Override + public String getCatalogSeparator() throws SQLException { + return null; + } + + @Override + public boolean supportsSchemasInDataManipulation() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInProcedureCalls() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInTableDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInIndexDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInDataManipulation() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInProcedureCalls() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInTableDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInIndexDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsPositionedDelete() throws SQLException { + return false; + } + + @Override + public boolean supportsPositionedUpdate() throws SQLException { + return false; + } + + @Override + public boolean supportsSelectForUpdate() throws SQLException { + return false; + } + + @Override + public boolean supportsStoredProcedures() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInComparisons() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInExists() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInIns() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInQuantifieds() throws SQLException { + return false; + } + + @Override + public boolean supportsCorrelatedSubqueries() throws SQLException { + return false; + } + + @Override + public boolean supportsUnion() throws SQLException { + return false; + } + + @Override + public boolean supportsUnionAll() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenCursorsAcrossCommit() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenCursorsAcrossRollback() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenStatementsAcrossCommit() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenStatementsAcrossRollback() throws SQLException { + return false; + } + + @Override + public int getMaxBinaryLiteralLength() throws SQLException { + return 0; + } + + @Override + public int getMaxCharLiteralLength() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInGroupBy() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInIndex() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInOrderBy() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInSelect() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInTable() throws SQLException { + return 0; + } + + @Override + public int getMaxConnections() throws SQLException { + return 0; + } + + @Override + public int getMaxCursorNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxIndexLength() throws SQLException { + return 0; + } + + @Override + public int getMaxSchemaNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxProcedureNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxCatalogNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxRowSize() throws SQLException { + return 0; + } + + @Override + public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { + return false; + } + + @Override + public int getMaxStatementLength() throws SQLException { + return 0; + } + + @Override + public int getMaxStatements() throws SQLException { + return 0; + } + + @Override + public int getMaxTableNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxTablesInSelect() throws SQLException { + return 0; + } + + @Override + public int getMaxUserNameLength() throws SQLException { + return 0; + } + + @Override + public int getDefaultTransactionIsolation() throws SQLException { + return 0; + } + + @Override + public boolean supportsTransactions() throws SQLException { + return false; + } + + @Override + public boolean supportsTransactionIsolationLevel(int level) throws SQLException { + return false; + } + + @Override + public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { + return false; + } + + @Override + public boolean supportsDataManipulationTransactionsOnly() throws SQLException { + return false; + } + + @Override + public boolean dataDefinitionCausesTransactionCommit() throws SQLException { + return false; + } + + @Override + public boolean dataDefinitionIgnoredInTransactions() throws SQLException { + return false; + } + + @Override + public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getProcedureColumns( + String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getTables( + String catalog, String schemaPattern, String tableNamePattern, String[] types) + throws SQLException { + return null; + } + + @Override + public ResultSet getCatalogs() throws SQLException { + return null; + } + + @Override + public ResultSet getTableTypes() throws SQLException { + return null; + } + + @Override + public ResultSet getColumns( + String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getColumnPrivileges( + String catalog, String schema, String table, String columnNamePattern) throws SQLException { + return null; + } + + @Override + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getBestRowIdentifier( + String catalog, String schema, String table, int scope, boolean nullable) + throws SQLException { + return null; + } + + @Override + public ResultSet getVersionColumns(String catalog, String schema, String table) + throws SQLException { + return null; + } + + @Override + public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { + return null; + } + + @Override + public ResultSet getImportedKeys(String catalog, String schema, String table) + throws SQLException { + return null; + } + + @Override + public ResultSet getExportedKeys(String catalog, String schema, String table) + throws SQLException { + return null; + } + + @Override + public ResultSet getCrossReference( + String parentCatalog, + String parentSchema, + String parentTable, + String foreignCatalog, + String foreignSchema, + String foreignTable) + throws SQLException { + return null; + } + + @Override + public ResultSet getTypeInfo() throws SQLException { + return null; + } + + @Override + public ResultSet getIndexInfo( + String catalog, String schema, String table, boolean unique, boolean approximate) + throws SQLException { + return null; + } + + @Override + public boolean supportsResultSetType(int type) throws SQLException { + return false; + } + + @Override + public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { + return false; + } + + @Override + public boolean ownUpdatesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean ownDeletesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean ownInsertsAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean othersUpdatesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean othersDeletesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean othersInsertsAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean updatesAreDetected(int type) throws SQLException { + return false; + } + + @Override + public boolean deletesAreDetected(int type) throws SQLException { + return false; + } + + @Override + public boolean insertsAreDetected(int type) throws SQLException { + return false; + } + + @Override + public boolean supportsBatchUpdates() throws SQLException { + return false; + } + + @Override + public ResultSet getUDTs( + String catalog, String schemaPattern, String typeNamePattern, int[] types) + throws SQLException { + return null; + } + + @Override + public Connection getConnection() throws SQLException { + return null; + } + + @Override + public boolean supportsSavepoints() throws SQLException { + return false; + } + + @Override + public boolean supportsNamedParameters() throws SQLException { + return false; + } + + @Override + public boolean supportsMultipleOpenResults() throws SQLException { + return false; + } + + @Override + public boolean supportsGetGeneratedKeys() throws SQLException { + return false; + } + + @Override + public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getAttributes( + String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) + throws SQLException { + return null; + } + + @Override + public boolean supportsResultSetHoldability(int holdability) throws SQLException { + return false; + } + + @Override + public int getResultSetHoldability() throws SQLException { + return 0; + } + + @Override + public int getDatabaseMajorVersion() throws SQLException { + return 0; + } + + @Override + public int getDatabaseMinorVersion() throws SQLException { + return 0; + } + + @Override + public int getJDBCMajorVersion() throws SQLException { + return 0; + } + + @Override + public int getJDBCMinorVersion() throws SQLException { + return 0; + } + + @Override + public int getSQLStateType() throws SQLException { + return 0; + } + + @Override + public boolean locatorsUpdateCopy() throws SQLException { + return false; + } + + @Override + public boolean supportsStatementPooling() throws SQLException { + return false; + } + + @Override + public RowIdLifetime getRowIdLifetime() throws SQLException { + return null; + } + + @Override + public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { + return null; + } + + @Override + public ResultSet getSchemas() throws SQLException { + return null; + } + + @Override + public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { + return false; + } + + @Override + public boolean autoCommitFailureClosesAllResultSets() throws SQLException { + return false; + } + + @Override + public ResultSet getClientInfoProperties() throws SQLException { + return null; + } + + @Override + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getFunctionColumns( + String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getPseudoColumns( + String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) + throws SQLException { + return null; + } + + @Override + public boolean generatedKeyAlwaysReturned() throws SQLException { + ; + return false; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } +} diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java new file mode 100644 index 000000000000..05032de7be47 --- /dev/null +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java @@ -0,0 +1,52 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jdbc; + +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.Properties; +import java.util.logging.Logger; + +class TestDriver implements Driver { + @Override + public Connection connect(String url, Properties info) throws SQLException { + return new TestConnection(); + } + + @Override + public boolean acceptsURL(String url) throws SQLException { + return url.startsWith("jdbc:test:"); + } + + @Override + public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { + DriverPropertyInfo driverPropertyInfo = new DriverPropertyInfo("test", "test"); + return new DriverPropertyInfo[] {driverPropertyInfo}; + } + + @Override + public int getMajorVersion() { + return 0; + } + + @Override + public int getMinorVersion() { + return 0; + } + + @Override + public boolean jdbcCompliant() { + return false; + } + + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return null; + } +} diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java new file mode 100644 index 000000000000..dcf86d958b3b --- /dev/null +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java @@ -0,0 +1,221 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jdbc; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.Date; +import java.sql.NClob; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; + +@SuppressWarnings("UngroupedOverloads") +class TestPreparedStatement extends TestStatement implements PreparedStatement { + + TestPreparedStatement() { + super(); + } + + TestPreparedStatement(Connection connection) { + super(connection); + } + + @Override + public boolean execute() throws SQLException { + return true; + } + + @Override + public ResultSet executeQuery() throws SQLException { + return null; + } + + @Override + public int executeUpdate() throws SQLException { + return 0; + } + + @Override + public void setNull(int parameterIndex, int sqlType) throws SQLException {} + + @Override + public void setBoolean(int parameterIndex, boolean x) throws SQLException {} + + @Override + public void setByte(int parameterIndex, byte x) throws SQLException {} + + @Override + public void setShort(int parameterIndex, short x) throws SQLException {} + + @Override + public void setInt(int parameterIndex, int x) throws SQLException {} + + @Override + public void setLong(int parameterIndex, long x) throws SQLException {} + + @Override + public void setFloat(int parameterIndex, float x) throws SQLException {} + + @Override + public void setDouble(int parameterIndex, double x) throws SQLException {} + + @Override + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {} + + @Override + public void setString(int parameterIndex, String x) throws SQLException {} + + @Override + public void setBytes(int parameterIndex, byte[] x) throws SQLException {} + + @Override + public void setDate(int parameterIndex, Date x) throws SQLException {} + + @Override + public void setTime(int parameterIndex, Time x) throws SQLException {} + + @Override + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {} + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {} + + @Override + @Deprecated + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {} + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {} + + @Override + public void clearParameters() throws SQLException {} + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {} + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException {} + + @Override + public void addBatch() throws SQLException {} + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, int length) + throws SQLException {} + + @Override + public void setRef(int parameterIndex, Ref x) throws SQLException {} + + @Override + public void setBlob(int parameterIndex, Blob x) throws SQLException {} + + @Override + public void setClob(int parameterIndex, Clob x) throws SQLException {} + + @Override + public void setArray(int parameterIndex, Array x) throws SQLException {} + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return null; + } + + @Override + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {} + + @Override + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {} + + @Override + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {} + + @Override + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {} + + @Override + public void setURL(int parameterIndex, URL x) throws SQLException {} + + @Override + public ParameterMetaData getParameterMetaData() throws SQLException { + return null; + } + + @Override + public void setRowId(int parameterIndex, RowId x) throws SQLException {} + + @Override + public void setNString(int parameterIndex, String value) throws SQLException {} + + @Override + public void setNCharacterStream(int parameterIndex, Reader value, long length) + throws SQLException {} + + @Override + public void setNClob(int parameterIndex, NClob value) throws SQLException {} + + @Override + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {} + + @Override + public void setBlob(int parameterIndex, InputStream inputStream, long length) + throws SQLException {} + + @Override + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {} + + @Override + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {} + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) + throws SQLException {} + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {} + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {} + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, long length) + throws SQLException {} + + @Override + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {} + + @Override + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {} + + @Override + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {} + + @Override + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {} + + @Override + public void setClob(int parameterIndex, Reader reader) throws SQLException {} + + @Override + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {} + + @Override + public void setNClob(int parameterIndex, Reader reader) throws SQLException {} +} diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java new file mode 100644 index 000000000000..644c333cf500 --- /dev/null +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java @@ -0,0 +1,217 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jdbc; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Statement; + +@SuppressWarnings("UngroupedOverloads") +class TestStatement implements Statement { + final Connection connection; + + TestStatement() { + this.connection = null; + } + + TestStatement(Connection connection) { + this.connection = connection; + } + + @Override + public ResultSet executeQuery(String sql) throws SQLException { + return null; + } + + @Override + public int executeUpdate(String sql) throws SQLException { + return 0; + } + + @Override + public void close() throws SQLException {} + + @Override + public int getMaxFieldSize() throws SQLException { + return 0; + } + + @Override + public void setMaxFieldSize(int max) throws SQLException {} + + @Override + public int getMaxRows() throws SQLException { + return 0; + } + + @Override + public void setMaxRows(int max) throws SQLException {} + + @Override + public void setEscapeProcessing(boolean enable) throws SQLException {} + + @Override + public int getQueryTimeout() throws SQLException { + return 0; + } + + @Override + public void setQueryTimeout(int seconds) throws SQLException {} + + @Override + public void cancel() throws SQLException {} + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException {} + + @Override + public void setCursorName(String name) throws SQLException {} + + @Override + public boolean execute(String sql) throws SQLException { + return true; + } + + @Override + public ResultSet getResultSet() throws SQLException { + return null; + } + + @Override + public int getUpdateCount() throws SQLException { + return 0; + } + + @Override + public boolean getMoreResults() throws SQLException { + return false; + } + + @Override + public int getFetchDirection() throws SQLException { + return 0; + } + + @Override + public void setFetchDirection(int direction) throws SQLException {} + + @Override + public int getFetchSize() throws SQLException { + return 0; + } + + @Override + public void setFetchSize(int rows) throws SQLException {} + + @Override + public int getResultSetConcurrency() throws SQLException { + return 0; + } + + @Override + public int getResultSetType() throws SQLException { + return 0; + } + + @Override + public void addBatch(String sql) throws SQLException {} + + @Override + public void clearBatch() throws SQLException {} + + @Override + public int[] executeBatch() throws SQLException { + return new int[0]; + } + + @Override + public Connection getConnection() throws SQLException { + return connection; + } + + @Override + public boolean getMoreResults(int current) throws SQLException { + return false; + } + + @Override + public ResultSet getGeneratedKeys() throws SQLException { + return null; + } + + @Override + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + return 0; + } + + @Override + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + return 0; + } + + @Override + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + return 0; + } + + @Override + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + return true; + } + + @Override + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + return true; + } + + @Override + public boolean execute(String sql, String[] columnNames) throws SQLException { + return true; + } + + @Override + public int getResultSetHoldability() throws SQLException { + return 0; + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public boolean isPoolable() throws SQLException { + return false; + } + + @Override + public void setPoolable(boolean poolable) throws SQLException {} + + @Override + public void closeOnCompletion() throws SQLException {} + + @Override + public boolean isCloseOnCompletion() throws SQLException { + return false; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } +} From b511ea13a127370540b36911bd51725d2a7ba6bf Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Thu, 29 Aug 2024 14:36:28 +0800 Subject: [PATCH 02/11] fix @SuppressWarnings(UngroupedOverloads) --- .../jdbc/test/JdbcInstrumentationTest.java | 22 +- .../jdbc/TestCallableStatement.java | 403 ++++++----- .../instrumentation/jdbc/TestConnection.java | 214 +++--- .../jdbc/TestDatabaseMetaData.java | 653 +++++++++--------- .../jdbc/TestPreparedStatement.java | 131 ++-- .../instrumentation/jdbc/TestStatement.java | 149 ++-- 6 files changed, 783 insertions(+), 789 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index aad93f2ecbc7..e25b1942ee3f 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -94,12 +94,10 @@ public void setUp() { cpDatasources = new HashMap<>(); prepareConnectionPoolDatasources(); - System.out.println("before all"); } @AfterAll public void tearDown() { - System.out.println("after all"); cpDatasources .values() .forEach( @@ -121,14 +119,14 @@ void prepareConnectionPoolDatasources() { List connectionPoolNames = asList("tomcat", "hikari", "c3p0"); connectionPoolNames.forEach( cpName -> { - Map dbDSMapping = new HashMap<>(); + Map dbDsMapping = new HashMap<>(); jdbcUrls.forEach( - (dbType, jdbcUrl) -> dbDSMapping.put(dbType, createDS(cpName, dbType, jdbcUrl))); - cpDatasources.put(cpName, dbDSMapping); + (dbType, jdbcUrl) -> dbDsMapping.put(dbType, createDs(cpName, dbType, jdbcUrl))); + cpDatasources.put(cpName, dbDsMapping); }); } - DataSource createTomcatDS(String dbType, String jdbcUrl) { + DataSource createTomcatDs(String dbType, String jdbcUrl) { org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(); String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; ds.setUrl(jdbcUrlToSet); @@ -143,7 +141,7 @@ DataSource createTomcatDS(String dbType, String jdbcUrl) { return ds; } - DataSource createHikariDS(String dbType, String jdbcUrl) { + DataSource createHikariDs(String dbType, String jdbcUrl) { HikariConfig config = new HikariConfig(); String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; config.setJdbcUrl(jdbcUrlToSet); @@ -160,7 +158,7 @@ DataSource createHikariDS(String dbType, String jdbcUrl) { return new HikariDataSource(config); } - DataSource createC3P0DS(String dbType, String jdbcUrl) { + DataSource createC3P0Ds(String dbType, String jdbcUrl) { ComboPooledDataSource ds = new ComboPooledDataSource(); try { ds.setDriverClass(jdbcDriverClassNames.get(dbType)); @@ -178,16 +176,16 @@ DataSource createC3P0DS(String dbType, String jdbcUrl) { return ds; } - DataSource createDS(String connectionPoolName, String dbType, String jdbcUrl) { + DataSource createDs(String connectionPoolName, String dbType, String jdbcUrl) { DataSource ds = null; if (Objects.equals(connectionPoolName, "tomcat")) { - ds = createTomcatDS(dbType, jdbcUrl); + ds = createTomcatDs(dbType, jdbcUrl); } if (Objects.equals(connectionPoolName, "hikari")) { - ds = createHikariDS(dbType, jdbcUrl); + ds = createHikariDs(dbType, jdbcUrl); } if (Objects.equals(connectionPoolName, "c3p0")) { - ds = createC3P0DS(dbType, jdbcUrl); + ds = createC3P0Ds(dbType, jdbcUrl); } return ds; } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java index 144a320fb402..1dbfeb93d751 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestCallableStatement.java @@ -24,64 +24,61 @@ import java.util.Calendar; import java.util.Map; -@SuppressWarnings("UngroupedOverloads") class TestCallableStatement extends TestPreparedStatement implements CallableStatement { @Override - public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {} - - @Override - public void registerOutParameter(int parameterIndex, int sqlType, int scale) - throws SQLException {} + public Array getArray(int parameterIndex) throws SQLException { + return null; + } @Override - public boolean wasNull() throws SQLException { - return false; + public Array getArray(String parameterName) throws SQLException { + return null; } @Override - public String getString(int parameterIndex) throws SQLException { + @Deprecated + public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { return null; } @Override - public boolean getBoolean(int parameterIndex) throws SQLException { - return false; + public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { + return null; } @Override - public byte getByte(int parameterIndex) throws SQLException { - return 0; + public BigDecimal getBigDecimal(String parameterName) throws SQLException { + return null; } @Override - public short getShort(int parameterIndex) throws SQLException { - return 0; + public Blob getBlob(int parameterIndex) throws SQLException { + return null; } @Override - public int getInt(int parameterIndex) throws SQLException { - return 0; + public Blob getBlob(String parameterName) throws SQLException { + return null; } @Override - public long getLong(int parameterIndex) throws SQLException { - return 0; + public boolean getBoolean(int parameterIndex) throws SQLException { + return false; } @Override - public float getFloat(int parameterIndex) throws SQLException { - return 0; + public boolean getBoolean(String parameterName) throws SQLException { + return false; } @Override - public double getDouble(int parameterIndex) throws SQLException { + public byte getByte(int parameterIndex) throws SQLException { return 0; } @Override - @Deprecated - public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { - return null; + public byte getByte(String parameterName) throws SQLException { + return 0; } @Override @@ -90,215 +87,207 @@ public byte[] getBytes(int parameterIndex) throws SQLException { } @Override - public Date getDate(int parameterIndex) throws SQLException { - return null; + public byte[] getBytes(String parameterName) throws SQLException { + return new byte[0]; } @Override - public Time getTime(int parameterIndex) throws SQLException { + public Reader getCharacterStream(int parameterIndex) throws SQLException { return null; } @Override - public Timestamp getTimestamp(int parameterIndex) throws SQLException { + public Reader getCharacterStream(String parameterName) throws SQLException { return null; } @Override - public Object getObject(int parameterIndex) throws SQLException { + public Clob getClob(int parameterIndex) throws SQLException { return null; } @Override - public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { + public Clob getClob(String parameterName) throws SQLException { return null; } @Override - public Object getObject(int parameterIndex, Map> map) throws SQLException { + public Date getDate(int parameterIndex) throws SQLException { return null; } @Override - public Ref getRef(int parameterIndex) throws SQLException { + public Date getDate(int parameterIndex, Calendar cal) throws SQLException { return null; } @Override - public Blob getBlob(int parameterIndex) throws SQLException { + public Date getDate(String parameterName) throws SQLException { return null; } @Override - public Clob getClob(int parameterIndex) throws SQLException { + public Date getDate(String parameterName, Calendar cal) throws SQLException { return null; } @Override - public Array getArray(int parameterIndex) throws SQLException { - return null; + public double getDouble(int parameterIndex) throws SQLException { + return 0; } @Override - public Date getDate(int parameterIndex, Calendar cal) throws SQLException { - return null; + public double getDouble(String parameterName) throws SQLException { + return 0; } @Override - public Time getTime(int parameterIndex, Calendar cal) throws SQLException { - return null; + public float getFloat(int parameterIndex) throws SQLException { + return 0; } @Override - public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { - return null; + public float getFloat(String parameterName) throws SQLException { + return 0; } @Override - public void registerOutParameter(int parameterIndex, int sqlType, String typeName) - throws SQLException {} + public int getInt(int parameterIndex) throws SQLException { + return 0; + } @Override - public void registerOutParameter(String parameterName, int sqlType) throws SQLException {} + public int getInt(String parameterName) throws SQLException { + return 0; + } @Override - public void registerOutParameter(String parameterName, int sqlType, int scale) - throws SQLException {} + public long getLong(int parameterIndex) throws SQLException { + return 0; + } @Override - public void registerOutParameter(String parameterName, int sqlType, String typeName) - throws SQLException {} + public long getLong(String parameterName) throws SQLException { + return 0; + } @Override - public URL getURL(int parameterIndex) throws SQLException { + public Reader getNCharacterStream(int parameterIndex) throws SQLException { return null; } @Override - public void setURL(String parameterName, URL val) throws SQLException {} - - @Override - public void setNull(String parameterName, int sqlType) throws SQLException {} - - @Override - public void setBoolean(String parameterName, boolean x) throws SQLException {} - - @Override - public void setByte(String parameterName, byte x) throws SQLException {} - - @Override - public void setShort(String parameterName, short x) throws SQLException {} - - @Override - public void setInt(String parameterName, int x) throws SQLException {} - - @Override - public void setLong(String parameterName, long x) throws SQLException {} - - @Override - public void setFloat(String parameterName, float x) throws SQLException {} - - @Override - public void setDouble(String parameterName, double x) throws SQLException {} - - @Override - public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {} - - @Override - public void setString(String parameterName, String x) throws SQLException {} - - @Override - public void setBytes(String parameterName, byte[] x) throws SQLException {} - - @Override - public void setDate(String parameterName, Date x) throws SQLException {} + public Reader getNCharacterStream(String parameterName) throws SQLException { + return null; + } @Override - public void setTime(String parameterName, Time x) throws SQLException {} + public NClob getNClob(int parameterIndex) throws SQLException { + return null; + } @Override - public void setTimestamp(String parameterName, Timestamp x) throws SQLException {} + public NClob getNClob(String parameterName) throws SQLException { + return null; + } @Override - public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {} + public String getNString(int parameterIndex) throws SQLException { + return null; + } @Override - public void setBinaryStream(String parameterName, InputStream x, int length) - throws SQLException {} + public String getNString(String parameterName) throws SQLException { + return null; + } @Override - public void setObject(String parameterName, Object x, int targetSqlType, int scale) - throws SQLException {} + public Object getObject(int parameterIndex) throws SQLException { + return null; + } @Override - public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {} + public Object getObject(int parameterIndex, Map> map) throws SQLException { + return null; + } @Override - public void setObject(String parameterName, Object x) throws SQLException {} + public Object getObject(String parameterName) throws SQLException { + return null; + } @Override - public void setCharacterStream(String parameterName, Reader reader, int length) - throws SQLException {} + public Object getObject(String parameterName, Map> map) throws SQLException { + return null; + } @Override - public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {} + public T getObject(int parameterIndex, Class type) throws SQLException { + return null; + } @Override - public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {} + public T getObject(String parameterName, Class type) throws SQLException { + return null; + } @Override - public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {} + public Ref getRef(int parameterIndex) throws SQLException { + return null; + } @Override - public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {} + public Ref getRef(String parameterName) throws SQLException { + return null; + } @Override - public String getString(String parameterName) throws SQLException { + public RowId getRowId(int parameterIndex) throws SQLException { return null; } @Override - public boolean getBoolean(String parameterName) throws SQLException { - return false; + public RowId getRowId(String parameterName) throws SQLException { + return null; } @Override - public byte getByte(String parameterName) throws SQLException { - return 0; + public SQLXML getSQLXML(int parameterIndex) throws SQLException { + return null; } @Override - public short getShort(String parameterName) throws SQLException { - return 0; + public SQLXML getSQLXML(String parameterName) throws SQLException { + return null; } @Override - public int getInt(String parameterName) throws SQLException { + public short getShort(int parameterIndex) throws SQLException { return 0; } @Override - public long getLong(String parameterName) throws SQLException { + public short getShort(String parameterName) throws SQLException { return 0; } @Override - public float getFloat(String parameterName) throws SQLException { - return 0; + public String getString(int parameterIndex) throws SQLException { + return null; } @Override - public double getDouble(String parameterName) throws SQLException { - return 0; + public String getString(String parameterName) throws SQLException { + return null; } @Override - public byte[] getBytes(String parameterName) throws SQLException { - return new byte[0]; + public Time getTime(int parameterIndex) throws SQLException { + return null; } @Override - public Date getDate(String parameterName) throws SQLException { + public Time getTime(int parameterIndex, Calendar cal) throws SQLException { return null; } @@ -308,197 +297,207 @@ public Time getTime(String parameterName) throws SQLException { } @Override - public Timestamp getTimestamp(String parameterName) throws SQLException { + public Time getTime(String parameterName, Calendar cal) throws SQLException { return null; } @Override - public Object getObject(String parameterName) throws SQLException { + public Timestamp getTimestamp(int parameterIndex) throws SQLException { return null; } @Override - public BigDecimal getBigDecimal(String parameterName) throws SQLException { + public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { return null; } @Override - public Object getObject(String parameterName, Map> map) throws SQLException { + public Timestamp getTimestamp(String parameterName) throws SQLException { return null; } @Override - public Ref getRef(String parameterName) throws SQLException { + public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { return null; } @Override - public Blob getBlob(String parameterName) throws SQLException { + public URL getURL(int parameterIndex) throws SQLException { return null; } @Override - public Clob getClob(String parameterName) throws SQLException { + public URL getURL(String parameterName) throws SQLException { return null; } @Override - public Array getArray(String parameterName) throws SQLException { - return null; - } + public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {} @Override - public Date getDate(String parameterName, Calendar cal) throws SQLException { - return null; - } + public void registerOutParameter(int parameterIndex, int sqlType, int scale) + throws SQLException {} @Override - public Time getTime(String parameterName, Calendar cal) throws SQLException { - return null; - } + public void registerOutParameter(int parameterIndex, int sqlType, String typeName) + throws SQLException {} @Override - public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { - return null; - } + public void registerOutParameter(String parameterName, int sqlType) throws SQLException {} @Override - public URL getURL(String parameterName) throws SQLException { - return null; - } + public void registerOutParameter(String parameterName, int sqlType, int scale) + throws SQLException {} @Override - public RowId getRowId(int parameterIndex) throws SQLException { - return null; - } + public void registerOutParameter(String parameterName, int sqlType, String typeName) + throws SQLException {} @Override - public RowId getRowId(String parameterName) throws SQLException { - return null; - } + public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {} @Override - public void setRowId(String parameterName, RowId x) throws SQLException {} + public void setAsciiStream(String parameterName, InputStream x, long length) + throws SQLException {} @Override - public void setNString(String parameterName, String value) throws SQLException {} + public void setAsciiStream(String parameterName, InputStream x) throws SQLException {} @Override - public void setNCharacterStream(String parameterName, Reader value, long length) + public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {} + + @Override + public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {} @Override - public void setNClob(String parameterName, NClob value) throws SQLException {} + public void setBinaryStream(String parameterName, InputStream x, long length) + throws SQLException {} @Override - public void setClob(String parameterName, Reader reader, long length) throws SQLException {} + public void setBinaryStream(String parameterName, InputStream x) throws SQLException {} @Override public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {} @Override - public void setNClob(String parameterName, Reader reader, long length) throws SQLException {} + public void setBlob(String parameterName, Blob x) throws SQLException {} @Override - public NClob getNClob(int parameterIndex) throws SQLException { - return null; - } + public void setBlob(String parameterName, InputStream inputStream) throws SQLException {} @Override - public NClob getNClob(String parameterName) throws SQLException { - return null; - } + public void setBoolean(String parameterName, boolean x) throws SQLException {} @Override - public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {} + public void setByte(String parameterName, byte x) throws SQLException {} @Override - public SQLXML getSQLXML(int parameterIndex) throws SQLException { - return null; - } + public void setBytes(String parameterName, byte[] x) throws SQLException {} @Override - public SQLXML getSQLXML(String parameterName) throws SQLException { - return null; - } + public void setCharacterStream(String parameterName, Reader reader, int length) + throws SQLException {} @Override - public String getNString(int parameterIndex) throws SQLException { - return null; - } + public void setCharacterStream(String parameterName, Reader reader, long length) + throws SQLException {} @Override - public String getNString(String parameterName) throws SQLException { - return null; - } + public void setCharacterStream(String parameterName, Reader reader) throws SQLException {} @Override - public Reader getNCharacterStream(int parameterIndex) throws SQLException { - return null; - } + public void setClob(String parameterName, Reader reader, long length) throws SQLException {} @Override - public Reader getNCharacterStream(String parameterName) throws SQLException { - return null; - } + public void setClob(String parameterName, Clob x) throws SQLException {} @Override - public Reader getCharacterStream(int parameterIndex) throws SQLException { - return null; - } + public void setClob(String parameterName, Reader reader) throws SQLException {} @Override - public Reader getCharacterStream(String parameterName) throws SQLException { - return null; - } + public void setDate(String parameterName, Date x) throws SQLException {} @Override - public void setBlob(String parameterName, Blob x) throws SQLException {} + public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {} @Override - public void setClob(String parameterName, Clob x) throws SQLException {} + public void setDouble(String parameterName, double x) throws SQLException {} @Override - public void setAsciiStream(String parameterName, InputStream x, long length) - throws SQLException {} + public void setFloat(String parameterName, float x) throws SQLException {} @Override - public void setBinaryStream(String parameterName, InputStream x, long length) + public void setInt(String parameterName, int x) throws SQLException {} + + @Override + public void setLong(String parameterName, long x) throws SQLException {} + + @Override + public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {} @Override - public void setCharacterStream(String parameterName, Reader reader, long length) + public void setNCharacterStream(String parameterName, Reader value) throws SQLException {} + + @Override + public void setNClob(String parameterName, NClob value) throws SQLException {} + + @Override + public void setNClob(String parameterName, Reader reader, long length) throws SQLException {} + + @Override + public void setNClob(String parameterName, Reader reader) throws SQLException {} + + @Override + public void setNString(String parameterName, String value) throws SQLException {} + + @Override + public void setNull(String parameterName, int sqlType) throws SQLException {} + + @Override + public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {} + + @Override + public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {} @Override - public void setAsciiStream(String parameterName, InputStream x) throws SQLException {} + public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {} @Override - public void setBinaryStream(String parameterName, InputStream x) throws SQLException {} + public void setObject(String parameterName, Object x) throws SQLException {} @Override - public void setCharacterStream(String parameterName, Reader reader) throws SQLException {} + public void setRowId(String parameterName, RowId x) throws SQLException {} @Override - public void setNCharacterStream(String parameterName, Reader value) throws SQLException {} + public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {} @Override - public void setClob(String parameterName, Reader reader) throws SQLException {} + public void setShort(String parameterName, short x) throws SQLException {} @Override - public void setBlob(String parameterName, InputStream inputStream) throws SQLException {} + public void setString(String parameterName, String x) throws SQLException {} @Override - public void setNClob(String parameterName, Reader reader) throws SQLException {} + public void setTime(String parameterName, Time x) throws SQLException {} @Override - public T getObject(int parameterIndex, Class type) throws SQLException { - return null; - } + public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {} @Override - public T getObject(String parameterName, Class type) throws SQLException { - return null; + public void setTimestamp(String parameterName, Timestamp x) throws SQLException {} + + @Override + public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {} + + @Override + public void setURL(String parameterName, URL val) throws SQLException {} + + @Override + public boolean wasNull() throws SQLException { + return false; } } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java index c5862d353aa5..443f3529d002 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java @@ -40,95 +40,88 @@ public TestConnection(boolean throwException) { } @Override - public Statement createStatement() throws SQLException { - return new TestStatement(this); - } + public void abort(Executor executor) throws SQLException {} @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency) - throws SQLException { - return new TestStatement(this); - } + public void clearWarnings() throws SQLException {} @Override - public Statement createStatement( - int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return new TestStatement(this); - } + public void close() throws SQLException {} @Override - public PreparedStatement prepareStatement(String sql) throws SQLException { - return new TestPreparedStatement(this); - } + public void commit() throws SQLException {} @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - return new TestPreparedStatement(this); + public Array createArrayOf(String typeName, Object[] elements) throws SQLException { + return null; } @Override - public PreparedStatement prepareStatement( - String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - return new TestPreparedStatement(this); + public Blob createBlob() throws SQLException { + return null; } @Override - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - return new TestPreparedStatement(this); + public Clob createClob() throws SQLException { + return null; } @Override - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - return new TestPreparedStatement(this); + public NClob createNClob() throws SQLException { + return null; } @Override - public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - return new TestPreparedStatement(this); + public SQLXML createSQLXML() throws SQLException { + return null; } @Override - public CallableStatement prepareCall(String sql) throws SQLException { - return new TestCallableStatement(); + public Statement createStatement() throws SQLException { + return new TestStatement(this); } @Override - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) + public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return new TestCallableStatement(); + return new TestStatement(this); } @Override - public CallableStatement prepareCall( - String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - return new TestCallableStatement(); + public Statement createStatement( + int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { + return new TestStatement(this); } @Override - public String nativeSQL(String sql) throws SQLException { + public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return null; } - @Override - public void setAutoCommit(boolean autoCommit) throws SQLException {} - @Override public boolean getAutoCommit() throws SQLException { return false; } @Override - public void commit() throws SQLException {} + public String getCatalog() throws SQLException { + return null; + } @Override - public void close() throws SQLException {} + public String getClientInfo(String name) throws SQLException { + throw new UnsupportedOperationException("Test 123"); + } @Override - public boolean isClosed() throws SQLException { - return false; + public Properties getClientInfo() throws SQLException { + // TODO throwable + throw new UnsupportedOperationException("Test 123"); + } + + @Override + public int getHoldability() throws SQLException { + return 0; } @Override @@ -140,154 +133,161 @@ public DatabaseMetaData getMetaData() throws SQLException { } @Override - public void setReadOnly(boolean readOnly) throws SQLException {} - - @Override - public boolean isReadOnly() throws SQLException { - return false; + public int getNetworkTimeout() throws SQLException { + return 0; } @Override - public void setCatalog(String catalog) throws SQLException {} - - @Override - public String getCatalog() throws SQLException { + public String getSchema() throws SQLException { return null; } - @Override - public void setTransactionIsolation(int level) throws SQLException {} - @Override public int getTransactionIsolation() throws SQLException { return 0; } @Override - public SQLWarning getWarnings() throws SQLException { - return null; + public Map> getTypeMap() throws SQLException { + return new HashMap<>(); } @Override - public void clearWarnings() throws SQLException {} + public SQLWarning getWarnings() throws SQLException { + return null; + } @Override - public Map> getTypeMap() throws SQLException { - return new HashMap<>(); + public boolean isClosed() throws SQLException { + return false; } @Override - public void setTypeMap(Map> map) throws SQLException {} + public boolean isReadOnly() throws SQLException { + return false; + } @Override - public void setHoldability(int holdability) throws SQLException {} + public boolean isValid(int timeout) throws SQLException { + return false; + } @Override - public int getHoldability() throws SQLException { - return 0; + public boolean isWrapperFor(Class iface) throws SQLException { + return false; } @Override - public Savepoint setSavepoint() throws SQLException { + public String nativeSQL(String sql) throws SQLException { return null; } @Override - public Savepoint setSavepoint(String name) throws SQLException { - return null; + public CallableStatement prepareCall(String sql) throws SQLException { + return new TestCallableStatement(); } @Override - public void rollback(Savepoint savepoint) throws SQLException {} + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return new TestCallableStatement(); + } @Override - public void rollback() throws SQLException {} + public CallableStatement prepareCall( + String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return new TestCallableStatement(); + } @Override - public void releaseSavepoint(Savepoint savepoint) throws SQLException {} + public PreparedStatement prepareStatement(String sql) throws SQLException { + return new TestPreparedStatement(this); + } @Override - public Clob createClob() throws SQLException { - return null; + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return new TestPreparedStatement(this); } @Override - public Blob createBlob() throws SQLException { - return null; + public PreparedStatement prepareStatement( + String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return new TestPreparedStatement(this); } @Override - public NClob createNClob() throws SQLException { - return null; + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { + return new TestPreparedStatement(this); } @Override - public SQLXML createSQLXML() throws SQLException { - return null; + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { + return new TestPreparedStatement(this); } @Override - public boolean isValid(int timeout) throws SQLException { - return false; + public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { + return new TestPreparedStatement(this); } @Override - public void setClientInfo(String name, String value) throws SQLClientInfoException {} + public void releaseSavepoint(Savepoint savepoint) throws SQLException {} @Override - public void setClientInfo(Properties properties) throws SQLClientInfoException {} + public void rollback(Savepoint savepoint) throws SQLException {} @Override - public String getClientInfo(String name) throws SQLException { - throw new UnsupportedOperationException("Test 123"); - } + public void rollback() throws SQLException {} @Override - public Properties getClientInfo() throws SQLException { - // TODO throwable - throw new UnsupportedOperationException("Test 123"); - } + public void setAutoCommit(boolean autoCommit) throws SQLException {} @Override - public Array createArrayOf(String typeName, Object[] elements) throws SQLException { - return null; - } + public void setCatalog(String catalog) throws SQLException {} @Override - public Struct createStruct(String typeName, Object[] attributes) throws SQLException { - return null; - } + public void setClientInfo(Properties properties) throws SQLClientInfoException {} @Override - public void setSchema(String schema) throws SQLException {} + public void setClientInfo(String name, String value) throws SQLClientInfoException {} @Override - public String getSchema() throws SQLException { - return null; - } + public void setHoldability(int holdability) throws SQLException {} @Override - public void abort(Executor executor) throws SQLException {} + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {} @Override - public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {} + public void setReadOnly(boolean readOnly) throws SQLException {} @Override - public int getNetworkTimeout() throws SQLException { - return 0; + public Savepoint setSavepoint() throws SQLException { + return null; } @Override - public T unwrap(Class iface) throws SQLException { + public Savepoint setSavepoint(String name) throws SQLException { return null; } @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } + public void setSchema(String schema) throws SQLException {} + + @Override + public void setTransactionIsolation(int level) throws SQLException {} + + @Override + public void setTypeMap(Map> map) throws SQLException {} void setUrl(String url) { this.url = url; } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java index 2e478f3b4464..721e5e060d51 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java @@ -11,7 +11,6 @@ import java.sql.RowIdLifetime; import java.sql.SQLException; -@SuppressWarnings("UngroupedOverloads") class TestDatabaseMetaData implements DatabaseMetaData { final String url; @@ -34,907 +33,907 @@ public boolean allTablesAreSelectable() throws SQLException { } @Override - public String getURL() throws SQLException { - return url; + public boolean autoCommitFailureClosesAllResultSets() throws SQLException { + return false; } @Override - public String getUserName() throws SQLException { - return null; + public boolean dataDefinitionCausesTransactionCommit() throws SQLException { + return false; } @Override - public boolean isReadOnly() throws SQLException { + public boolean dataDefinitionIgnoredInTransactions() throws SQLException { return false; } @Override - public boolean nullsAreSortedHigh() throws SQLException { + public boolean deletesAreDetected(int type) throws SQLException { return false; } @Override - public boolean nullsAreSortedLow() throws SQLException { + public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { return false; } @Override - public boolean nullsAreSortedAtStart() throws SQLException { + public boolean generatedKeyAlwaysReturned() throws SQLException { + ; return false; } @Override - public boolean nullsAreSortedAtEnd() throws SQLException { - return false; + public ResultSet getAttributes( + String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) + throws SQLException { + return null; } @Override - public String getDatabaseProductName() throws SQLException { + public ResultSet getBestRowIdentifier( + String catalog, String schema, String table, int scope, boolean nullable) + throws SQLException { return null; } @Override - public String getDatabaseProductVersion() throws SQLException { + public String getCatalogSeparator() throws SQLException { return null; } @Override - public String getDriverName() throws SQLException { + public String getCatalogTerm() throws SQLException { return null; } @Override - public String getDriverVersion() throws SQLException { + public ResultSet getCatalogs() throws SQLException { return null; } @Override - public int getDriverMajorVersion() { - return 0; + public ResultSet getClientInfoProperties() throws SQLException { + return null; } @Override - public int getDriverMinorVersion() { - return 0; + public ResultSet getColumnPrivileges( + String catalog, String schema, String table, String columnNamePattern) throws SQLException { + return null; } @Override - public boolean usesLocalFiles() throws SQLException { - return false; + public ResultSet getColumns( + String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) + throws SQLException { + return null; } @Override - public boolean usesLocalFilePerTable() throws SQLException { - return false; + public Connection getConnection() throws SQLException { + return null; } @Override - public boolean supportsMixedCaseIdentifiers() throws SQLException { - return false; + public ResultSet getCrossReference( + String parentCatalog, + String parentSchema, + String parentTable, + String foreignCatalog, + String foreignSchema, + String foreignTable) + throws SQLException { + return null; } @Override - public boolean storesUpperCaseIdentifiers() throws SQLException { - return false; + public int getDatabaseMajorVersion() throws SQLException { + return 0; } @Override - public boolean storesLowerCaseIdentifiers() throws SQLException { - return false; + public int getDatabaseMinorVersion() throws SQLException { + return 0; } @Override - public boolean storesMixedCaseIdentifiers() throws SQLException { - return false; + public String getDatabaseProductName() throws SQLException { + return null; } @Override - public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - return false; + public String getDatabaseProductVersion() throws SQLException { + return null; } @Override - public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - return false; + public int getDefaultTransactionIsolation() throws SQLException { + return 0; } @Override - public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - return false; + public int getDriverMajorVersion() { + return 0; } @Override - public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - return false; + public int getDriverMinorVersion() { + return 0; } @Override - public String getIdentifierQuoteString() throws SQLException { + public String getDriverName() throws SQLException { return null; } @Override - public String getSQLKeywords() throws SQLException { + public String getDriverVersion() throws SQLException { return null; } @Override - public String getNumericFunctions() throws SQLException { + public ResultSet getExportedKeys(String catalog, String schema, String table) + throws SQLException { return null; } @Override - public String getStringFunctions() throws SQLException { + public String getExtraNameCharacters() throws SQLException { return null; } @Override - public String getSystemFunctions() throws SQLException { + public ResultSet getFunctionColumns( + String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) + throws SQLException { return null; } @Override - public String getTimeDateFunctions() throws SQLException { + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) + throws SQLException { return null; } @Override - public String getSearchStringEscape() throws SQLException { + public String getIdentifierQuoteString() throws SQLException { return null; } @Override - public String getExtraNameCharacters() throws SQLException { + public ResultSet getImportedKeys(String catalog, String schema, String table) + throws SQLException { return null; } @Override - public boolean supportsAlterTableWithAddColumn() throws SQLException { - return false; + public ResultSet getIndexInfo( + String catalog, String schema, String table, boolean unique, boolean approximate) + throws SQLException { + return null; } @Override - public boolean supportsAlterTableWithDropColumn() throws SQLException { - return false; + public int getJDBCMajorVersion() throws SQLException { + return 0; } @Override - public boolean supportsColumnAliasing() throws SQLException { - return false; + public int getJDBCMinorVersion() throws SQLException { + return 0; } @Override - public boolean nullPlusNonNullIsNull() throws SQLException { - return false; + public int getMaxBinaryLiteralLength() throws SQLException { + return 0; } @Override - public boolean supportsConvert() throws SQLException { - return false; + public int getMaxCatalogNameLength() throws SQLException { + return 0; } @Override - public boolean supportsConvert(int fromType, int toType) throws SQLException { - return false; + public int getMaxCharLiteralLength() throws SQLException { + return 0; } @Override - public boolean supportsTableCorrelationNames() throws SQLException { - return false; + public int getMaxColumnNameLength() throws SQLException { + return 0; } @Override - public boolean supportsDifferentTableCorrelationNames() throws SQLException { - return false; + public int getMaxColumnsInGroupBy() throws SQLException { + return 0; } @Override - public boolean supportsExpressionsInOrderBy() throws SQLException { - return false; + public int getMaxColumnsInIndex() throws SQLException { + return 0; } @Override - public boolean supportsOrderByUnrelated() throws SQLException { - return false; + public int getMaxColumnsInOrderBy() throws SQLException { + return 0; } @Override - public boolean supportsGroupBy() throws SQLException { - return false; + public int getMaxColumnsInSelect() throws SQLException { + return 0; } @Override - public boolean supportsGroupByUnrelated() throws SQLException { - return false; + public int getMaxColumnsInTable() throws SQLException { + return 0; } @Override - public boolean supportsGroupByBeyondSelect() throws SQLException { - return false; + public int getMaxConnections() throws SQLException { + return 0; } @Override - public boolean supportsLikeEscapeClause() throws SQLException { - return false; + public int getMaxCursorNameLength() throws SQLException { + return 0; } @Override - public boolean supportsMultipleResultSets() throws SQLException { - return false; + public int getMaxIndexLength() throws SQLException { + return 0; } @Override - public boolean supportsMultipleTransactions() throws SQLException { - return false; + public int getMaxProcedureNameLength() throws SQLException { + return 0; } @Override - public boolean supportsNonNullableColumns() throws SQLException { - return false; + public int getMaxRowSize() throws SQLException { + return 0; } @Override - public boolean supportsMinimumSQLGrammar() throws SQLException { - return false; + public int getMaxSchemaNameLength() throws SQLException { + return 0; } @Override - public boolean supportsCoreSQLGrammar() throws SQLException { - return false; + public int getMaxStatementLength() throws SQLException { + return 0; } @Override - public boolean supportsExtendedSQLGrammar() throws SQLException { - return false; + public int getMaxStatements() throws SQLException { + return 0; } @Override - public boolean supportsANSI92EntryLevelSQL() throws SQLException { - return false; + public int getMaxTableNameLength() throws SQLException { + return 0; } @Override - public boolean supportsANSI92IntermediateSQL() throws SQLException { - return false; + public int getMaxTablesInSelect() throws SQLException { + return 0; } @Override - public boolean supportsANSI92FullSQL() throws SQLException { - return false; + public int getMaxUserNameLength() throws SQLException { + return 0; } @Override - public boolean supportsIntegrityEnhancementFacility() throws SQLException { - return false; + public String getNumericFunctions() throws SQLException { + return null; } @Override - public boolean supportsOuterJoins() throws SQLException { - return false; + public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { + return null; } @Override - public boolean supportsFullOuterJoins() throws SQLException { - return false; + public ResultSet getProcedureColumns( + String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) + throws SQLException { + return null; } @Override - public boolean supportsLimitedOuterJoins() throws SQLException { - return false; + public String getProcedureTerm() throws SQLException { + return null; } @Override - public String getSchemaTerm() throws SQLException { + public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) + throws SQLException { return null; } @Override - public String getProcedureTerm() throws SQLException { + public ResultSet getPseudoColumns( + String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) + throws SQLException { return null; } @Override - public String getCatalogTerm() throws SQLException { - return null; + public int getResultSetHoldability() throws SQLException { + return 0; } @Override - public boolean isCatalogAtStart() throws SQLException { - return false; + public RowIdLifetime getRowIdLifetime() throws SQLException { + return null; } @Override - public String getCatalogSeparator() throws SQLException { + public String getSQLKeywords() throws SQLException { return null; } @Override - public boolean supportsSchemasInDataManipulation() throws SQLException { - return false; + public int getSQLStateType() throws SQLException { + return 0; } @Override - public boolean supportsSchemasInProcedureCalls() throws SQLException { - return false; + public String getSchemaTerm() throws SQLException { + return null; } @Override - public boolean supportsSchemasInTableDefinitions() throws SQLException { - return false; + public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { + return null; } @Override - public boolean supportsSchemasInIndexDefinitions() throws SQLException { - return false; + public ResultSet getSchemas() throws SQLException { + return null; } @Override - public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - return false; + public String getSearchStringEscape() throws SQLException { + return null; } @Override - public boolean supportsCatalogsInDataManipulation() throws SQLException { - return false; + public String getStringFunctions() throws SQLException { + return null; } @Override - public boolean supportsCatalogsInProcedureCalls() throws SQLException { - return false; + public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return null; } @Override - public boolean supportsCatalogsInTableDefinitions() throws SQLException { - return false; + public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) + throws SQLException { + return null; } @Override - public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - return false; + public String getSystemFunctions() throws SQLException { + return null; } @Override - public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - return false; + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return null; } @Override - public boolean supportsPositionedDelete() throws SQLException { - return false; + public ResultSet getTableTypes() throws SQLException { + return null; } @Override - public boolean supportsPositionedUpdate() throws SQLException { - return false; + public ResultSet getTables( + String catalog, String schemaPattern, String tableNamePattern, String[] types) + throws SQLException { + return null; } @Override - public boolean supportsSelectForUpdate() throws SQLException { - return false; + public String getTimeDateFunctions() throws SQLException { + return null; } @Override - public boolean supportsStoredProcedures() throws SQLException { - return false; + public ResultSet getTypeInfo() throws SQLException { + return null; } @Override - public boolean supportsSubqueriesInComparisons() throws SQLException { - return false; + public ResultSet getUDTs( + String catalog, String schemaPattern, String typeNamePattern, int[] types) + throws SQLException { + return null; } @Override - public boolean supportsSubqueriesInExists() throws SQLException { - return false; + public String getURL() throws SQLException { + return url; } @Override - public boolean supportsSubqueriesInIns() throws SQLException { - return false; + public String getUserName() throws SQLException { + return null; } @Override - public boolean supportsSubqueriesInQuantifieds() throws SQLException { - return false; + public ResultSet getVersionColumns(String catalog, String schema, String table) + throws SQLException { + return null; } @Override - public boolean supportsCorrelatedSubqueries() throws SQLException { + public boolean insertsAreDetected(int type) throws SQLException { return false; } @Override - public boolean supportsUnion() throws SQLException { + public boolean isCatalogAtStart() throws SQLException { return false; } @Override - public boolean supportsUnionAll() throws SQLException { + public boolean isReadOnly() throws SQLException { return false; } @Override - public boolean supportsOpenCursorsAcrossCommit() throws SQLException { + public boolean isWrapperFor(Class iface) throws SQLException { return false; } @Override - public boolean supportsOpenCursorsAcrossRollback() throws SQLException { + public boolean locatorsUpdateCopy() throws SQLException { return false; } @Override - public boolean supportsOpenStatementsAcrossCommit() throws SQLException { + public boolean nullPlusNonNullIsNull() throws SQLException { return false; } @Override - public boolean supportsOpenStatementsAcrossRollback() throws SQLException { + public boolean nullsAreSortedAtEnd() throws SQLException { return false; } @Override - public int getMaxBinaryLiteralLength() throws SQLException { - return 0; + public boolean nullsAreSortedAtStart() throws SQLException { + return false; } @Override - public int getMaxCharLiteralLength() throws SQLException { - return 0; + public boolean nullsAreSortedHigh() throws SQLException { + return false; } @Override - public int getMaxColumnNameLength() throws SQLException { - return 0; + public boolean nullsAreSortedLow() throws SQLException { + return false; } @Override - public int getMaxColumnsInGroupBy() throws SQLException { - return 0; + public boolean othersDeletesAreVisible(int type) throws SQLException { + return false; } @Override - public int getMaxColumnsInIndex() throws SQLException { - return 0; + public boolean othersInsertsAreVisible(int type) throws SQLException { + return false; } @Override - public int getMaxColumnsInOrderBy() throws SQLException { - return 0; + public boolean othersUpdatesAreVisible(int type) throws SQLException { + return false; } @Override - public int getMaxColumnsInSelect() throws SQLException { - return 0; + public boolean ownDeletesAreVisible(int type) throws SQLException { + return false; } @Override - public int getMaxColumnsInTable() throws SQLException { - return 0; + public boolean ownInsertsAreVisible(int type) throws SQLException { + return false; } @Override - public int getMaxConnections() throws SQLException { - return 0; + public boolean ownUpdatesAreVisible(int type) throws SQLException { + return false; } @Override - public int getMaxCursorNameLength() throws SQLException { - return 0; + public boolean storesLowerCaseIdentifiers() throws SQLException { + return false; } @Override - public int getMaxIndexLength() throws SQLException { - return 0; + public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { + return false; } @Override - public int getMaxSchemaNameLength() throws SQLException { - return 0; + public boolean storesMixedCaseIdentifiers() throws SQLException { + return false; } @Override - public int getMaxProcedureNameLength() throws SQLException { - return 0; + public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { + return false; } @Override - public int getMaxCatalogNameLength() throws SQLException { - return 0; + public boolean storesUpperCaseIdentifiers() throws SQLException { + return false; } @Override - public int getMaxRowSize() throws SQLException { - return 0; + public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { + return false; } @Override - public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { + public boolean supportsANSI92EntryLevelSQL() throws SQLException { return false; } @Override - public int getMaxStatementLength() throws SQLException { - return 0; + public boolean supportsANSI92FullSQL() throws SQLException { + return false; } @Override - public int getMaxStatements() throws SQLException { - return 0; + public boolean supportsANSI92IntermediateSQL() throws SQLException { + return false; } @Override - public int getMaxTableNameLength() throws SQLException { - return 0; + public boolean supportsAlterTableWithAddColumn() throws SQLException { + return false; } @Override - public int getMaxTablesInSelect() throws SQLException { - return 0; + public boolean supportsAlterTableWithDropColumn() throws SQLException { + return false; } @Override - public int getMaxUserNameLength() throws SQLException { - return 0; + public boolean supportsBatchUpdates() throws SQLException { + return false; } @Override - public int getDefaultTransactionIsolation() throws SQLException { - return 0; + public boolean supportsCatalogsInDataManipulation() throws SQLException { + return false; } @Override - public boolean supportsTransactions() throws SQLException { + public boolean supportsCatalogsInIndexDefinitions() throws SQLException { return false; } @Override - public boolean supportsTransactionIsolationLevel(int level) throws SQLException { + public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { return false; } @Override - public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { + public boolean supportsCatalogsInProcedureCalls() throws SQLException { return false; } @Override - public boolean supportsDataManipulationTransactionsOnly() throws SQLException { + public boolean supportsCatalogsInTableDefinitions() throws SQLException { return false; } @Override - public boolean dataDefinitionCausesTransactionCommit() throws SQLException { + public boolean supportsColumnAliasing() throws SQLException { return false; } @Override - public boolean dataDefinitionIgnoredInTransactions() throws SQLException { + public boolean supportsConvert() throws SQLException { return false; } @Override - public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) - throws SQLException { - return null; + public boolean supportsConvert(int fromType, int toType) throws SQLException { + return false; } @Override - public ResultSet getProcedureColumns( - String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) - throws SQLException { - return null; + public boolean supportsCoreSQLGrammar() throws SQLException { + return false; } @Override - public ResultSet getTables( - String catalog, String schemaPattern, String tableNamePattern, String[] types) - throws SQLException { - return null; + public boolean supportsCorrelatedSubqueries() throws SQLException { + return false; } @Override - public ResultSet getCatalogs() throws SQLException { - return null; + public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { + return false; } @Override - public ResultSet getTableTypes() throws SQLException { - return null; + public boolean supportsDataManipulationTransactionsOnly() throws SQLException { + return false; } @Override - public ResultSet getColumns( - String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) - throws SQLException { - return null; + public boolean supportsDifferentTableCorrelationNames() throws SQLException { + return false; } @Override - public ResultSet getColumnPrivileges( - String catalog, String schema, String table, String columnNamePattern) throws SQLException { - return null; + public boolean supportsExpressionsInOrderBy() throws SQLException { + return false; } @Override - public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) - throws SQLException { - return null; + public boolean supportsExtendedSQLGrammar() throws SQLException { + return false; } @Override - public ResultSet getBestRowIdentifier( - String catalog, String schema, String table, int scope, boolean nullable) - throws SQLException { - return null; + public boolean supportsFullOuterJoins() throws SQLException { + return false; } @Override - public ResultSet getVersionColumns(String catalog, String schema, String table) - throws SQLException { - return null; + public boolean supportsGetGeneratedKeys() throws SQLException { + return false; } @Override - public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { - return null; + public boolean supportsGroupBy() throws SQLException { + return false; } @Override - public ResultSet getImportedKeys(String catalog, String schema, String table) - throws SQLException { - return null; + public boolean supportsGroupByBeyondSelect() throws SQLException { + return false; } @Override - public ResultSet getExportedKeys(String catalog, String schema, String table) - throws SQLException { - return null; + public boolean supportsGroupByUnrelated() throws SQLException { + return false; } @Override - public ResultSet getCrossReference( - String parentCatalog, - String parentSchema, - String parentTable, - String foreignCatalog, - String foreignSchema, - String foreignTable) - throws SQLException { - return null; + public boolean supportsIntegrityEnhancementFacility() throws SQLException { + return false; } @Override - public ResultSet getTypeInfo() throws SQLException { - return null; + public boolean supportsLikeEscapeClause() throws SQLException { + return false; } @Override - public ResultSet getIndexInfo( - String catalog, String schema, String table, boolean unique, boolean approximate) - throws SQLException { - return null; + public boolean supportsLimitedOuterJoins() throws SQLException { + return false; } @Override - public boolean supportsResultSetType(int type) throws SQLException { + public boolean supportsMinimumSQLGrammar() throws SQLException { return false; } @Override - public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { + public boolean supportsMixedCaseIdentifiers() throws SQLException { return false; } @Override - public boolean ownUpdatesAreVisible(int type) throws SQLException { + public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { return false; } @Override - public boolean ownDeletesAreVisible(int type) throws SQLException { + public boolean supportsMultipleOpenResults() throws SQLException { return false; } @Override - public boolean ownInsertsAreVisible(int type) throws SQLException { + public boolean supportsMultipleResultSets() throws SQLException { return false; } @Override - public boolean othersUpdatesAreVisible(int type) throws SQLException { + public boolean supportsMultipleTransactions() throws SQLException { return false; } @Override - public boolean othersDeletesAreVisible(int type) throws SQLException { + public boolean supportsNamedParameters() throws SQLException { return false; } @Override - public boolean othersInsertsAreVisible(int type) throws SQLException { + public boolean supportsNonNullableColumns() throws SQLException { return false; } @Override - public boolean updatesAreDetected(int type) throws SQLException { + public boolean supportsOpenCursorsAcrossCommit() throws SQLException { return false; } @Override - public boolean deletesAreDetected(int type) throws SQLException { + public boolean supportsOpenCursorsAcrossRollback() throws SQLException { return false; } @Override - public boolean insertsAreDetected(int type) throws SQLException { + public boolean supportsOpenStatementsAcrossCommit() throws SQLException { return false; } @Override - public boolean supportsBatchUpdates() throws SQLException { + public boolean supportsOpenStatementsAcrossRollback() throws SQLException { return false; } @Override - public ResultSet getUDTs( - String catalog, String schemaPattern, String typeNamePattern, int[] types) - throws SQLException { - return null; + public boolean supportsOrderByUnrelated() throws SQLException { + return false; } @Override - public Connection getConnection() throws SQLException { - return null; + public boolean supportsOuterJoins() throws SQLException { + return false; } @Override - public boolean supportsSavepoints() throws SQLException { + public boolean supportsPositionedDelete() throws SQLException { return false; } @Override - public boolean supportsNamedParameters() throws SQLException { + public boolean supportsPositionedUpdate() throws SQLException { return false; } @Override - public boolean supportsMultipleOpenResults() throws SQLException { + public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { return false; } @Override - public boolean supportsGetGeneratedKeys() throws SQLException { + public boolean supportsResultSetHoldability(int holdability) throws SQLException { return false; } @Override - public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) - throws SQLException { - return null; + public boolean supportsResultSetType(int type) throws SQLException { + return false; } @Override - public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) - throws SQLException { - return null; + public boolean supportsSavepoints() throws SQLException { + return false; } @Override - public ResultSet getAttributes( - String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) - throws SQLException { - return null; + public boolean supportsSchemasInDataManipulation() throws SQLException { + return false; } @Override - public boolean supportsResultSetHoldability(int holdability) throws SQLException { + public boolean supportsSchemasInIndexDefinitions() throws SQLException { return false; } @Override - public int getResultSetHoldability() throws SQLException { - return 0; + public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { + return false; } @Override - public int getDatabaseMajorVersion() throws SQLException { - return 0; + public boolean supportsSchemasInProcedureCalls() throws SQLException { + return false; } @Override - public int getDatabaseMinorVersion() throws SQLException { - return 0; + public boolean supportsSchemasInTableDefinitions() throws SQLException { + return false; } @Override - public int getJDBCMajorVersion() throws SQLException { - return 0; + public boolean supportsSelectForUpdate() throws SQLException { + return false; } @Override - public int getJDBCMinorVersion() throws SQLException { - return 0; + public boolean supportsStatementPooling() throws SQLException { + return false; } @Override - public int getSQLStateType() throws SQLException { - return 0; + public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { + return false; } @Override - public boolean locatorsUpdateCopy() throws SQLException { + public boolean supportsStoredProcedures() throws SQLException { return false; } @Override - public boolean supportsStatementPooling() throws SQLException { + public boolean supportsSubqueriesInComparisons() throws SQLException { return false; } @Override - public RowIdLifetime getRowIdLifetime() throws SQLException { - return null; + public boolean supportsSubqueriesInExists() throws SQLException { + return false; } @Override - public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - return null; + public boolean supportsSubqueriesInIns() throws SQLException { + return false; } @Override - public ResultSet getSchemas() throws SQLException { - return null; + public boolean supportsSubqueriesInQuantifieds() throws SQLException { + return false; } @Override - public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { + public boolean supportsTableCorrelationNames() throws SQLException { return false; } @Override - public boolean autoCommitFailureClosesAllResultSets() throws SQLException { + public boolean supportsTransactionIsolationLevel(int level) throws SQLException { return false; } @Override - public ResultSet getClientInfoProperties() throws SQLException { - return null; + public boolean supportsTransactions() throws SQLException { + return false; } @Override - public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) - throws SQLException { - return null; + public boolean supportsUnion() throws SQLException { + return false; } @Override - public ResultSet getFunctionColumns( - String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) - throws SQLException { - return null; + public boolean supportsUnionAll() throws SQLException { + return false; } @Override - public ResultSet getPseudoColumns( - String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) - throws SQLException { + public T unwrap(Class iface) throws SQLException { return null; } @Override - public boolean generatedKeyAlwaysReturned() throws SQLException { - ; + public boolean updatesAreDetected(int type) throws SQLException { return false; } @Override - public T unwrap(Class iface) throws SQLException { - return null; + public boolean usesLocalFilePerTable() throws SQLException { + return false; } @Override - public boolean isWrapperFor(Class iface) throws SQLException { + public boolean usesLocalFiles() throws SQLException { return false; } } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java index dcf86d958b3b..8c8c0092a3db 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestPreparedStatement.java @@ -27,7 +27,6 @@ import java.sql.Timestamp; import java.util.Calendar; -@SuppressWarnings("UngroupedOverloads") class TestPreparedStatement extends TestStatement implements PreparedStatement { TestPreparedStatement() { @@ -38,6 +37,12 @@ class TestPreparedStatement extends TestStatement implements PreparedStatement { super(connection); } + @Override + public void addBatch() throws SQLException {} + + @Override + public void clearParameters() throws SQLException {} + @Override public boolean execute() throws SQLException { return true; @@ -54,168 +59,162 @@ public int executeUpdate() throws SQLException { } @Override - public void setNull(int parameterIndex, int sqlType) throws SQLException {} - - @Override - public void setBoolean(int parameterIndex, boolean x) throws SQLException {} - - @Override - public void setByte(int parameterIndex, byte x) throws SQLException {} + public ResultSetMetaData getMetaData() throws SQLException { + return null; + } @Override - public void setShort(int parameterIndex, short x) throws SQLException {} + public ParameterMetaData getParameterMetaData() throws SQLException { + return null; + } @Override - public void setInt(int parameterIndex, int x) throws SQLException {} + public void setArray(int parameterIndex, Array x) throws SQLException {} @Override - public void setLong(int parameterIndex, long x) throws SQLException {} + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {} @Override - public void setFloat(int parameterIndex, float x) throws SQLException {} + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {} @Override - public void setDouble(int parameterIndex, double x) throws SQLException {} + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {} @Override public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {} @Override - public void setString(int parameterIndex, String x) throws SQLException {} - - @Override - public void setBytes(int parameterIndex, byte[] x) throws SQLException {} - - @Override - public void setDate(int parameterIndex, Date x) throws SQLException {} - - @Override - public void setTime(int parameterIndex, Time x) throws SQLException {} + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {} @Override - public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {} + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {} @Override - public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {} + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {} @Override - @Deprecated - public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {} + public void setBlob(int parameterIndex, Blob x) throws SQLException {} @Override - public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {} + public void setBlob(int parameterIndex, InputStream inputStream, long length) + throws SQLException {} @Override - public void clearParameters() throws SQLException {} + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {} @Override - public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {} + public void setBoolean(int parameterIndex, boolean x) throws SQLException {} @Override - public void setObject(int parameterIndex, Object x) throws SQLException {} + public void setByte(int parameterIndex, byte x) throws SQLException {} @Override - public void addBatch() throws SQLException {} + public void setBytes(int parameterIndex, byte[] x) throws SQLException {} @Override public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {} @Override - public void setRef(int parameterIndex, Ref x) throws SQLException {} + public void setCharacterStream(int parameterIndex, Reader reader, long length) + throws SQLException {} @Override - public void setBlob(int parameterIndex, Blob x) throws SQLException {} + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {} @Override public void setClob(int parameterIndex, Clob x) throws SQLException {} @Override - public void setArray(int parameterIndex, Array x) throws SQLException {} + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {} @Override - public ResultSetMetaData getMetaData() throws SQLException { - return null; - } + public void setClob(int parameterIndex, Reader reader) throws SQLException {} + + @Override + public void setDate(int parameterIndex, Date x) throws SQLException {} @Override public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {} @Override - public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {} + public void setDouble(int parameterIndex, double x) throws SQLException {} @Override - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {} + public void setFloat(int parameterIndex, float x) throws SQLException {} @Override - public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {} + public void setInt(int parameterIndex, int x) throws SQLException {} @Override - public void setURL(int parameterIndex, URL x) throws SQLException {} + public void setLong(int parameterIndex, long x) throws SQLException {} @Override - public ParameterMetaData getParameterMetaData() throws SQLException { - return null; - } + public void setNCharacterStream(int parameterIndex, Reader value, long length) + throws SQLException {} @Override - public void setRowId(int parameterIndex, RowId x) throws SQLException {} + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {} @Override - public void setNString(int parameterIndex, String value) throws SQLException {} + public void setNClob(int parameterIndex, NClob value) throws SQLException {} @Override - public void setNCharacterStream(int parameterIndex, Reader value, long length) - throws SQLException {} + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {} @Override - public void setNClob(int parameterIndex, NClob value) throws SQLException {} + public void setNClob(int parameterIndex, Reader reader) throws SQLException {} @Override - public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {} + public void setNString(int parameterIndex, String value) throws SQLException {} @Override - public void setBlob(int parameterIndex, InputStream inputStream, long length) - throws SQLException {} + public void setNull(int parameterIndex, int sqlType) throws SQLException {} @Override - public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {} + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {} @Override - public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {} + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {} + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException {} @Override public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {} @Override - public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {} + public void setRef(int parameterIndex, Ref x) throws SQLException {} @Override - public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {} + public void setRowId(int parameterIndex, RowId x) throws SQLException {} @Override - public void setCharacterStream(int parameterIndex, Reader reader, long length) - throws SQLException {} + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {} @Override - public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {} + public void setShort(int parameterIndex, short x) throws SQLException {} @Override - public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {} + public void setString(int parameterIndex, String x) throws SQLException {} @Override - public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {} + public void setTime(int parameterIndex, Time x) throws SQLException {} @Override - public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {} + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {} @Override - public void setClob(int parameterIndex, Reader reader) throws SQLException {} + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {} @Override - public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {} + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {} @Override - public void setNClob(int parameterIndex, Reader reader) throws SQLException {} + public void setURL(int parameterIndex, URL x) throws SQLException {} + + @Override + @Deprecated + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {} } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java index 644c333cf500..b6db71df4565 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestStatement.java @@ -11,7 +11,6 @@ import java.sql.SQLWarning; import java.sql.Statement; -@SuppressWarnings("UngroupedOverloads") class TestStatement implements Statement { final Connection connection; @@ -24,77 +23,76 @@ class TestStatement implements Statement { } @Override - public ResultSet executeQuery(String sql) throws SQLException { - return null; - } + public void addBatch(String sql) throws SQLException {} @Override - public int executeUpdate(String sql) throws SQLException { - return 0; - } + public void cancel() throws SQLException {} @Override - public void close() throws SQLException {} + public void clearBatch() throws SQLException {} @Override - public int getMaxFieldSize() throws SQLException { - return 0; - } + public void clearWarnings() throws SQLException {} @Override - public void setMaxFieldSize(int max) throws SQLException {} + public void close() throws SQLException {} @Override - public int getMaxRows() throws SQLException { - return 0; - } + public void closeOnCompletion() throws SQLException {} @Override - public void setMaxRows(int max) throws SQLException {} + public boolean execute(String sql) throws SQLException { + return true; + } @Override - public void setEscapeProcessing(boolean enable) throws SQLException {} + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + return true; + } @Override - public int getQueryTimeout() throws SQLException { - return 0; + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + return true; } @Override - public void setQueryTimeout(int seconds) throws SQLException {} + public boolean execute(String sql, String[] columnNames) throws SQLException { + return true; + } @Override - public void cancel() throws SQLException {} + public int[] executeBatch() throws SQLException { + return new int[0]; + } @Override - public SQLWarning getWarnings() throws SQLException { + public ResultSet executeQuery(String sql) throws SQLException { return null; } @Override - public void clearWarnings() throws SQLException {} - - @Override - public void setCursorName(String name) throws SQLException {} + public int executeUpdate(String sql) throws SQLException { + return 0; + } @Override - public boolean execute(String sql) throws SQLException { - return true; + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + return 0; } @Override - public ResultSet getResultSet() throws SQLException { - return null; + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + return 0; } @Override - public int getUpdateCount() throws SQLException { + public int executeUpdate(String sql, String[] columnNames) throws SQLException { return 0; } @Override - public boolean getMoreResults() throws SQLException { - return false; + public Connection getConnection() throws SQLException { + return connection; } @Override @@ -102,116 +100,117 @@ public int getFetchDirection() throws SQLException { return 0; } - @Override - public void setFetchDirection(int direction) throws SQLException {} - @Override public int getFetchSize() throws SQLException { return 0; } @Override - public void setFetchSize(int rows) throws SQLException {} + public ResultSet getGeneratedKeys() throws SQLException { + return null; + } @Override - public int getResultSetConcurrency() throws SQLException { + public int getMaxFieldSize() throws SQLException { return 0; } @Override - public int getResultSetType() throws SQLException { + public int getMaxRows() throws SQLException { return 0; } @Override - public void addBatch(String sql) throws SQLException {} - - @Override - public void clearBatch() throws SQLException {} - - @Override - public int[] executeBatch() throws SQLException { - return new int[0]; + public boolean getMoreResults() throws SQLException { + return false; } @Override - public Connection getConnection() throws SQLException { - return connection; + public boolean getMoreResults(int current) throws SQLException { + return false; } @Override - public boolean getMoreResults(int current) throws SQLException { - return false; + public int getQueryTimeout() throws SQLException { + return 0; } @Override - public ResultSet getGeneratedKeys() throws SQLException { + public ResultSet getResultSet() throws SQLException { return null; } @Override - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + public int getResultSetConcurrency() throws SQLException { return 0; } @Override - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + public int getResultSetHoldability() throws SQLException { return 0; } @Override - public int executeUpdate(String sql, String[] columnNames) throws SQLException { + public int getResultSetType() throws SQLException { return 0; } @Override - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - return true; + public int getUpdateCount() throws SQLException { + return 0; } @Override - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - return true; + public SQLWarning getWarnings() throws SQLException { + return null; } @Override - public boolean execute(String sql, String[] columnNames) throws SQLException { - return true; + public boolean isCloseOnCompletion() throws SQLException { + return false; } @Override - public int getResultSetHoldability() throws SQLException { - return 0; + public boolean isClosed() throws SQLException { + return false; } @Override - public boolean isClosed() throws SQLException { + public boolean isPoolable() throws SQLException { return false; } @Override - public boolean isPoolable() throws SQLException { + public boolean isWrapperFor(Class iface) throws SQLException { return false; } @Override - public void setPoolable(boolean poolable) throws SQLException {} + public void setCursorName(String name) throws SQLException {} @Override - public void closeOnCompletion() throws SQLException {} + public void setEscapeProcessing(boolean enable) throws SQLException {} @Override - public boolean isCloseOnCompletion() throws SQLException { - return false; - } + public void setFetchDirection(int direction) throws SQLException {} @Override - public T unwrap(Class iface) throws SQLException { - return null; - } + public void setFetchSize(int rows) throws SQLException {} @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; + public void setMaxFieldSize(int max) throws SQLException {} + + @Override + public void setMaxRows(int max) throws SQLException {} + + @Override + public void setPoolable(boolean poolable) throws SQLException {} + + @Override + public void setQueryTimeout(int seconds) throws SQLException {} + + @Override + public T unwrap(Class iface) throws SQLException { + return null; } } From e899cf488b66b1e86b5ad65cf12ecbeec0cbb54a Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Fri, 6 Sep 2024 17:53:36 +0800 Subject: [PATCH 03/11] add more jdbc test --- .../groovy/JdbcInstrumentationTest.groovy | 903 -------------- .../jdbc/test/JdbcInstrumentationTest.java | 1102 ++++++++++++++++- .../instrumentation/jdbc/TestConnection.java | 2 +- .../instrumentation/jdbc/TestDriver.java | 2 +- 4 files changed, 1082 insertions(+), 927 deletions(-) delete mode 100644 instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy diff --git a/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy b/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy deleted file mode 100644 index 39eec0059569..000000000000 --- a/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy +++ /dev/null @@ -1,903 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import com.mchange.v2.c3p0.ComboPooledDataSource -import com.zaxxer.hikari.HikariConfig -import com.zaxxer.hikari.HikariDataSource -import io.opentelemetry.api.trace.SpanKind -import io.opentelemetry.instrumentation.jdbc.TestConnection -import io.opentelemetry.instrumentation.jdbc.TestDriver -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import io.opentelemetry.javaagent.instrumentation.jdbc.test.ProxyStatementFactory -import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes -import io.opentelemetry.semconv.incubating.DbIncubatingAttributes -import io.opentelemetry.semconv.ServerAttributes -import org.apache.derby.jdbc.EmbeddedDataSource -import org.apache.derby.jdbc.EmbeddedDriver -import org.h2.Driver -import org.h2.jdbcx.JdbcDataSource -import org.hsqldb.jdbc.JDBCDriver -import spock.lang.Shared -import spock.lang.Unroll - -import javax.sql.DataSource -import java.sql.CallableStatement -import java.sql.Connection -import java.sql.DatabaseMetaData -import java.sql.PreparedStatement -import java.sql.ResultSet -import java.sql.SQLException -import java.sql.Statement - -import static io.opentelemetry.api.trace.SpanKind.CLIENT -import static io.opentelemetry.api.trace.SpanKind.INTERNAL - -@Unroll -class JdbcInstrumentationTest extends AgentInstrumentationSpecification { - - @Shared - def dbName = "jdbcUnitTest" - @Shared - def dbNameLower = dbName.toLowerCase() - - @Shared - private Map jdbcUrls = [ - "h2" : "jdbc:h2:mem:$dbName", - "derby" : "jdbc:derby:memory:$dbName", - "hsqldb": "jdbc:hsqldb:mem:$dbName", - ] - - @Shared - private Map jdbcDriverClassNames = [ - "h2" : "org.h2.Driver", - "derby" : "org.apache.derby.jdbc.EmbeddedDriver", - "hsqldb": "org.hsqldb.jdbc.JDBCDriver", - ] - - @Shared - private Map jdbcUserNames = [ - "h2" : null, - "derby" : "APP", - "hsqldb": "SA", - ] - - @Shared - private Properties connectionProps = { - def props = new Properties() -// props.put("user", "someUser") -// props.put("password", "somePassword") - props.put("databaseName", "someDb") - props.put("OPEN_NEW", "true") // So H2 doesn't complain about username/password. - return props - }() - - // JDBC Connection pool name (i.e. HikariCP) -> Map - @Shared - private Map> cpDatasources = new HashMap<>() - - def prepareConnectionPoolDatasources() { - String[] connectionPoolNames = [ - "tomcat", "hikari", "c3p0", - ] - connectionPoolNames.each { - cpName -> - Map dbDSMapping = new HashMap<>() - jdbcUrls.each { - dbType, jdbcUrl -> - dbDSMapping.put(dbType, createDS(cpName, dbType, jdbcUrl)) - } - cpDatasources.put(cpName, dbDSMapping) - } - } - - def createTomcatDS(String dbType, String jdbcUrl) { - DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource() - def jdbcUrlToSet = dbType == "derby" ? jdbcUrl + ";create=true" : jdbcUrl - ds.setUrl(jdbcUrlToSet) - ds.setDriverClassName(jdbcDriverClassNames.get(dbType)) - String username = jdbcUserNames.get(dbType) - if (username != null) { - ds.setUsername(username) - } - ds.setPassword("") - ds.setMaxActive(1) // to test proper caching, having > 1 max active connection will be hard to - // determine whether the connection is properly cached - return ds - } - - def createHikariDS(String dbType, String jdbcUrl) { - HikariConfig config = new HikariConfig() - def jdbcUrlToSet = dbType == "derby" ? jdbcUrl + ";create=true" : jdbcUrl - config.setJdbcUrl(jdbcUrlToSet) - String username = jdbcUserNames.get(dbType) - if (username != null) { - config.setUsername(username) - } - config.setPassword("") - config.addDataSourceProperty("cachePrepStmts", "true") - config.addDataSourceProperty("prepStmtCacheSize", "250") - config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048") - config.setMaximumPoolSize(1) - - return new HikariDataSource(config) - } - - def createC3P0DS(String dbType, String jdbcUrl) { - DataSource ds = new ComboPooledDataSource() - ds.setDriverClass(jdbcDriverClassNames.get(dbType)) - def jdbcUrlToSet = dbType == "derby" ? jdbcUrl + ";create=true" : jdbcUrl - ds.setJdbcUrl(jdbcUrlToSet) - String username = jdbcUserNames.get(dbType) - if (username != null) { - ds.setUser(username) - } - ds.setPassword("") - ds.setMaxPoolSize(1) - return ds - } - - def createDS(String connectionPoolName, String dbType, String jdbcUrl) { - DataSource ds = null - if (connectionPoolName == "tomcat") { - ds = createTomcatDS(dbType, jdbcUrl) - } - if (connectionPoolName == "hikari") { - ds = createHikariDS(dbType, jdbcUrl) - } - if (connectionPoolName == "c3p0") { - ds = createC3P0DS(dbType, jdbcUrl) - } - return ds - } - - def setupSpec() { - prepareConnectionPoolDatasources() - } - - def cleanupSpec() { - cpDatasources.values().each { - it.values().each { - datasource -> - if (datasource instanceof Closeable) { - datasource.close() - } - } - } - } - - @SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation - def "basic statement with #connection.getClass().getCanonicalName() on #system generates spans"() { - setup: - Statement statement = connection.createStatement() - ResultSet resultSet = runWithSpan("parent") { - return statement.executeQuery(query) - } - - expect: - resultSet.next() - resultSet.getInt(1) == 3 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_NAME" dbNameLower - if (username != null) { - "$DbIncubatingAttributes.DB_USER" username - } - "$DbIncubatingAttributes.DB_CONNECTION_STRING" url - "$DbIncubatingAttributes.DB_STATEMENT" sanitizedQuery - "$DbIncubatingAttributes.DB_OPERATION" "SELECT" - "$DbIncubatingAttributes.DB_SQL_TABLE" table - } - } - } - } - - cleanup: - statement.close() - connection.close() - - where: - system | connection | username | query | sanitizedQuery | spanName | url | table - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" | "SELECT INFORMATION_SCHEMA.SYSTEM_USERS" | "hsqldb:mem:" | "INFORMATION_SCHEMA.SYSTEM_USERS" - } - - def "prepared statement execute on #system with #connection.getClass().getCanonicalName() generates a span"() { - setup: - PreparedStatement statement = connection.prepareStatement(query) - ResultSet resultSet = runWithSpan("parent") { - assert statement.execute() - return statement.resultSet - } - - expect: - resultSet.next() - resultSet.getInt(1) == 3 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_NAME" dbNameLower - if (username != null) { - "$DbIncubatingAttributes.DB_USER" username - } - "$DbIncubatingAttributes.DB_CONNECTION_STRING" url - "$DbIncubatingAttributes.DB_STATEMENT" sanitizedQuery - "$DbIncubatingAttributes.DB_OPERATION" "SELECT" - "$DbIncubatingAttributes.DB_SQL_TABLE" table - } - } - } - } - - cleanup: - statement.close() - connection.close() - - where: - system | connection | username | query | sanitizedQuery | spanName | url | table - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - } - - def "prepared statement query on #system with #connection.getClass().getCanonicalName() generates a span"() { - setup: - PreparedStatement statement = connection.prepareStatement(query) - ResultSet resultSet = runWithSpan("parent") { - return statement.executeQuery() - } - - expect: - resultSet.next() - resultSet.getInt(1) == 3 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_NAME" dbNameLower - if (username != null) { - "$DbIncubatingAttributes.DB_USER" username - } - "$DbIncubatingAttributes.DB_CONNECTION_STRING" url - "$DbIncubatingAttributes.DB_STATEMENT" sanitizedQuery - "$DbIncubatingAttributes.DB_OPERATION" "SELECT" - "$DbIncubatingAttributes.DB_SQL_TABLE" table - } - } - } - } - - cleanup: - statement.close() - connection.close() - - where: - system | connection | username | query | sanitizedQuery | spanName | url | table - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - } - - def "prepared call on #system with #connection.getClass().getCanonicalName() generates a span"() { - setup: - CallableStatement statement = connection.prepareCall(query) - ResultSet resultSet = runWithSpan("parent") { - return statement.executeQuery() - } - - expect: - resultSet.next() - resultSet.getInt(1) == 3 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_NAME" dbName.toLowerCase() - if (username != null) { - "$DbIncubatingAttributes.DB_USER" username - } - "$DbIncubatingAttributes.DB_CONNECTION_STRING" url - "$DbIncubatingAttributes.DB_STATEMENT" sanitizedQuery - "$DbIncubatingAttributes.DB_OPERATION" "SELECT" - "$DbIncubatingAttributes.DB_SQL_TABLE" table - } - } - } - } - - cleanup: - statement.close() - connection.close() - - where: - system | connection | username | query | sanitizedQuery | spanName | url | table - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3" | "SELECT ?" | "SELECT $dbNameLower" | "h2:mem:" | null - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - } - - def "statement update on #system with #connection.getClass().getCanonicalName() generates a span"() { - setup: - Statement statement = connection.createStatement() - def sql = connection.nativeSQL(query) - - expect: - runWithSpan("parent") { - return !statement.execute(sql) - } - statement.updateCount == 0 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_NAME" dbNameLower - if (username != null) { - "$DbIncubatingAttributes.DB_USER" username - } - "$DbIncubatingAttributes.DB_STATEMENT" query - "$DbIncubatingAttributes.DB_CONNECTION_STRING" url - "$DbIncubatingAttributes.DB_OPERATION" "CREATE TABLE" - "$DbIncubatingAttributes.DB_SQL_TABLE" table - } - } - } - } - - cleanup: - statement.close() - connection.close() - - where: - system | connection | username | query | spanName | url | table - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2" | "h2:mem:" | "S_H2" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY" | "derby:memory:" | "S_DERBY" - "hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2_TOMCAT" | "h2:mem:" | "S_H2_TOMCAT" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY_TOMCAT" | "derby:memory:" | "S_DERBY_TOMCAT" - "hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB_TOMCAT" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2_HIKARI" | "h2:mem:" | "S_H2_HIKARI" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY_HIKARI" | "derby:memory:" | "S_DERBY_HIKARI" - "hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB_HIKARI" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_H2_C3P0" | "h2:mem:" | "S_H2_C3P0" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.S_DERBY_C3P0" | "derby:memory:" | "S_DERBY_C3P0" - "hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE PUBLIC.S_HSQLDB_C3P0" | "hsqldb:mem:" | "PUBLIC.S_HSQLDB_C3P0" - } - - def "prepared statement update on #system with #connection.getClass().getCanonicalName() generates a span"() { - setup: - def sql = connection.nativeSQL(query) - PreparedStatement statement = connection.prepareStatement(sql) - - expect: - runWithSpan("parent") { - return statement.executeUpdate() == 0 - } - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_NAME" dbName.toLowerCase() - if (username != null) { - "$DbIncubatingAttributes.DB_USER" username - } - "$DbIncubatingAttributes.DB_STATEMENT" query - "$DbIncubatingAttributes.DB_CONNECTION_STRING" url - "$DbIncubatingAttributes.DB_OPERATION" "CREATE TABLE" - "$DbIncubatingAttributes.DB_SQL_TABLE" table - } - } - } - } - - cleanup: - statement.close() - connection.close() - - where: - system | connection | username | query | spanName | url | table - "h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2" | "h2:mem:" | "PS_H2" - "derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY" | "derby:memory:" | "PS_DERBY" - "h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2_TOMCAT" | "h2:mem:" | "PS_H2_TOMCAT" - "derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY_TOMCAT" | "derby:memory:" | "PS_DERBY_TOMCAT" - "h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2_HIKARI" | "h2:mem:" | "PS_H2_HIKARI" - "derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY_HIKARI" | "derby:memory:" | "PS_DERBY_HIKARI" - "h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_H2_C3P0" | "h2:mem:" | "PS_H2_C3P0" - "derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))" | "CREATE TABLE jdbcunittest.PS_DERBY_C3P0" | "derby:memory:" | "PS_DERBY_C3P0" - } - - def "connection constructor throwing then generating correct spans after recovery using #driver connection (prepare statement = #prepareStatement)"() { - setup: - Connection connection = null - - when: - try { - connection = new TestConnection(true) - connection.url = "jdbc:testdb://localhost" - } catch (Exception ignored) { - connection = driver.connect(jdbcUrl, null) - } - - def (Statement statement, ResultSet rs) = runWithSpan("parent") { - if (prepareStatement) { - def stmt = connection.prepareStatement(query) - return new Tuple(stmt, stmt.executeQuery()) - } - - def stmt = connection.createStatement() - return new Tuple(stmt, stmt.executeQuery(query)) - } - - then: - rs.next() - rs.getInt(1) == 3 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_NAME" dbNameLower - if (username != null) { - "$DbIncubatingAttributes.DB_USER" username - } - "$DbIncubatingAttributes.DB_CONNECTION_STRING" url - "$DbIncubatingAttributes.DB_STATEMENT" sanitizedQuery - "$DbIncubatingAttributes.DB_OPERATION" "SELECT" - "$DbIncubatingAttributes.DB_SQL_TABLE" table - } - } - } - } - - cleanup: - statement?.close() - connection?.close() - - where: - prepareStatement | system | driver | jdbcUrl | username | query | sanitizedQuery | spanName | url | table - true | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "SELECT ?;" | "SELECT $dbNameLower" | "h2:mem:" | null - true | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - false | "h2" | new Driver() | "jdbc:h2:mem:" + dbName | null | "SELECT 3;" | "SELECT ?;" | "SELECT $dbNameLower" | "h2:mem:" | null - false | "derby" | new EmbeddedDriver() | "jdbc:derby:memory:" + dbName + ";create=true" | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1" | "SELECT ? FROM SYSIBM.SYSDUMMY1" | "SELECT SYSIBM.SYSDUMMY1" | "derby:memory:" | "SYSIBM.SYSDUMMY1" - } - - def "calling #datasource.class.simpleName getConnection generates a span when under existing trace"() { - setup: - assert datasource instanceof DataSource - init?.call(datasource) - - when: - datasource.getConnection().close() - - then: - !traces.any { it.any { it.name == "database.connection" } } - clearExportedData() - - when: - runWithSpan("parent") { - datasource.getConnection().close() - } - - then: - assertTraces(1) { - trace(0, recursive ? 3 : 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - - span(1) { - name "${datasource.class.simpleName}.getConnection" - kind INTERNAL - childOf span(0) - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" datasource.class.name - "$CodeIncubatingAttributes.CODE_FUNCTION" "getConnection" - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_USER" { user == null | user == it } - "$DbIncubatingAttributes.DB_NAME" "jdbcunittest" - "$DbIncubatingAttributes.DB_CONNECTION_STRING" connectionString - } - } - if (recursive) { - span(2) { - name "${datasource.class.simpleName}.getConnection" - kind INTERNAL - childOf span(1) - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" datasource.class.name - "$CodeIncubatingAttributes.CODE_FUNCTION" "getConnection" - "$DbIncubatingAttributes.DB_SYSTEM" system - "$DbIncubatingAttributes.DB_USER" { user == null | user == it } - "$DbIncubatingAttributes.DB_NAME" "jdbcunittest" - "$DbIncubatingAttributes.DB_CONNECTION_STRING" connectionString - } - } - } - } - } - - where: - datasource | init | system | user | connectionString - new JdbcDataSource() | { ds -> ds.setURL(jdbcUrls.get("h2")) } | "h2" | null | "h2:mem:" - new EmbeddedDataSource() | { ds -> ds.jdbcurl = jdbcUrls.get("derby") } | "derby" | "APP" | "derby:memory:" - cpDatasources.get("hikari").get("h2") | null | "h2" | null | "h2:mem:" - cpDatasources.get("hikari").get("derby") | null | "derby" | "APP" | "derby:memory:" - cpDatasources.get("c3p0").get("h2") | null | "h2" | null | "h2:mem:" - cpDatasources.get("c3p0").get("derby") | null | "derby" | "APP" | "derby:memory:" - - // Tomcat's pool doesn't work because the getConnection method is - // implemented in a parent class that doesn't implement DataSource - - recursive = datasource instanceof EmbeddedDataSource - } - - def "test getClientInfo exception"() { - setup: - Connection connection = new TestConnection(false) - connection.url = "jdbc:testdb://localhost" - - when: - Statement statement = null - runWithSpan("parent") { - statement = connection.createStatement() - return statement.executeQuery(query) - } - - then: - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name "DB Query" - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" "other_sql" - "$DbIncubatingAttributes.DB_STATEMENT" "testing ?" - "$DbIncubatingAttributes.DB_CONNECTION_STRING" "testdb://localhost" - "$ServerAttributes.SERVER_ADDRESS" "localhost" - } - } - } - } - - cleanup: - statement?.close() - connection?.close() - - where: - query = "testing 123" - } - - def "should produce proper span name #spanName"() { - setup: - def driver = new TestDriver() - - when: - def connection = driver.connect(url, null) - runWithSpan("parent") { - def statement = connection.createStatement() - return statement.executeQuery(query) - } - - then: - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name spanName - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" "other_sql" - "$DbIncubatingAttributes.DB_NAME" databaseName - "$DbIncubatingAttributes.DB_CONNECTION_STRING" "testdb://localhost" - "$DbIncubatingAttributes.DB_STATEMENT" sanitizedQuery - "$DbIncubatingAttributes.DB_OPERATION" operation - "$DbIncubatingAttributes.DB_SQL_TABLE" table - "$ServerAttributes.SERVER_ADDRESS" "localhost" - } - } - } - } - - where: - url | query | sanitizedQuery | spanName | databaseName | operation | table - "jdbc:testdb://localhost?databaseName=test" | "SELECT * FROM table" | "SELECT * FROM table" | "SELECT test.table" | "test" | "SELECT" | "table" - "jdbc:testdb://localhost?databaseName=test" | "SELECT 42" | "SELECT ?" | "SELECT test" | "test" | "SELECT" | null - "jdbc:testdb://localhost" | "SELECT * FROM table" | "SELECT * FROM table" | "SELECT table" | null | "SELECT" | "table" - "jdbc:testdb://localhost?databaseName=test" | "CREATE TABLE table" | "CREATE TABLE table" | "CREATE TABLE test.table" | "test" | "CREATE TABLE" | "table" - "jdbc:testdb://localhost" | "CREATE TABLE table" | "CREATE TABLE table" | "CREATE TABLE table" | null | "CREATE TABLE" | "table" - } - - def "#connectionPoolName connections should be cached in case of wrapped connections"() { - setup: - String dbType = "hsqldb" - DataSource ds = createDS(connectionPoolName, dbType, jdbcUrls.get(dbType)) - String query = "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS" - int numQueries = 5 - Connection connection = null - int[] res = new int[numQueries] - - when: - for (int i = 0; i < numQueries; ++i) { - try { - connection = ds.getConnection() - def statement = connection.prepareStatement(query) - def rs = statement.executeQuery() - if (rs.next()) { - res[i] = rs.getInt(1) - } else { - res[i] = 0 - } - } finally { - connection.close() - } - } - - then: - for (int i = 0; i < numQueries; ++i) { - res[i] == 3 - } - assertTraces(numQueries) { - for (int i = 0; i < numQueries; ++i) { - trace(i, 1) { - span(0) { - name "SELECT INFORMATION_SCHEMA.SYSTEM_USERS" - kind CLIENT - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" "hsqldb" - "$DbIncubatingAttributes.DB_NAME" dbNameLower - "$DbIncubatingAttributes.DB_USER" "SA" - "$DbIncubatingAttributes.DB_CONNECTION_STRING" "hsqldb:mem:" - "$DbIncubatingAttributes.DB_STATEMENT" "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS" - "$DbIncubatingAttributes.DB_OPERATION" "SELECT" - "$DbIncubatingAttributes.DB_SQL_TABLE" "INFORMATION_SCHEMA.SYSTEM_USERS" - } - } - } - } - } - - cleanup: - if (ds instanceof Closeable) { - ds.close() - } - - where: - connectionPoolName | _ - "hikari" | _ - "tomcat" | _ - "c3p0" | _ - } - - // regression test for https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/2644 - def "should handle recursive Statements inside Connection.getMetaData(): #desc"() { - given: - def connection = new DbCallingConnection(usePreparedStatementInConnection) - connection.url = "jdbc:testdb://localhost" - - when: - runWithSpan("parent") { - executeQueryFunction(connection, "SELECT * FROM table") - } - - then: - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name "SELECT table" - kind CLIENT - childOf span(0) - attributes { - "$DbIncubatingAttributes.DB_SYSTEM" "other_sql" - "$DbIncubatingAttributes.DB_CONNECTION_STRING" "testdb://localhost" - "$DbIncubatingAttributes.DB_STATEMENT" "SELECT * FROM table" - "$DbIncubatingAttributes.DB_OPERATION" "SELECT" - "$DbIncubatingAttributes.DB_SQL_TABLE" "table" - "$ServerAttributes.SERVER_ADDRESS" "localhost" - } - } - } - } - - where: - desc | usePreparedStatementInConnection | executeQueryFunction - "getMetaData() uses Statement, test Statement" | false | { con, query -> con.createStatement().executeQuery(query) } - "getMetaData() uses PreparedStatement, test Statement" | true | { con, query -> con.createStatement().executeQuery(query) } - "getMetaData() uses Statement, test PreparedStatement" | false | { con, query -> con.prepareStatement(query).executeQuery() } - "getMetaData() uses PreparedStatement, test PreparedStatement" | true | { con, query -> con.prepareStatement(query).executeQuery() } - } - - class DbCallingConnection extends TestConnection { - final boolean usePreparedStatement - - DbCallingConnection(boolean usePreparedStatement) { - super(false) - this.usePreparedStatement = usePreparedStatement - } - - @Override - DatabaseMetaData getMetaData() throws SQLException { - // simulate retrieving DB metadata from the DB itself - if (usePreparedStatement) { - prepareStatement("SELECT * from DB_METADATA").executeQuery() - } else { - createStatement().executeQuery("SELECT * from DB_METADATA") - } - return super.getMetaData() - } - } - - // regression test for https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/6015 - def "test proxy statement"() { - def connection = new Driver().connect(jdbcUrls.get("h2"), null) - Statement statement = connection.createStatement() - Statement proxyStatement = ProxyStatementFactory.proxyStatement(statement) - ResultSet resultSet = runWithSpan("parent") { - return proxyStatement.executeQuery("SELECT 3") - } - - expect: - resultSet.next() - resultSet.getInt(1) == 3 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name "SELECT $dbNameLower" - kind CLIENT - childOf span(0) - } - } - } - - cleanup: - statement.close() - connection.close() - } - - // regression test for https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/9359 - def "test proxy prepared statement"() { - def connection = new Driver().connect(jdbcUrls.get("h2"), null) - PreparedStatement statement = connection.prepareStatement("SELECT 3") - PreparedStatement proxyStatement = ProxyStatementFactory.proxyPreparedStatement(statement) - ResultSet resultSet = runWithSpan("parent") { - return proxyStatement.executeQuery() - } - - expect: - resultSet.next() - resultSet.getInt(1) == 3 - assertTraces(1) { - trace(0, 2) { - span(0) { - name "parent" - kind SpanKind.INTERNAL - hasNoParent() - } - span(1) { - name "SELECT $dbNameLower" - kind CLIENT - childOf span(0) - } - } - } - - cleanup: - statement.close() - connection.close() - } -} diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index e25b1942ee3f..4cc4e48f6fdd 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -14,17 +14,29 @@ import com.mchange.v2.c3p0.ComboPooledDataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.jdbc.TestConnection; +import io.opentelemetry.instrumentation.jdbc.TestDriver; +import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.sdk.testing.assertj.TraceAssert; +import io.opentelemetry.semconv.ServerAttributes; +import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import java.beans.PropertyVetoException; import java.io.Closeable; import java.io.IOException; +import java.sql.CallableStatement; import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.Driver; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -32,38 +44,43 @@ import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.sql.DataSource; +import org.apache.derby.jdbc.EmbeddedDataSource; import org.apache.derby.jdbc.EmbeddedDriver; -import org.h2.Driver; +import org.h2.jdbcx.JdbcDataSource; import org.hsqldb.jdbc.JDBCDriver; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; -@TestInstance(TestInstance.Lifecycle.PER_CLASS) class JdbcInstrumentationTest { + @RegisterExtension static AutoCleanupExtension cleanup = AutoCleanupExtension.create(); + @RegisterExtension static InstrumentationExtension testing = AgentInstrumentationExtension.create(); - private String dbName; - private String dbNameLower; - private Map jdbcUrls; - private Map jdbcDriverClassNames; - private Map jdbcUserNames; - private Properties connectionProps; + private static String dbName; + private static String dbNameLower; + private static Map jdbcUrls; + private static Map jdbcDriverClassNames; + private static Map jdbcUserNames; + private static Properties connectionProps; // JDBC Connection pool name (i.e. HikariCP) -> Map - private Map> cpDatasources; + private static Map> cpDatasources; @BeforeAll - public void setUp() { + static void setUp() { dbName = "jdbcUnitTest"; dbNameLower = dbName.toLowerCase(Locale.ROOT); jdbcUrls = @@ -97,7 +114,7 @@ public void setUp() { } @AfterAll - public void tearDown() { + static void tearDown() { cpDatasources .values() .forEach( @@ -108,14 +125,14 @@ public void tearDown() { if (dataSource instanceof Closeable) { try { ((Closeable) dataSource).close(); - } catch (IOException e) { + } catch (IOException ignore) { // ignore } } })); } - void prepareConnectionPoolDatasources() { + static void prepareConnectionPoolDatasources() { List connectionPoolNames = asList("tomcat", "hikari", "c3p0"); connectionPoolNames.forEach( cpName -> { @@ -126,7 +143,7 @@ void prepareConnectionPoolDatasources() { }); } - DataSource createTomcatDs(String dbType, String jdbcUrl) { + static DataSource createTomcatDs(String dbType, String jdbcUrl) { org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(); String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; ds.setUrl(jdbcUrlToSet); @@ -141,7 +158,7 @@ DataSource createTomcatDs(String dbType, String jdbcUrl) { return ds; } - DataSource createHikariDs(String dbType, String jdbcUrl) { + static DataSource createHikariDs(String dbType, String jdbcUrl) { HikariConfig config = new HikariConfig(); String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; config.setJdbcUrl(jdbcUrlToSet); @@ -158,7 +175,7 @@ DataSource createHikariDs(String dbType, String jdbcUrl) { return new HikariDataSource(config); } - DataSource createC3P0Ds(String dbType, String jdbcUrl) { + static DataSource createC3P0Ds(String dbType, String jdbcUrl) { ComboPooledDataSource ds = new ComboPooledDataSource(); try { ds.setDriverClass(jdbcDriverClassNames.get(dbType)); @@ -176,7 +193,7 @@ DataSource createC3P0Ds(String dbType, String jdbcUrl) { return ds; } - DataSource createDs(String connectionPoolName, String dbType, String jdbcUrl) { + static DataSource createDs(String connectionPoolName, String dbType, String jdbcUrl) { DataSource ds = null; if (Objects.equals(connectionPoolName, "tomcat")) { ds = createTomcatDs(dbType, jdbcUrl); @@ -190,11 +207,11 @@ DataSource createDs(String connectionPoolName, String dbType, String jdbcUrl) { return ds; } - Stream basicStatementStream() throws SQLException { + static Stream basicStatementStream() throws SQLException { return Stream.of( Arguments.of( "h2", - new Driver().connect(jdbcUrls.get("h2"), null), + new org.h2.Driver().connect(jdbcUrls.get("h2"), null), null, "SELECT 3", "SELECT ?", @@ -221,7 +238,7 @@ Stream basicStatementStream() throws SQLException { "INFORMATION_SCHEMA.SYSTEM_USERS"), Arguments.of( "h2", - new Driver().connect(jdbcUrls.get("h2"), connectionProps), + new org.h2.Driver().connect(jdbcUrls.get("h2"), connectionProps), null, "SELECT 3", "SELECT ?", @@ -367,11 +384,1052 @@ public void testBasicStatement( val.satisfiesAnyOf( v -> assertThat(v).isEqualTo(username), v -> assertThat(v).isNull())), - equalTo(DbIncubatingAttributes.DB_CONNECTION_STRING, url), + equalTo(getDbConnectionStringKey(), url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); statement.close(); connection.close(); } + + static Stream preparedStatementStream() throws SQLException { + return Stream.of( + Arguments.of( + "h2", + new org.h2.Driver().connect(jdbcUrls.get("h2"), null), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + new EmbeddedDriver().connect(jdbcUrls.get("derby"), null), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "h2", + cpDatasources.get("tomcat").get("h2").getConnection(), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + cpDatasources.get("tomcat").get("derby").getConnection(), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "h2", + cpDatasources.get("hikari").get("h2").getConnection(), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + cpDatasources.get("hikari").get("derby").getConnection(), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + "h2", + cpDatasources.get("c3p0").get("h2").getConnection(), + null, + "SELECT 3", + "SELECT ?", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + "derby", + cpDatasources.get("c3p0").get("derby").getConnection(), + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1")); + } + + @ParameterizedTest + @MethodSource("preparedStatementStream") + @DisplayName( + "prepared statement execute on #system with #connection.getClass().getCanonicalName() generates a span") + void testPreparedStatementExecute( + String system, + Connection connection, + String username, + String query, + String sanitizedQuery, + String spanName, + String url, + String table) + throws SQLException { + PreparedStatement statement = connection.prepareStatement(query); + cleanup.deferCleanup(statement); + cleanup.deferCleanup(connection); + ResultSet resultSet = + testing.runWithSpan( + "parent", + () -> { + statement.execute(); + return statement.getResultSet(); + }); + + resultSet.next(); + assertThat(resultSet.getInt(1)).isEqualTo(3); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(username), + v -> assertThat(v).isNull())), + equalTo(getDbConnectionStringKey(), url), + equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), + equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); + } + + @ParameterizedTest + @MethodSource("preparedStatementStream") + @DisplayName( + "prepared statement query on #system with #connection.getClass().getCanonicalName() generates a span") + void testPreparedStatementQuery( + String system, + Connection connection, + String username, + String query, + String sanitizedQuery, + String spanName, + String url, + String table) + throws SQLException { + PreparedStatement statement = connection.prepareStatement(query); + cleanup.deferCleanup(statement); + cleanup.deferCleanup(connection); + ResultSet resultSet = testing.runWithSpan("parent", () -> statement.executeQuery()); + + resultSet.next(); + assertThat(resultSet.getInt(1)).isEqualTo(3); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(username), + v -> assertThat(v).isNull())), + equalTo(getDbConnectionStringKey(), url), + equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), + equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); + } + + @ParameterizedTest + @MethodSource("preparedStatementStream") + @DisplayName( + "prepared call on #system with #connection.getClass().getCanonicalName() generates a span") + void testPreparedCall( + String system, + Connection connection, + String username, + String query, + String sanitizedQuery, + String spanName, + String url, + String table) + throws SQLException { + CallableStatement statement = connection.prepareCall(query); + cleanup.deferCleanup(statement); + cleanup.deferCleanup(connection); + ResultSet resultSet = testing.runWithSpan("parent", () -> statement.executeQuery()); + + resultSet.next(); + assertThat(resultSet.getInt(1)).isEqualTo(3); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(username), + v -> assertThat(v).isNull())), + equalTo(getDbConnectionStringKey(), url), + equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), + equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); + } + + static Stream statementUpdateStream() throws SQLException { + return Stream.of( + Arguments.of( + "h2", + new org.h2.Driver().connect(jdbcUrls.get("h2"), null), + null, + "CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_H2", + "h2:mem:", + "S_H2"), + Arguments.of( + "derby", + new EmbeddedDriver().connect(jdbcUrls.get("derby"), null), + "APP", + "CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_DERBY", + "derby:memory:", + "S_DERBY"), + Arguments.of( + "hsqldb", + new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null), + "SA", + "CREATE TABLE PUBLIC.S_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE PUBLIC.S_HSQLDB", + "hsqldb:mem:", + "PUBLIC.S_HSQLDB"), + Arguments.of( + "h2", + cpDatasources.get("tomcat").get("h2").getConnection(), + null, + "CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_H2_TOMCAT", + "h2:mem:", + "S_H2_TOMCAT"), + Arguments.of( + "derby", + cpDatasources.get("tomcat").get("derby").getConnection(), + "APP", + "CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_DERBY_TOMCAT", + "derby:memory:", + "S_DERBY_TOMCAT"), + Arguments.of( + "hsqldb", + cpDatasources.get("tomcat").get("hsqldb").getConnection(), + "SA", + "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE PUBLIC.S_HSQLDB_TOMCAT", + "hsqldb:mem:", + "PUBLIC.S_HSQLDB_TOMCAT"), + Arguments.of( + "h2", + cpDatasources.get("hikari").get("h2").getConnection(), + null, + "CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_H2_HIKARI", + "h2:mem:", + "S_H2_HIKARI"), + Arguments.of( + "derby", + cpDatasources.get("hikari").get("derby").getConnection(), + "APP", + "CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_DERBY_HIKARI", + "derby:memory:", + "S_DERBY_HIKARI"), + Arguments.of( + "hsqldb", + cpDatasources.get("hikari").get("hsqldb").getConnection(), + "SA", + "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE PUBLIC.S_HSQLDB_HIKARI", + "hsqldb:mem:", + "PUBLIC.S_HSQLDB_HIKARI"), + Arguments.of( + "h2", + cpDatasources.get("c3p0").get("h2").getConnection(), + null, + "CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_H2_C3P0", + "h2:mem:", + "S_H2_C3P0"), + Arguments.of( + "derby", + cpDatasources.get("c3p0").get("derby").getConnection(), + "APP", + "CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.S_DERBY_C3P0", + "derby:memory:", + "S_DERBY_C3P0"), + Arguments.of( + "hsqldb", + cpDatasources.get("c3p0").get("hsqldb").getConnection(), + "SA", + "CREATE TABLE PUBLIC.S_HSQLDB_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE PUBLIC.S_HSQLDB_C3P0", + "hsqldb:mem:", + "PUBLIC.S_HSQLDB_C3P0")); + } + + @ParameterizedTest + @MethodSource("statementUpdateStream") + @DisplayName( + "statement update on #system with #connection.getClass().getCanonicalName() generates a span") + void testStatementUpdate( + String system, + Connection connection, + String username, + String query, + String spanName, + String url, + String table) + throws SQLException { + Statement statement = connection.createStatement(); + cleanup.deferCleanup(statement); + cleanup.deferCleanup(connection); + String sql = connection.nativeSQL(query); + testing.runWithSpan("parent", () -> statement.execute(sql)); + + assertThat(statement.getUpdateCount()).isEqualTo(0); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(username), + v -> assertThat(v).isNull())), + equalTo(getDbConnectionStringKey(), url), + equalTo(DbIncubatingAttributes.DB_STATEMENT, query), + equalTo(DbIncubatingAttributes.DB_OPERATION, "CREATE TABLE"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); + } + + static Stream preparedStatementUpdateStream() throws SQLException { + return Stream.of( + Arguments.of( + "h2", + new org.h2.Driver().connect(jdbcUrls.get("h2"), null), + null, + "CREATE TABLE PS_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_H2", + "h2:mem:", + "PS_H2"), + Arguments.of( + "derby", + new EmbeddedDriver().connect(jdbcUrls.get("derby"), null), + "APP", + "CREATE TABLE PS_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_DERBY", + "derby:memory:", + "PS_DERBY"), + Arguments.of( + "h2", + cpDatasources.get("tomcat").get("h2").getConnection(), + null, + "CREATE TABLE PS_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_H2_TOMCAT", + "h2:mem:", + "PS_H2_TOMCAT"), + Arguments.of( + "derby", + cpDatasources.get("tomcat").get("derby").getConnection(), + "APP", + "CREATE TABLE PS_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_DERBY_TOMCAT", + "derby:memory:", + "PS_DERBY_TOMCAT"), + Arguments.of( + "h2", + cpDatasources.get("hikari").get("h2").getConnection(), + null, + "CREATE TABLE PS_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_H2_HIKARI", + "h2:mem:", + "PS_H2_HIKARI"), + Arguments.of( + "derby", + cpDatasources.get("hikari").get("derby").getConnection(), + "APP", + "CREATE TABLE PS_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_DERBY_HIKARI", + "derby:memory:", + "PS_DERBY_HIKARI"), + Arguments.of( + "h2", + cpDatasources.get("c3p0").get("h2").getConnection(), + null, + "CREATE TABLE PS_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_H2_C3P0", + "h2:mem:", + "PS_H2_C3P0"), + Arguments.of( + "derby", + cpDatasources.get("c3p0").get("derby").getConnection(), + "APP", + "CREATE TABLE PS_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))", + "CREATE TABLE jdbcunittest.PS_DERBY_C3P0", + "derby:memory:", + "PS_DERBY_C3P0")); + } + + @ParameterizedTest + @MethodSource("preparedStatementUpdateStream") + @DisplayName( + "prepared statement update on #system with #connection.getClass().getCanonicalName() generates a span") + void testPreparedStatementUpdate( + String system, + Connection connection, + String username, + String query, + String spanName, + String url, + String table) + throws SQLException { + String sql = connection.nativeSQL(query); + PreparedStatement statement = connection.prepareStatement(sql); + cleanup.deferCleanup(statement); + cleanup.deferCleanup(connection); + testing.runWithSpan("parent", () -> statement.executeUpdate() == 0); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(username), + v -> assertThat(v).isNull())), + equalTo(getDbConnectionStringKey(), url), + equalTo(DbIncubatingAttributes.DB_STATEMENT, query), + equalTo(DbIncubatingAttributes.DB_OPERATION, "CREATE TABLE"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); + } + + static Stream connectionConstructorStream() { + return Stream.of( + Arguments.of( + true, + "h2", + new org.h2.Driver(), + "jdbc:h2:mem:" + dbName, + null, + "SELECT 3;", + "SELECT ?;", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + true, + "derby", + new EmbeddedDriver(), + "jdbc:derby:memory:" + dbName + ";create=true", + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1"), + Arguments.of( + false, + "h2", + new org.h2.Driver(), + "jdbc:h2:mem:" + dbName, + null, + "SELECT 3;", + "SELECT ?;", + "SELECT " + dbNameLower, + "h2:mem:", + null), + Arguments.of( + false, + "derby", + new EmbeddedDriver(), + "jdbc:derby:memory:" + dbName + ";create=true", + "APP", + "SELECT 3 FROM SYSIBM.SYSDUMMY1", + "SELECT ? FROM SYSIBM.SYSDUMMY1", + "SELECT SYSIBM.SYSDUMMY1", + "derby:memory:", + "SYSIBM.SYSDUMMY1")); + } + + @SuppressWarnings("CatchingUnchecked") + @ParameterizedTest + @MethodSource("connectionConstructorStream") + @DisplayName( + "connection constructor throwing then generating correct spans after recovery using #driver connection (prepare statement = #prepareStatement)") + void testConnectionConstructorThrowing( + boolean prepareStatement, + String system, + Driver driver, + String jdbcUrl, + String username, + String query, + String sanitizedQuery, + String spanName, + String url, + String table) + throws SQLException { + Connection connection = null; + + try { + connection = new TestConnection(true); + } catch (Exception ignored) { + connection = driver.connect(jdbcUrl, null); + } + cleanup.deferCleanup(connection); + Connection finalConnection = connection; + ResultSet rs = + testing.runWithSpan( + "parent", + () -> { + if (prepareStatement) { + PreparedStatement stmt = finalConnection.prepareStatement(query); + cleanup.deferCleanup(stmt); + return stmt.executeQuery(); + } else { + Statement stmt = finalConnection.createStatement(); + cleanup.deferCleanup(stmt); + return stmt.executeQuery(query); + } + }); + + rs.next(); + assertThat(rs.getInt(1)).isEqualTo(3); + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(username), + v -> assertThat(v).isNull())), + equalTo(getDbConnectionStringKey(), url), + equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), + equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); + } + + static Stream getConnectionStream() { + return Stream.of( + Arguments.of( + (Supplier) () -> new JdbcDataSource(), + (Consumer) ds -> ((JdbcDataSource) ds).setUrl(jdbcUrls.get("h2")), + "h2", + null, + "h2:mem:"), + Arguments.of( + (Supplier) () -> new EmbeddedDataSource(), + (Consumer) + ds -> ((EmbeddedDataSource) ds).setDatabaseName("memory:" + dbName), + "derby", + "APP", + "derby:memory:"), + Arguments.of( + (Supplier) () -> cpDatasources.get("hikari").get("h2"), + null, + "h2", + null, + "h2:mem:"), + Arguments.of( + (Supplier) () -> cpDatasources.get("hikari").get("derby"), + null, + "derby", + "APP", + "derby:memory:"), + Arguments.of( + (Supplier) () -> cpDatasources.get("c3p0").get("h2"), + null, + "h2", + null, + "h2:mem:"), + Arguments.of( + (Supplier) () -> cpDatasources.get("c3p0").get("derby"), + null, + "derby", + "APP", + "derby:memory:")); + } + + @ParameterizedTest + @MethodSource("getConnectionStream") + @DisplayName( + "calling #datasource.class.simpleName getConnection generates a span when under existing trace") + void testGetConnection( + // if the parameter is Datasource which is implement Closeable, junit will close the ds in + // cpDatasources + // other test case will fail. So this is a workaround + Supplier datasourceSupplier, + Consumer init, + String system, + String user, + String connectionString) + throws SQLException { + DataSource datasource = datasourceSupplier.get(); + // Tomcat's pool doesn't work because the getConnection method is + // implemented in a parent class that doesn't implement DataSource + boolean recursive = datasource instanceof EmbeddedDataSource; + + if (init != null) { + init.accept(datasource); + } + datasource.getConnection().close(); + + testing.clearData(); + + testing.runWithSpan( + "parent", + () -> { + datasource.getConnection().close(); + }); + if (recursive) { + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(datasource.getClass().getSimpleName() + ".getConnection") + .hasKind(SpanKind.INTERNAL) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + datasource.getClass().getName()), + equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(user), + v -> assertThat(v).isNull())), + equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), + equalTo(getDbConnectionStringKey(), connectionString)), + span -> + span.hasName(datasource.getClass().getSimpleName() + ".getConnection") + .hasKind(SpanKind.INTERNAL) + .hasParent(trace.getSpan(1)) + .hasAttributesSatisfying( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + datasource.getClass().getName()), + equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(user), + v -> assertThat(v).isNull())), + equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), + equalTo(getDbConnectionStringKey(), connectionString)))); + } else { + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(datasource.getClass().getSimpleName() + ".getConnection") + .hasKind(SpanKind.INTERNAL) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + datasource.getClass().getName()), + equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(user), + v -> assertThat(v).isNull())), + equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), + equalTo(getDbConnectionStringKey(), connectionString)))); + } + } + + @SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation + AttributeKey getDbConnectionStringKey() { + return DbIncubatingAttributes.DB_CONNECTION_STRING; + } + + @ParameterizedTest + @DisplayName("test getClientInfo exception") + @ValueSource(strings = "testing 123") + void testGetClientInfoException(String query) throws SQLException { + TestConnection connection = new TestConnection(false); + cleanup.deferCleanup(connection); + connection.setUrl("jdbc:testdb://localhost"); + + Statement statement = + testing.runWithSpan( + "parent", + () -> { + Statement stmt = connection.createStatement(); + stmt.executeQuery(query); + return stmt; + }); + cleanup.deferCleanup(statement); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName("DB Query") + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, "other_sql"), + equalTo(DbIncubatingAttributes.DB_STATEMENT, "testing ?"), + equalTo(getDbConnectionStringKey(), "testdb://localhost"), + equalTo(ServerAttributes.SERVER_ADDRESS, "localhost")))); + } + + static Stream spanNameStream() { + return Stream.of( + Arguments.of( + "jdbc:testdb://localhost?databaseName=test", + "SELECT * FROM table", + "SELECT * FROM table", + "SELECT test.table", + "test", + "SELECT", + "table"), + Arguments.of( + "jdbc:testdb://localhost?databaseName=test", + "SELECT 42", + "SELECT ?", + "SELECT test", + "test", + "SELECT", + null), + Arguments.of( + "jdbc:testdb://localhost", + "SELECT * FROM table", + "SELECT * FROM table", + "SELECT table", + null, + "SELECT", + "table"), + Arguments.of( + "jdbc:testdb://localhost?databaseName=test", + "CREATE TABLE table", + "CREATE TABLE table", + "CREATE TABLE test.table", + "test", + "CREATE TABLE", + "table"), + Arguments.of( + "jdbc:testdb://localhost", + "CREATE TABLE table", + "CREATE TABLE table", + "CREATE TABLE table", + null, + "CREATE TABLE", + "table")); + } + + @ParameterizedTest + @DisplayName("should produce proper span name #spanName") + @MethodSource("spanNameStream") + void testProduceProperSpanName( + String url, + String query, + String sanitizedQuery, + String spanName, + String databaseName, + String operation, + String table) + throws SQLException { + Driver driver = new TestDriver(); + Connection connection = driver.connect(url, null); + cleanup.deferCleanup(connection); + + testing.runWithSpan( + "parent", + () -> { + Statement statement = connection.createStatement(); + statement.executeQuery(query); + }); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName(spanName) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, "other_sql"), + equalTo(DbIncubatingAttributes.DB_NAME, databaseName), + equalTo(getDbConnectionStringKey(), "testdb://localhost"), + equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), + equalTo(DbIncubatingAttributes.DB_OPERATION, operation), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table), + equalTo(ServerAttributes.SERVER_ADDRESS, "localhost")))); + } + + @ParameterizedTest + @ValueSource(strings = {"hikari", "tomcat", "c3p0"}) + @DisplayName("#connectionPoolName connections should be cached in case of wrapped connections") + void testConnectionCached(String connectionPoolName) throws SQLException { + String dbType = "hsqldb"; + DataSource ds = createDs(connectionPoolName, dbType, jdbcUrls.get(dbType)); + cleanup.deferCleanup( + () -> { + if (ds instanceof Closeable) { + ((Closeable) ds).close(); + } + }); + String query = "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"; + int numQueries = 5; + int[] res = new int[numQueries]; + + for (int i = 0; i < numQueries; ++i) { + try (Connection connection = ds.getConnection(); + PreparedStatement statement = connection.prepareStatement(query)) { + ResultSet rs = statement.executeQuery(); + if (rs.next()) { + res[i] = rs.getInt(1); + } else { + res[i] = 0; + } + } + } + + for (int i = 0; i < numQueries; ++i) { + assertThat(res[i]).isEqualTo(3); + } + + List> assertions = new ArrayList<>(); + Consumer traceAssertConsumer = + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("SELECT INFORMATION_SCHEMA.SYSTEM_USERS") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, "hsqldb"), + equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), + equalTo(DbIncubatingAttributes.DB_USER, "SA"), + equalTo(getDbConnectionStringKey(), "hsqldb:mem:"), + equalTo( + DbIncubatingAttributes.DB_STATEMENT, + "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS"), + equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + equalTo( + DbIncubatingAttributes.DB_SQL_TABLE, + "INFORMATION_SCHEMA.SYSTEM_USERS"))); + for (int i = 0; i < numQueries; i++) { + assertions.add(traceAssertConsumer); + } + + testing.waitAndAssertTraces(assertions); + } + + @FunctionalInterface + public interface ThrowingBiConsumer { + void accept(T t, U u) throws Exception; + } + + static Stream recursiveStatementsStream() { + return Stream.of( + Arguments.of( + "getMetaData() uses Statement, test Statement", + false, + (ThrowingBiConsumer) + (con, query) -> con.createStatement().executeQuery(query)), + Arguments.of( + "getMetaData() uses PreparedStatement, test Statement", + true, + (ThrowingBiConsumer) + (con, query) -> con.createStatement().executeQuery(query)), + Arguments.of( + "getMetaData() uses Statement, test PreparedStatement", + false, + (ThrowingBiConsumer) + (con, query) -> con.prepareStatement(query).executeQuery()), + Arguments.of( + "getMetaData() uses PreparedStatement, test PreparedStatement", + true, + (ThrowingBiConsumer) + (con, query) -> con.prepareStatement(query).executeQuery())); + } + + // regression test for + // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/2644 + @ParameterizedTest + @DisplayName("should handle recursive Statements inside Connection.getMetaData(): #desc") + @MethodSource("recursiveStatementsStream") + void testHandleRecursiveStatements( + String desc, + boolean usePreparedStatementInConnection, + ThrowingBiConsumer executeQueryFunction) + throws Exception { + DbCallingConnection connection = new DbCallingConnection(usePreparedStatementInConnection); + connection.setUrl("jdbc:testdb://localhost"); + + testing.runWithSpan( + "parent", + () -> { + executeQueryFunction.accept(connection, "SELECT * FROM table"); + }); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName("SELECT table") + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo(DbIncubatingAttributes.DB_SYSTEM, "other_sql"), + equalTo(getDbConnectionStringKey(), "testdb://localhost"), + equalTo(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"), + equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), + equalTo(DbIncubatingAttributes.DB_SQL_TABLE, "table"), + equalTo(ServerAttributes.SERVER_ADDRESS, "localhost")))); + } + + static class DbCallingConnection extends TestConnection { + final boolean usePreparedStatement; + + DbCallingConnection(boolean usePreparedStatement) { + super(false); + this.usePreparedStatement = usePreparedStatement; + } + + @Override + public DatabaseMetaData getMetaData() throws SQLException { + // simulate retrieving DB metadata from the DB itself + if (usePreparedStatement) { + prepareStatement("SELECT * from DB_METADATA").executeQuery(); + } else { + createStatement().executeQuery("SELECT * from DB_METADATA"); + } + return super.getMetaData(); + } + } + + // regression test for + // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/6015 + @DisplayName("test proxy statement") + @Test + void testProxyStatement() throws Exception { + Connection connection = new org.h2.Driver().connect(jdbcUrls.get("h2"), null); + Statement statement = connection.createStatement(); + cleanup.deferCleanup(statement); + cleanup.deferCleanup(connection); + + Statement proxyStatement = ProxyStatementFactory.proxyStatement(statement); + ResultSet resultSet = + testing.runWithSpan("parent", () -> proxyStatement.executeQuery("SELECT 3")); + + resultSet.next(); + assertThat(resultSet.getInt(1)).isEqualTo(3); + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName("SELECT " + dbNameLower) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)))); + } + + // regression test for + // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/9359 + @DisplayName("test proxy prepared statement") + @Test + void testProxyPreparedStatement() throws SQLException { + Connection connection = new org.h2.Driver().connect(jdbcUrls.get("h2"), null); + PreparedStatement statement = connection.prepareStatement("SELECT 3"); + cleanup.deferCleanup(statement); + cleanup.deferCleanup(connection); + + PreparedStatement proxyStatement = ProxyStatementFactory.proxyPreparedStatement(statement); + ResultSet resultSet = testing.runWithSpan("parent", () -> proxyStatement.executeQuery()); + + resultSet.next(); + assertThat(resultSet.getInt(1)).isEqualTo(3); + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span -> + span.hasName("SELECT " + dbNameLower) + .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)))); + } } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java index 443f3529d002..6ee3d1f5d91e 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java @@ -282,7 +282,7 @@ public void setTransactionIsolation(int level) throws SQLException {} @Override public void setTypeMap(Map> map) throws SQLException {} - void setUrl(String url) { + public void setUrl(String url) { this.url = url; } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java index 05032de7be47..dd0e185dff3f 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDriver.java @@ -13,7 +13,7 @@ import java.util.Properties; import java.util.logging.Logger; -class TestDriver implements Driver { +public class TestDriver implements Driver { @Override public Connection connect(String url, Properties info) throws SQLException { return new TestConnection(); From 8399e927506b9a4ec513de2fc4c9f5a4ddcd7731 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Fri, 6 Sep 2024 18:00:34 +0800 Subject: [PATCH 04/11] fix ut --- .../jdbc/test/JdbcInstrumentationTest.java | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index 4cc4e48f6fdd..6159beeda324 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -45,7 +45,6 @@ import java.util.Objects; import java.util.Properties; import java.util.function.Consumer; -import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.sql.DataSource; @@ -980,59 +979,37 @@ void testConnectionConstructorThrowing( static Stream getConnectionStream() { return Stream.of( Arguments.of( - (Supplier) () -> new JdbcDataSource(), + new JdbcDataSource(), (Consumer) ds -> ((JdbcDataSource) ds).setUrl(jdbcUrls.get("h2")), "h2", null, "h2:mem:"), Arguments.of( - (Supplier) () -> new EmbeddedDataSource(), + new EmbeddedDataSource(), (Consumer) ds -> ((EmbeddedDataSource) ds).setDatabaseName("memory:" + dbName), "derby", "APP", "derby:memory:"), + Arguments.of(cpDatasources.get("hikari").get("h2"), null, "h2", null, "h2:mem:"), Arguments.of( - (Supplier) () -> cpDatasources.get("hikari").get("h2"), - null, - "h2", - null, - "h2:mem:"), - Arguments.of( - (Supplier) () -> cpDatasources.get("hikari").get("derby"), - null, - "derby", - "APP", - "derby:memory:"), + cpDatasources.get("hikari").get("derby"), null, "derby", "APP", "derby:memory:"), + Arguments.of(cpDatasources.get("c3p0").get("h2"), null, "h2", null, "h2:mem:"), Arguments.of( - (Supplier) () -> cpDatasources.get("c3p0").get("h2"), - null, - "h2", - null, - "h2:mem:"), - Arguments.of( - (Supplier) () -> cpDatasources.get("c3p0").get("derby"), - null, - "derby", - "APP", - "derby:memory:")); + cpDatasources.get("c3p0").get("derby"), null, "derby", "APP", "derby:memory:")); } - @ParameterizedTest + @ParameterizedTest(autoCloseArguments = false) @MethodSource("getConnectionStream") @DisplayName( "calling #datasource.class.simpleName getConnection generates a span when under existing trace") void testGetConnection( - // if the parameter is Datasource which is implement Closeable, junit will close the ds in - // cpDatasources - // other test case will fail. So this is a workaround - Supplier datasourceSupplier, + DataSource datasource, Consumer init, String system, String user, String connectionString) throws SQLException { - DataSource datasource = datasourceSupplier.get(); // Tomcat's pool doesn't work because the getConnection method is // implemented in a parent class that doesn't implement DataSource boolean recursive = datasource instanceof EmbeddedDataSource; From f02b3e695a6c39f61571a9062bba87bfd4d0b445 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Tue, 10 Sep 2024 14:13:00 +0800 Subject: [PATCH 05/11] fix ut --- .../jdbc/test/JdbcInstrumentationTest.java | 27 ++++++++----------- .../instrumentation/jdbc/TestConnection.java | 1 - .../jdbc/TestDatabaseMetaData.java | 1 - 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index 6159beeda324..92a46a24238b 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -9,8 +9,8 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; +import com.google.common.collect.ImmutableMap; import com.mchange.v2.c3p0.ComboPooledDataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -37,7 +37,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -45,7 +44,6 @@ import java.util.Objects; import java.util.Properties; import java.util.function.Consumer; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.sql.DataSource; import org.apache.derby.jdbc.EmbeddedDataSource; @@ -83,20 +81,16 @@ static void setUp() { dbName = "jdbcUnitTest"; dbNameLower = dbName.toLowerCase(Locale.ROOT); jdbcUrls = - Collections.unmodifiableMap( - Stream.of( - entry("h2", "jdbc:h2:mem:" + dbName), - entry("derby", "jdbc:derby:memory:" + dbName), - entry("hsqldb", "jdbc:hsqldb:mem:" + dbName)) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + ImmutableMap.of( + "h2", "jdbc:h2:mem:" + dbName, + "derby", "jdbc:derby:memory:" + dbName, + "hsqldb", "jdbc:hsqldb:mem:" + dbName); jdbcDriverClassNames = - Collections.unmodifiableMap( - Stream.of( - entry("h2", "org.h2.Driver"), - entry("derby", "org.apache.derby.jdbc.EmbeddedDriver"), - entry("hsqldb", "org.hsqldb.jdbc.JDBCDriver")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + ImmutableMap.of( + "h2", "org.h2.Driver", + "derby", "org.apache.derby.jdbc.EmbeddedDriver", + "hsqldb", "org.hsqldb.jdbc.JDBCDriver"); jdbcUserNames = new HashMap<>(); jdbcUserNames.put("derby", "APP"); @@ -345,7 +339,6 @@ static Stream basicStatementStream() throws SQLException { "INFORMATION_SCHEMA.SYSTEM_USERS")); } - @SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation @DisplayName( "basic statement with #connection.getClass().getCanonicalName() on #system generates spans") @ParameterizedTest @@ -1018,6 +1011,8 @@ void testGetConnection( init.accept(datasource); } datasource.getConnection().close(); + assertThat(testing.spans()) + .noneMatch(span -> Objects.equals(span.getName(), "database.connection")); testing.clearData(); diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java index 6ee3d1f5d91e..6230bcbecdc0 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestConnection.java @@ -115,7 +115,6 @@ public String getClientInfo(String name) throws SQLException { @Override public Properties getClientInfo() throws SQLException { - // TODO throwable throw new UnsupportedOperationException("Test 123"); } diff --git a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java index 721e5e060d51..0494a212a04e 100644 --- a/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java +++ b/instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/TestDatabaseMetaData.java @@ -59,7 +59,6 @@ public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { @Override public boolean generatedKeyAlwaysReturned() throws SQLException { - ; return false; } From 5c7af8cdb41f5f4b7b290c7c1adea25f729e8ba1 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Tue, 10 Sep 2024 17:02:24 +0800 Subject: [PATCH 06/11] Apply suggestions from code review Co-authored-by: Jay DeLuca --- .../instrumentation/jdbc/test/JdbcInstrumentationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index 92a46a24238b..b1aed176b771 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -62,10 +62,10 @@ class JdbcInstrumentationTest { - @RegisterExtension static AutoCleanupExtension cleanup = AutoCleanupExtension.create(); + @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); @RegisterExtension - static InstrumentationExtension testing = AgentInstrumentationExtension.create(); + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); private static String dbName; private static String dbNameLower; From 6b8fa6e7fb560b5391af0dc249976a5b4fd7f7cc Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Thu, 12 Sep 2024 21:07:14 +0800 Subject: [PATCH 07/11] refine ut --- .../jdbc/test/JdbcInstrumentationTest.java | 122 ++++++++---------- 1 file changed, 51 insertions(+), 71 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index b1aed176b771..1c236f3b3cd8 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -21,6 +21,7 @@ import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.sdk.testing.assertj.TraceAssert; import io.opentelemetry.semconv.ServerAttributes; import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes; @@ -37,6 +38,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -1011,81 +1013,59 @@ void testGetConnection( init.accept(datasource); } datasource.getConnection().close(); - assertThat(testing.spans()) - .noneMatch(span -> Objects.equals(span.getName(), "database.connection")); + assertThat(testing.spans()).noneMatch(span -> span.getName().equals("database.connection")); testing.clearData(); - testing.runWithSpan( - "parent", - () -> { - datasource.getConnection().close(); + testing.runWithSpan("parent", () -> datasource.getConnection().close()); + testing.waitAndAssertTraces( + trace -> { + List> assertions = + new ArrayList<>( + Arrays.asList( + span1 -> span1.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), + span1 -> + span1 + .hasName(datasource.getClass().getSimpleName() + ".getConnection") + .hasKind(SpanKind.INTERNAL) + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfying( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + datasource.getClass().getName()), + equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + satisfies( + DbIncubatingAttributes.DB_USER, + val1 -> + val1.satisfiesAnyOf( + v1 -> assertThat(v1).isEqualTo(user), + v1 -> assertThat(v1).isNull())), + equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), + equalTo(getDbConnectionStringKey(), connectionString)))); + if (recursive) { + assertions.add( + span -> + span.hasName(datasource.getClass().getSimpleName() + ".getConnection") + .hasKind(SpanKind.INTERNAL) + .hasParent(trace.getSpan(1)) + .hasAttributesSatisfying( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + datasource.getClass().getName()), + equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), + equalTo(DbIncubatingAttributes.DB_SYSTEM, system), + satisfies( + DbIncubatingAttributes.DB_USER, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(user), + v -> assertThat(v).isNull())), + equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), + equalTo(getDbConnectionStringKey(), connectionString))); + } + trace.hasSpansSatisfyingExactly(assertions); }); - if (recursive) { - testing.waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), - span -> - span.hasName(datasource.getClass().getSimpleName() + ".getConnection") - .hasKind(SpanKind.INTERNAL) - .hasParent(trace.getSpan(0)) - .hasAttributesSatisfying( - equalTo( - CodeIncubatingAttributes.CODE_NAMESPACE, - datasource.getClass().getName()), - equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), - equalTo(DbIncubatingAttributes.DB_SYSTEM, system), - satisfies( - DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(user), - v -> assertThat(v).isNull())), - equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), - equalTo(getDbConnectionStringKey(), connectionString)), - span -> - span.hasName(datasource.getClass().getSimpleName() + ".getConnection") - .hasKind(SpanKind.INTERNAL) - .hasParent(trace.getSpan(1)) - .hasAttributesSatisfying( - equalTo( - CodeIncubatingAttributes.CODE_NAMESPACE, - datasource.getClass().getName()), - equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), - equalTo(DbIncubatingAttributes.DB_SYSTEM, system), - satisfies( - DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(user), - v -> assertThat(v).isNull())), - equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), - equalTo(getDbConnectionStringKey(), connectionString)))); - } else { - testing.waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), - span -> - span.hasName(datasource.getClass().getSimpleName() + ".getConnection") - .hasKind(SpanKind.INTERNAL) - .hasParent(trace.getSpan(0)) - .hasAttributesSatisfying( - equalTo( - CodeIncubatingAttributes.CODE_NAMESPACE, - datasource.getClass().getName()), - equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "getConnection"), - equalTo(DbIncubatingAttributes.DB_SYSTEM, system), - satisfies( - DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(user), - v -> assertThat(v).isNull())), - equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), - equalTo(getDbConnectionStringKey(), connectionString)))); - } } @SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation From 11eea16b969784d2a250145a611bbcf3b144d989 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Fri, 13 Sep 2024 19:22:30 +0800 Subject: [PATCH 08/11] Apply suggestions from code review Co-authored-by: Jay DeLuca --- .../jdbc/test/JdbcInstrumentationTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index 1c236f3b3cd8..e7933d00658d 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -140,7 +140,7 @@ static void prepareConnectionPoolDatasources() { static DataSource createTomcatDs(String dbType, String jdbcUrl) { org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(); - String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; + String jdbcUrlToSet = dbType.equals("derby") ? jdbcUrl + ";create=true" : jdbcUrl; ds.setUrl(jdbcUrlToSet); ds.setDriverClassName(jdbcDriverClassNames.get(dbType)); String username = jdbcUserNames.get(dbType); @@ -155,7 +155,7 @@ static DataSource createTomcatDs(String dbType, String jdbcUrl) { static DataSource createHikariDs(String dbType, String jdbcUrl) { HikariConfig config = new HikariConfig(); - String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; + String jdbcUrlToSet = dbType.equals("derby") ? jdbcUrl + ";create=true" : jdbcUrl; config.setJdbcUrl(jdbcUrlToSet); String username = jdbcUserNames.get(dbType); if (username != null) { @@ -177,7 +177,7 @@ static DataSource createC3P0Ds(String dbType, String jdbcUrl) { } catch (PropertyVetoException e) { throw new RuntimeException(e); } - String jdbcUrlToSet = Objects.equals(dbType, "derby") ? jdbcUrl + ";create=true" : jdbcUrl; + String jdbcUrlToSet = dbType.equals("derby") ? jdbcUrl + ";create=true" : jdbcUrl; ds.setJdbcUrl(jdbcUrlToSet); String username = jdbcUserNames.get(dbType); if (username != null) { @@ -190,13 +190,13 @@ static DataSource createC3P0Ds(String dbType, String jdbcUrl) { static DataSource createDs(String connectionPoolName, String dbType, String jdbcUrl) { DataSource ds = null; - if (Objects.equals(connectionPoolName, "tomcat")) { + if (connectionPoolName.equals("tomcat")) { ds = createTomcatDs(dbType, jdbcUrl); } - if (Objects.equals(connectionPoolName, "hikari")) { + if (connectionPoolName.equals("hikari")) { ds = createHikariDs(dbType, jdbcUrl); } - if (Objects.equals(connectionPoolName, "c3p0")) { + if (connectionPoolName.equals("c3p0")) { ds = createC3P0Ds(dbType, jdbcUrl); } return ds; @@ -720,7 +720,7 @@ void testStatementUpdate( cleanup.deferCleanup(statement); cleanup.deferCleanup(connection); String sql = connection.nativeSQL(query); - testing.runWithSpan("parent", () -> statement.execute(sql)); + testing.runWithSpan("parent", () -> assertThat(statement.execute(sql)).isFalse()); assertThat(statement.getUpdateCount()).isEqualTo(0); @@ -832,7 +832,7 @@ void testPreparedStatementUpdate( PreparedStatement statement = connection.prepareStatement(sql); cleanup.deferCleanup(statement); cleanup.deferCleanup(connection); - testing.runWithSpan("parent", () -> statement.executeUpdate() == 0); + testing.runWithSpan("parent", () -> assertThat(statement.executeUpdate()).isEqualTo(0)); testing.waitAndAssertTraces( trace -> From 635484d1b93a0a993474a6b3d02640c642add288 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Fri, 13 Sep 2024 20:08:50 +0800 Subject: [PATCH 09/11] up level nested class --- .../jdbc/test/DbCallingConnection.java | 30 +++++++++++++++++++ .../jdbc/test/JdbcInstrumentationTest.java | 22 -------------- 2 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/DbCallingConnection.java diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/DbCallingConnection.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/DbCallingConnection.java new file mode 100644 index 000000000000..356199e5c76b --- /dev/null +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/DbCallingConnection.java @@ -0,0 +1,30 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jdbc.test; + +import io.opentelemetry.instrumentation.jdbc.TestConnection; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + +class DbCallingConnection extends TestConnection { + final boolean usePreparedStatement; + + DbCallingConnection(boolean usePreparedStatement) { + super(false); + this.usePreparedStatement = usePreparedStatement; + } + + @Override + public DatabaseMetaData getMetaData() throws SQLException { + // simulate retrieving DB metadata from the DB itself + if (usePreparedStatement) { + prepareStatement("SELECT * from DB_METADATA").executeQuery(); + } else { + createStatement().executeQuery("SELECT * from DB_METADATA"); + } + return super.getMetaData(); + } +} diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index e7933d00658d..85e099c60b74 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -31,7 +31,6 @@ import java.io.IOException; import java.sql.CallableStatement; import java.sql.Connection; -import java.sql.DatabaseMetaData; import java.sql.Driver; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -43,7 +42,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Objects; import java.util.Properties; import java.util.function.Consumer; import java.util.stream.Stream; @@ -1314,26 +1312,6 @@ void testHandleRecursiveStatements( equalTo(ServerAttributes.SERVER_ADDRESS, "localhost")))); } - static class DbCallingConnection extends TestConnection { - final boolean usePreparedStatement; - - DbCallingConnection(boolean usePreparedStatement) { - super(false); - this.usePreparedStatement = usePreparedStatement; - } - - @Override - public DatabaseMetaData getMetaData() throws SQLException { - // simulate retrieving DB metadata from the DB itself - if (usePreparedStatement) { - prepareStatement("SELECT * from DB_METADATA").executeQuery(); - } else { - createStatement().executeQuery("SELECT * from DB_METADATA"); - } - return super.getMetaData(); - } - } - // regression test for // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/6015 @DisplayName("test proxy statement") From 50fddfdce01c5b96d4c9dbbf53e2755691376a1d Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 23 Sep 2024 16:33:53 +0800 Subject: [PATCH 10/11] update jdbc ut --- .../jdbc/test/JdbcInstrumentationTest.java | 103 ++++++++---------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index 85e099c60b74..06358057d8d1 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -11,6 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import com.mchange.v2.c3p0.ComboPooledDataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -67,42 +68,38 @@ class JdbcInstrumentationTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); - private static String dbName; - private static String dbNameLower; - private static Map jdbcUrls; - private static Map jdbcDriverClassNames; - private static Map jdbcUserNames; - private static Properties connectionProps; + @SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation + static final AttributeKey DB_CONNECTION_STRING = + DbIncubatingAttributes.DB_CONNECTION_STRING; + + private static final String dbName = "jdbcUnitTest"; + private static final String dbNameLower = dbName.toLowerCase(Locale.ROOT); + private static final Map jdbcUrls = + ImmutableMap.of( + "h2", "jdbc:h2:mem:" + dbName, + "derby", "jdbc:derby:memory:" + dbName, + "hsqldb", "jdbc:hsqldb:mem:" + dbName); + private static final Map jdbcDriverClassNames = + ImmutableMap.of( + "h2", "org.h2.Driver", + "derby", "org.apache.derby.jdbc.EmbeddedDriver", + "hsqldb", "org.hsqldb.jdbc.JDBCDriver"); + private static final Map jdbcUserNames = Maps.newHashMap(); + private static final Properties connectionProps = new Properties(); // JDBC Connection pool name (i.e. HikariCP) -> Map - private static Map> cpDatasources; + private static final Map> cpDatasources = Maps.newHashMap(); - @BeforeAll - static void setUp() { - dbName = "jdbcUnitTest"; - dbNameLower = dbName.toLowerCase(Locale.ROOT); - jdbcUrls = - ImmutableMap.of( - "h2", "jdbc:h2:mem:" + dbName, - "derby", "jdbc:derby:memory:" + dbName, - "hsqldb", "jdbc:hsqldb:mem:" + dbName); - - jdbcDriverClassNames = - ImmutableMap.of( - "h2", "org.h2.Driver", - "derby", "org.apache.derby.jdbc.EmbeddedDriver", - "hsqldb", "org.hsqldb.jdbc.JDBCDriver"); - - jdbcUserNames = new HashMap<>(); + static { jdbcUserNames.put("derby", "APP"); jdbcUserNames.put("h2", null); jdbcUserNames.put("hsqldb", "SA"); - connectionProps = new Properties(); connectionProps.put("databaseName", "someDb"); connectionProps.put("OPEN_NEW", "true"); // So H2 doesn't complain about username/password. + } - cpDatasources = new HashMap<>(); - + @BeforeAll + static void setUp() { prepareConnectionPoolDatasources(); } @@ -354,6 +351,7 @@ public void testBasicStatement( String table) throws SQLException { Statement statement = connection.createStatement(); + cleanup.deferCleanup(statement); ResultSet resultSet = testing.runWithSpan("parent", () -> statement.executeQuery(query)); resultSet.next(); @@ -376,12 +374,10 @@ public void testBasicStatement( val.satisfiesAnyOf( v -> assertThat(v).isEqualTo(username), v -> assertThat(v).isNull())), - equalTo(getDbConnectionStringKey(), url), + equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); - statement.close(); - connection.close(); } static Stream preparedStatementStream() throws SQLException { @@ -505,7 +501,7 @@ void testPreparedStatementExecute( val.satisfiesAnyOf( v -> assertThat(v).isEqualTo(username), v -> assertThat(v).isNull())), - equalTo(getDbConnectionStringKey(), url), + equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); @@ -550,7 +546,7 @@ void testPreparedStatementQuery( val.satisfiesAnyOf( v -> assertThat(v).isEqualTo(username), v -> assertThat(v).isNull())), - equalTo(getDbConnectionStringKey(), url), + equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); @@ -595,7 +591,7 @@ void testPreparedCall( val.satisfiesAnyOf( v -> assertThat(v).isEqualTo(username), v -> assertThat(v).isNull())), - equalTo(getDbConnectionStringKey(), url), + equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); @@ -739,7 +735,7 @@ void testStatementUpdate( val.satisfiesAnyOf( v -> assertThat(v).isEqualTo(username), v -> assertThat(v).isNull())), - equalTo(getDbConnectionStringKey(), url), + equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, query), equalTo(DbIncubatingAttributes.DB_OPERATION, "CREATE TABLE"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); @@ -845,11 +841,12 @@ void testPreparedStatementUpdate( equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(username), - v -> assertThat(v).isNull())), - equalTo(getDbConnectionStringKey(), url), + val -> { + if (username != null) { + val.isEqualTo(username); + } + }), + equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, query), equalTo(DbIncubatingAttributes.DB_OPERATION, "CREATE TABLE"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); @@ -959,11 +956,12 @@ void testConnectionConstructorThrowing( equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(username), - v -> assertThat(v).isNull())), - equalTo(getDbConnectionStringKey(), url), + val -> { + if (username != null) { + val.isEqualTo(username); + } + }), + equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table)))); @@ -1040,7 +1038,7 @@ void testGetConnection( v1 -> assertThat(v1).isEqualTo(user), v1 -> assertThat(v1).isNull())), equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), - equalTo(getDbConnectionStringKey(), connectionString)))); + equalTo(DB_CONNECTION_STRING, connectionString)))); if (recursive) { assertions.add( span -> @@ -1060,17 +1058,12 @@ void testGetConnection( v -> assertThat(v).isEqualTo(user), v -> assertThat(v).isNull())), equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), - equalTo(getDbConnectionStringKey(), connectionString))); + equalTo(DB_CONNECTION_STRING, connectionString))); } trace.hasSpansSatisfyingExactly(assertions); }); } - @SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation - AttributeKey getDbConnectionStringKey() { - return DbIncubatingAttributes.DB_CONNECTION_STRING; - } - @ParameterizedTest @DisplayName("test getClientInfo exception") @ValueSource(strings = "testing 123") @@ -1100,7 +1093,7 @@ void testGetClientInfoException(String query) throws SQLException { .hasAttributesSatisfying( equalTo(DbIncubatingAttributes.DB_SYSTEM, "other_sql"), equalTo(DbIncubatingAttributes.DB_STATEMENT, "testing ?"), - equalTo(getDbConnectionStringKey(), "testdb://localhost"), + equalTo(DB_CONNECTION_STRING, "testdb://localhost"), equalTo(ServerAttributes.SERVER_ADDRESS, "localhost")))); } @@ -1182,7 +1175,7 @@ void testProduceProperSpanName( .hasAttributesSatisfying( equalTo(DbIncubatingAttributes.DB_SYSTEM, "other_sql"), equalTo(DbIncubatingAttributes.DB_NAME, databaseName), - equalTo(getDbConnectionStringKey(), "testdb://localhost"), + equalTo(DB_CONNECTION_STRING, "testdb://localhost"), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, operation), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, table), @@ -1232,7 +1225,7 @@ void testConnectionCached(String connectionPoolName) throws SQLException { equalTo(DbIncubatingAttributes.DB_SYSTEM, "hsqldb"), equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), equalTo(DbIncubatingAttributes.DB_USER, "SA"), - equalTo(getDbConnectionStringKey(), "hsqldb:mem:"), + equalTo(DB_CONNECTION_STRING, "hsqldb:mem:"), equalTo( DbIncubatingAttributes.DB_STATEMENT, "SELECT ? FROM INFORMATION_SCHEMA.SYSTEM_USERS"), @@ -1305,7 +1298,7 @@ void testHandleRecursiveStatements( .hasParent(trace.getSpan(0)) .hasAttributesSatisfying( equalTo(DbIncubatingAttributes.DB_SYSTEM, "other_sql"), - equalTo(getDbConnectionStringKey(), "testdb://localhost"), + equalTo(DB_CONNECTION_STRING, "testdb://localhost"), equalTo(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), equalTo(DbIncubatingAttributes.DB_SQL_TABLE, "table"), From 5649acee54131962a815846fb2a4486741caf591 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Thu, 26 Sep 2024 12:52:37 +0800 Subject: [PATCH 11/11] refine ut --- .../jdbc/test/JdbcInstrumentationTest.java | 87 ++++++++----------- 1 file changed, 35 insertions(+), 52 deletions(-) diff --git a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java index 06358057d8d1..d89414baa55a 100644 --- a/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java +++ b/instrumentation/jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jdbc/test/JdbcInstrumentationTest.java @@ -336,8 +336,6 @@ static Stream basicStatementStream() throws SQLException { "INFORMATION_SCHEMA.SYSTEM_USERS")); } - @DisplayName( - "basic statement with #connection.getClass().getCanonicalName() on #system generates spans") @ParameterizedTest @MethodSource("basicStatementStream") public void testBasicStatement( @@ -370,10 +368,11 @@ public void testBasicStatement( equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(username), - v -> assertThat(v).isNull())), + val -> { + if (username != null) { + val.isEqualTo(username); + } + }), equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), @@ -458,8 +457,6 @@ static Stream preparedStatementStream() throws SQLException { @ParameterizedTest @MethodSource("preparedStatementStream") - @DisplayName( - "prepared statement execute on #system with #connection.getClass().getCanonicalName() generates a span") void testPreparedStatementExecute( String system, Connection connection, @@ -472,7 +469,6 @@ void testPreparedStatementExecute( throws SQLException { PreparedStatement statement = connection.prepareStatement(query); cleanup.deferCleanup(statement); - cleanup.deferCleanup(connection); ResultSet resultSet = testing.runWithSpan( "parent", @@ -497,10 +493,11 @@ void testPreparedStatementExecute( equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(username), - v -> assertThat(v).isNull())), + val -> { + if (username != null) { + val.isEqualTo(username); + } + }), equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), @@ -509,8 +506,6 @@ void testPreparedStatementExecute( @ParameterizedTest @MethodSource("preparedStatementStream") - @DisplayName( - "prepared statement query on #system with #connection.getClass().getCanonicalName() generates a span") void testPreparedStatementQuery( String system, Connection connection, @@ -523,7 +518,6 @@ void testPreparedStatementQuery( throws SQLException { PreparedStatement statement = connection.prepareStatement(query); cleanup.deferCleanup(statement); - cleanup.deferCleanup(connection); ResultSet resultSet = testing.runWithSpan("parent", () -> statement.executeQuery()); resultSet.next(); @@ -542,10 +536,11 @@ void testPreparedStatementQuery( equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(username), - v -> assertThat(v).isNull())), + val -> { + if (username != null) { + val.isEqualTo(username); + } + }), equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), @@ -554,8 +549,6 @@ void testPreparedStatementQuery( @ParameterizedTest @MethodSource("preparedStatementStream") - @DisplayName( - "prepared call on #system with #connection.getClass().getCanonicalName() generates a span") void testPreparedCall( String system, Connection connection, @@ -568,7 +561,6 @@ void testPreparedCall( throws SQLException { CallableStatement statement = connection.prepareCall(query); cleanup.deferCleanup(statement); - cleanup.deferCleanup(connection); ResultSet resultSet = testing.runWithSpan("parent", () -> statement.executeQuery()); resultSet.next(); @@ -587,10 +579,11 @@ void testPreparedCall( equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(username), - v -> assertThat(v).isNull())), + val -> { + if (username != null) { + val.isEqualTo(username); + } + }), equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, sanitizedQuery), equalTo(DbIncubatingAttributes.DB_OPERATION, "SELECT"), @@ -699,8 +692,6 @@ static Stream statementUpdateStream() throws SQLException { @ParameterizedTest @MethodSource("statementUpdateStream") - @DisplayName( - "statement update on #system with #connection.getClass().getCanonicalName() generates a span") void testStatementUpdate( String system, Connection connection, @@ -712,7 +703,6 @@ void testStatementUpdate( throws SQLException { Statement statement = connection.createStatement(); cleanup.deferCleanup(statement); - cleanup.deferCleanup(connection); String sql = connection.nativeSQL(query); testing.runWithSpan("parent", () -> assertThat(statement.execute(sql)).isFalse()); @@ -731,10 +721,11 @@ void testStatementUpdate( equalTo(DbIncubatingAttributes.DB_NAME, dbNameLower), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(username), - v -> assertThat(v).isNull())), + val -> { + if (username != null) { + val.isEqualTo(username); + } + }), equalTo(DB_CONNECTION_STRING, url), equalTo(DbIncubatingAttributes.DB_STATEMENT, query), equalTo(DbIncubatingAttributes.DB_OPERATION, "CREATE TABLE"), @@ -811,8 +802,6 @@ static Stream preparedStatementUpdateStream() throws SQLException { @ParameterizedTest @MethodSource("preparedStatementUpdateStream") - @DisplayName( - "prepared statement update on #system with #connection.getClass().getCanonicalName() generates a span") void testPreparedStatementUpdate( String system, Connection connection, @@ -825,7 +814,6 @@ void testPreparedStatementUpdate( String sql = connection.nativeSQL(query); PreparedStatement statement = connection.prepareStatement(sql); cleanup.deferCleanup(statement); - cleanup.deferCleanup(connection); testing.runWithSpan("parent", () -> assertThat(statement.executeUpdate()).isEqualTo(0)); testing.waitAndAssertTraces( @@ -903,8 +891,6 @@ static Stream connectionConstructorStream() { @SuppressWarnings("CatchingUnchecked") @ParameterizedTest @MethodSource("connectionConstructorStream") - @DisplayName( - "connection constructor throwing then generating correct spans after recovery using #driver connection (prepare statement = #prepareStatement)") void testConnectionConstructorThrowing( boolean prepareStatement, String system, @@ -992,8 +978,6 @@ static Stream getConnectionStream() { @ParameterizedTest(autoCloseArguments = false) @MethodSource("getConnectionStream") - @DisplayName( - "calling #datasource.class.simpleName getConnection generates a span when under existing trace") void testGetConnection( DataSource datasource, Consumer init, @@ -1033,10 +1017,11 @@ void testGetConnection( equalTo(DbIncubatingAttributes.DB_SYSTEM, system), satisfies( DbIncubatingAttributes.DB_USER, - val1 -> - val1.satisfiesAnyOf( - v1 -> assertThat(v1).isEqualTo(user), - v1 -> assertThat(v1).isNull())), + val -> { + if (user != null) { + val.isEqualTo(user); + } + }), equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), equalTo(DB_CONNECTION_STRING, connectionString)))); if (recursive) { @@ -1053,10 +1038,11 @@ void testGetConnection( equalTo(DbIncubatingAttributes.DB_SYSTEM, system), satisfies( DbIncubatingAttributes.DB_USER, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isEqualTo(user), - v -> assertThat(v).isNull())), + val -> { + if (user != null) { + val.isEqualTo(user); + } + }), equalTo(DbIncubatingAttributes.DB_NAME, "jdbcunittest"), equalTo(DB_CONNECTION_STRING, connectionString))); } @@ -1142,7 +1128,6 @@ static Stream spanNameStream() { } @ParameterizedTest - @DisplayName("should produce proper span name #spanName") @MethodSource("spanNameStream") void testProduceProperSpanName( String url, @@ -1184,7 +1169,6 @@ void testProduceProperSpanName( @ParameterizedTest @ValueSource(strings = {"hikari", "tomcat", "c3p0"}) - @DisplayName("#connectionPoolName connections should be cached in case of wrapped connections") void testConnectionCached(String connectionPoolName) throws SQLException { String dbType = "hsqldb"; DataSource ds = createDs(connectionPoolName, dbType, jdbcUrls.get(dbType)); @@ -1272,7 +1256,6 @@ static Stream recursiveStatementsStream() { // regression test for // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/2644 @ParameterizedTest - @DisplayName("should handle recursive Statements inside Connection.getMetaData(): #desc") @MethodSource("recursiveStatementsStream") void testHandleRecursiveStatements( String desc,