Skip to content
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

convert instrument jdbc test from groovy to java #12132

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

shalk
Copy link
Contributor

@shalk shalk commented Aug 28, 2024

relate to #7195

@shalk shalk marked this pull request as ready for review September 6, 2024 10:07
@shalk shalk requested a review from a team September 6, 2024 10:07
shalk and others added 2 commits September 10, 2024 14:13
Co-authored-by: Jay DeLuca <jaydeluca4@gmail.com>
shalk and others added 2 commits September 13, 2024 19:22
Co-authored-by: Jay DeLuca <jaydeluca4@gmail.com>
@shalk
Copy link
Contributor Author

shalk commented Sep 14, 2024

It is look like

:instrumentation:couchbase:couchbase-2.6:javaagent:test

failed by Address already in use.

It is not break by jdbc test. the jdc case is all memory server

Comment on lines +81 to +98
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<>();
jdbcUserNames.put("derby", "APP");
jdbcUserNames.put("h2", null);
jdbcUserNames.put("hsqldb", "SA");
Copy link
Contributor

Choose a reason for hiding this comment

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

you could have initialized these in the field declaration as the groovy test did

Comment on lines +342 to +343
@DisplayName(
"basic statement with #connection.getClass().getCanonicalName() on #system generates spans")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the value of this. Spock is able to replace #connection.getClass().getCanonicalName() and #system with actual parameter values so you'd have a test named prepared statement execute on h2 with org.h2.jdbc.JdbcConnection generates a span with junit this does not happen

Comment on lines +373 to +378
satisfies(
DbIncubatingAttributes.DB_USER,
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo(username),
v -> assertThat(v).isNull())),
Copy link
Contributor

Choose a reason for hiding this comment

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

the original groovy test uses

if (username != null) {
  "$DbIncubatingAttributes.DB_USER" username
}

If username is given verify that this attribute exists, your assertion just makes user name optional.

Comment on lines +383 to +384
statement.close();
connection.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

other tests use

    cleanup.deferCleanup(statement);
    cleanup.deferCleanup(connection);

Comment on lines +1069 to +1072
@SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation
AttributeKey<String> getDbConnectionStringKey() {
return DbIncubatingAttributes.DB_CONNECTION_STRING;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps instead of a method it would be better to define this as a field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants