-
Couldn't load subscription status.
- Fork 1k
Unify jdbc tests between javaagent and library instrumentation #15137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2d63bcd to
6e4b8c0
Compare
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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")), |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(unrelated fix)
| private String url; | ||
| Consumer<String> sqlConsumer = unused -> {}; | ||
|
|
||
| public TestConnection() {} | ||
| private final String url; | ||
| private final Consumer<String> sqlConsumer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated simplification
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
0ea49ce to
4928d36
Compare
| transformer.applyAdviceToMethod( | ||
| namedOneOf( | ||
| "setBoolean", | ||
| "setByte", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
| putParameter(parameterIndex, x); | ||
| } | ||
|
|
||
| @SuppressWarnings("UngroupedOverloads") | ||
| @Override | ||
| public void setObject(int parameterIndex, Object x) throws SQLException { | ||
| delegate.setObject(parameterIndex, x); | ||
| putParameter(parameterIndex, x); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Lines 157 to 167 in 5c145a8
| 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(); | |
| } |
| 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")); |
There was a problem hiding this comment.
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
| 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); | ||
| } |
There was a problem hiding this comment.
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
| 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); | ||
| } |
There was a problem hiding this comment.
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
|
|
||
| // 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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
8c72788 to
cf1db4c
Compare
| // need to unwrap in order to preserve SQLException behavior | ||
| private static Object invokeWithUnwrappedTarget(Object target, Method method, Object[] args) |
There was a problem hiding this comment.
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
|
🔧 The result from spotlessApply was committed to the PR branch. |
No description provided.