aglinxinyuan opened a new issue, #5695:
URL: https://github.com/apache/texera/issues/5695
### Task Summary
Add dedicated unit-specs for the two JDBC connection helpers in
`common/workflow-operator/operator/source/sql/{postgresql,mysql}/`. Pin the
JDBC URL composition (the only application-controlled logic in each method)
without standing up a real DB.
## Background
Two thin JDBC wrappers in `common/workflow-operator/operator/source/sql/`
currently lack a dedicated unit-spec. Each `connect(host, port, database,
username, password)` method builds a JDBC URL string, calls
`DriverManager.getConnection`, and flips the resulting Connection to read-only:
| Source class | URL format |
| --- | --- |
| `PostgreSQLConnUtil` | `jdbc:postgresql://{host}:{port}/{database}` |
| `MySQLConnUtil` |
`jdbc:mysql://{host}:{port}/{database}?autoReconnect=true&useSSL=true` |
The URL string is application-logic worth pinning; an accidental edit (e.g.
dropping `useSSL=true` from MySQL) would silently change connection security.
The actual `DriverManager.getConnection` call needs no DB — when the host is
unreachable, it throws `SQLException` early, and the URL has already been built
and visible inside the exception.
## Behavior to pin
For each `connect` method:
| Surface | Contract |
| --- | --- |
| Invocation with a bogus host (e.g. `"unreachable.example.invalid"`) |
throws `SQLException` (no driver class is loaded for `jdbc:postgresql://…` /
`jdbc:mysql://…` in the unit-test classpath, or the driver throws "no suitable
driver") |
| `PostgreSQLConnUtil.connect("h", "5432", "db", "u", "p")` | the
SQLException's message or the constructed URL contains the substring
`jdbc:postgresql://h:5432/db` |
| `MySQLConnUtil.connect("h", "3306", "db", "u", "p")` | the constructed URL
substring includes `jdbc:mysql://h:3306/db`, `autoReconnect=true`, AND
`useSSL=true` |
| Distinct host/port/database values | are interpolated into the right
positions (e.g. swapping `host` and `database` produces a different URL) |
| Empty database name | does not crash the URL builder (the resulting URL
`jdbc:postgresql://h:5432/` is still well-formed even if rejected by the
driver) |
## Scope
- New spec files (one per source class):
- `PostgreSQLConnUtilSpec.scala`
- `MySQLConnUtilSpec.scala`
- No production-code changes.
- The harness uses `intercept[SQLException]` (or `RuntimeException` for
`ClassNotFoundException` cases) and asserts on the *URL substring* visible in
the exception message — the URL has already been built before the connection
failure, so the substring is reachable.
- If the URL substring is not in the exception, consider registering a dummy
`Driver` via `DriverManager.registerDriver` that captures the URL it was asked
to open and throws — that gives the test full control without touching network.
### Task Type
- [ ] Refactor / Cleanup
- [ ] DevOps / Deployment / CI
- [x] Testing / QA
- [ ] Documentation
- [ ] Performance
- [ ] Other
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]