Skip to content

Conversation

@trask
Copy link
Member

@trask trask commented Oct 24, 2025

No description provided.

@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Oct 24, 2025
@trask trask force-pushed the unify-jdbc-tests-2 branch 10 times, most recently from 2d63bcd to 6e4b8c0 Compare October 26, 2025 00:35
Copy link
Member Author

@trask trask Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only change compared to the old javaagent PreparedStatementParametersTest is calling wrap()

EDIT and added test for setByte

if (init != null) {
init.accept(ds);
}
Class<?> originalDatasourceClass = ds.getClass();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capturing the original class here before to use in verification later

Copy link
Member Author

@trask trask Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see review comments for changes to this file other than calling wrap()

return Stream.of(
Arguments.of(
new JdbcDataSource(),
(Consumer<DataSource>) ds -> ((JdbcDataSource) ds).setURL(jdbcUrls.get("h2")),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this changed from setUrl in the javaagent test to setURL in this module because in the javaagent module, h2 version is overridden for slick test

try {
ds.setDriverClass(jdbcDriverClassNames.get(dbType));
} catch (PropertyVetoException e) {
throw new IllegalStateException(e);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this changed from RuntimeException to IllegalStateException b/c it's now in src/main and so errorprone rules apply


@SuppressWarnings("deprecation") // using deprecated semconv
class DruicDataSourceTest {
class DruidDataSourceTest {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unrelated fix)

Comment on lines -31 to +33
private String url;
Consumer<String> sqlConsumer = unused -> {};

public TestConnection() {}
private final String url;
private final Consumer<String> sqlConsumer;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated simplification

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed tests from here that are now covered by the shared tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only change compared to the old javaagent PreparedStatementParametersTest is calling wrap()

@trask trask force-pushed the unify-jdbc-tests-2 branch from 0ea49ce to 4928d36 Compare October 27, 2025 01:54
transformer.applyAdviceToMethod(
namedOneOf(
"setBoolean",
"setByte",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added to match library instrumentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. Down below there are 2 lines with comment // Short, Int, Long, Float, Double, BigDecimal could also add Byte to the list there

// these dependencies are for SlickTest
testImplementation("org.scala-lang:scala-library:2.11.12")
testImplementation("com.typesafe.slick:slick_2.11:3.2.0")
testImplementation("com.h2database:h2:1.4.197")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test seems to pass with version 1.3.169 which is specified above

Comment on lines 247 to 254
putParameter(parameterIndex, x);
}

@SuppressWarnings("UngroupedOverloads")
@Override
public void setObject(int parameterIndex, Object x) throws SQLException {
delegate.setObject(parameterIndex, x);
putParameter(parameterIndex, x);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for parity with javaagent instrumentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agent only captures the object if it is of a recognized type, see

if (value instanceof Boolean
// Short, Int, Long, Float, Double, BigDecimal
|| value instanceof Number
|| value instanceof String
|| value instanceof Date
|| value instanceof Time
|| value instanceof Timestamp
|| value instanceof URL
|| value instanceof RowId) {
str = value.toString();
}

Comment on lines +869 to +884
Arguments.of(
"derby",
new EmbeddedDriver().connect(jdbcUrls.get("derby"), null),
"APP",
"CREATE TABLE PS_LARGE_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))",
"CREATE TABLE jdbcunittest.PS_LARGE_DERBY",
"derby:memory:",
"PS_LARGE_DERBY"),
Arguments.of(
"hsqldb",
new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null),
"SA",
"CREATE TABLE PUBLIC.PS_LARGE_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))",
"CREATE TABLE PUBLIC.PS_LARGE_HSQLDB",
"hsqldb:mem:",
"PUBLIC.PS_LARGE_HSQLDB"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added derby and hsqldb for more "large" method testing

Comment on lines +900 to +918
if (Boolean.getBoolean("testLatestDeps")) {
testPreparedStatementUpdateImpl(
system,
connection,
username,
query,
spanName,
url,
table,
statement -> assertThat(statement.executeLargeUpdate()).isEqualTo(0));
} else {
// Older drivers don't support JDBC 4.2, expect UnsupportedOperationException
// This is the correct behavior - instrumentation should not change driver behavior
String sql = connection.nativeSQL(query);
PreparedStatement statement = connection.prepareStatement(sql);
cleanup.deferCleanup(statement);
assertThatThrownBy(statement::executeLargeUpdate)
.isInstanceOf(UnsupportedOperationException.class);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verifies both new and old driver behavior now

Comment on lines +1475 to +1482
if (Boolean.getBoolean("testLatestDeps")) {
assertThat(statement.executeLargeBatch()).isEqualTo(new long[] {1, 1});
} else {
// Older drivers don't support JDBC 4.2, expect UnsupportedOperationException
// This is the correct behavior - instrumentation should not change driver behavior
assertThatThrownBy(statement::executeLargeBatch)
.isInstanceOf(UnsupportedOperationException.class);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verifies both new and old driver behavior now

Comment on lines 48 to 52

// Initialize the connection pool to trigger H2's internal schema setup
// This prevents internal H2 spans from appearing in the test assertions
dataSource.getConnection().close();
testing.clearData();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change was triggered by the h2 dependency version change in the javaagent module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Often we add testing.waitForTraces(1); before clearData to ensure that the trace is received before we clear it.

@trask trask force-pushed the unify-jdbc-tests-2 branch from 8c72788 to cf1db4c Compare October 27, 2025 04:13
Comment on lines +47 to +48
// need to unwrap in order to preserve SQLException behavior
private static Object invokeWithUnwrappedTarget(Object target, Method method, Object[] args)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change also triggered by h2 dependency version change in the javaagent tests

@trask trask marked this pull request as ready for review October 27, 2025 04:58
@trask trask requested a review from a team as a code owner October 27, 2025 04:58
@trask trask enabled auto-merge (squash) October 27, 2025 16:37
@trask trask disabled auto-merge October 27, 2025 17:37
@otelbot-java-instrumentation
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

@trask trask merged commit bdc098f into open-telemetry:main Oct 27, 2025
83 checks passed
@trask trask deleted the unify-jdbc-tests-2 branch October 27, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants