You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "DanielLeens (via GitHub)" <gi...@apache.org> on 2026/04/20 06:56:16 UTC
Re: [PR] [Feature][Connectors-v2] Optimize unit testing for PostgreSQL in JDBC connector [seatunnel]
DanielLeens commented on PR #10252:
URL: https://github.com/apache/seatunnel/pull/10252#issuecomment-4278481191
# What Problem Does This PR Solve?
- User pain point
PostgreSQL JDBC catalog/dialect behavior is important for real users: table creation, primary-key/index discovery, PostgreSQL-specific type mapping, and upsert SQL generation are all paths that can regress quietly if they are covered only by lightweight string assertions or by indirect E2E coverage.
- Fix approach
This PR adds PostgreSQL Testcontainers-based tests under `connector-jdbc`: a shared `AbstractPostgresContainerTest`, `PostgresCatalogTest`, and `PostgresDialectTest`. It also keeps the main `JdbcPostgresIT` E2E flow and removes the old `testCatalog()` method from E2E, which is better covered at the connector-jdbc test layer.
- One sentence
This is a useful PostgreSQL JDBC test improvement, but the POM currently leaks JUnit into the runtime dependency surface and the Build check is still red, so it needs a small fix before merge.
Simple example: instead of only checking that a generated SQL string looks right, the new tests can start a real PostgreSQL container, create a table, read it through `PostgresCatalog`, and verify schema/index/type behavior against a real database.
# 1. Code Change Review
## 1.1 Core Logic Analysis
- Precise change description
Main changes:
- `seatunnel-connectors-v2/connector-jdbc/pom.xml:255`, `452`: adds Testcontainers/JUnit-related dependencies.
- `seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/container/AbstractPostgresContainerTest.java:41`: adds a PostgreSQL Testcontainers base class, disabled on Windows.
- `seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/container/PostgresCatalogTest.java:52`: adds real PostgreSQL catalog tests.
- `seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/container/PostgresDialectTest.java:39`: adds PostgreSQL dialect tests.
- `seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-3/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcPostgresIT.java:307`: keeps the E2E flow while removing a catalog-only test from E2E.
The production PostgreSQL source/sink path is not directly changed. The changed code is mainly hit by Maven unit/E2E test execution, but the POM dependency change can affect connector-jdbc packaging/runtime classpath.
- Before / after snippets
Before, this PR baseline did not add PostgreSQL Testcontainers/JUnit dependencies in this module:
```xml
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sts</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
```
After this PR, `junit-jupiter-api` is added without test scope:
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
```
The `JdbcPostgresIT.hasIndex()` change is behavior-preserving and removes the `StringUtils` dependency:
```java
if (primaryKey != null
&& primaryKey.getPrimaryKey() != null
&& !primaryKey.getPrimaryKey().trim().isEmpty()) {
return true;
}
```
- Key findings
- Normal PostgreSQL source/sink runtime does not directly hit the new test classes.
- Maven unit tests do hit `PostgresCatalogTest` and `PostgresDialectTest`; Windows skips them with `@DisabledOnOs(OS.WINDOWS)`.
- The main `JdbcPostgresIT` E2E flow remains; the removed `testCatalog()` is better placed in connector-jdbc tests.
- The real blocker is the POM dependency scope: JUnit should not be a runtime dependency of connector-jdbc.
- The current Build check is failing and must be made green or clearly rerun after the dependency fix.
- Deep correctness analysis
`AbstractPostgresContainerTest` starts `postgres:15-alpine` in `@BeforeAll`, exposes the runtime JDBC URL/user/password, and creates a production `PostgresCatalog`. `PostgresCatalogTest` creates real PostgreSQL tables with JDBC, then calls `PostgresCatalog.open()`, `tableExists()`, `getTable()`, `createTable()`, `truncateTable()`, `dropTable()`, and `isExistsData()`. `PostgresDialectTest` directly verifies `PostgresDialect` identifier quoting, parsing, hash split expressions, and SQL generation; one test creates a real table and verifies the generated upsert statement shape.
Complete test flow:
```text
Maven test phase
-> connector-jdbc test classpath resolves pom.xml dependencies [pom.xml:452-472]
-> testcontainers / junit-jupiter / postgresql driver enter test classpath
-> current junit-jupiter-api also enters compile/runtime dependency surface because scope is missing
PostgreSQL test startup
-> AbstractPostgresContainerTest.startContainer() [L56-64]
-> new PostgreSQLContainer("postgres:15-alpine")
-> database=testdb, user=test, password=test
-> POSTGRES_CONTAINER.start()
Catalog tests
-> executeSql()/createTestTable()
-> create real PostgreSQL tables
-> createPostgresCatalog()
-> new PostgresCatalog(DatabaseIdentifier.POSTGRESQL, user, password, JdbcUrlInfo, "public", null)
-> catalog.open()
-> tableExists/getTable/createTable/truncateTable/dropTable/isExistsData
Dialect tests
-> new PostgresDialect()
-> quoteIdentifier/tableIdentifier/parse/hashModForField/getUpsertStatement
-> some coverage uses the live PostgreSQL container
E2E path
-> JdbcPostgresIT still runs the PostgreSQL source/sink job flow
-> removed testCatalog() was catalog-only and is now covered in connector-jdbc tests
```
## 1.2 Compatibility Impact
Judgement: partially incompatible risk.
- API: no public connector API changes.
- Config options: no user-facing config changes.
- Defaults: no default changes.
- Protocol: no JDBC/SeaTunnel protocol changes.
- Serialization format: unchanged.
- Historical behavior: production code is unchanged, but the missing test scope can pollute runtime connector dependencies and packaging.
## 1.3 Performance / Side Effects
- CPU/memory/network: no production runtime impact; CI/test execution will use extra Docker resources for PostgreSQL.
- GC: no production runtime impact.
- Lock contention/concurrency: no production lock changes.
- Retry/idempotency: no production changes.
- Resource release: the PostgreSQL container is stopped in `@AfterAll`, and most test resources are closed in try/finally.
## 1.4 Error Handling and Logging
No production error handling is changed. The tests contain several `System.out.println` calls; that is not a blocker, but can be cleaned up later. The current CI failure must be addressed.
Issue 1: `junit-jupiter-api` is added without test scope and leaks into connector-jdbc runtime dependencies
- Location: `seatunnel-connectors-v2/connector-jdbc/pom.xml:469`
- Description:
This is a test-only PR, but `org.junit.jupiter:junit-jupiter-api` is declared without `<scope>test</scope>`, so Maven treats it as a compile dependency of connector-jdbc. The CI logs already show a matching packaging/classpath signal: `connector-jdbc-2.3.13-SNAPSHOT-2.12.15.jar, junit-jupiter-api-5.9.0.jar define 175 overlapping class and resource`, plus overlap warnings involving `opentest4j`.
- Risk:
JUnit should not be part of the runtime connector dependency surface. This can pollute plugin packaging, increase classpath conflicts, and make dependency/license/shading checks noisier.
- Recommendation:
Remove the explicit `junit-jupiter-api` dependency if the parent/test dependencies already provide it. If it must stay, add `<scope>test</scope>`. Please also check whether the Testcontainers entries are already managed by the parent/current `dev` to avoid duplicate dependency management.
- Severity: High
Issue 2: The current Build check is still failing
- Location: `seatunnel-connectors-v2/connector-jdbc/pom.xml:469`
- Description:
GitHub currently reports the `Build` check as failure. The check-run points to fork run `BrandaoFelipe/seatunnel` run id `22691510615`. Failed jobs include `Run / unit-test (8, ubuntu-latest)`, `Run / updated-modules-integration-test-part-8 (11, ubuntu-latest)`, and `Run / kafka-connector-it (11, ubuntu-latest)`. The logs show `connector-fake` unit-test failures, `MetalakeIT.testMetalake:190 expected <0> but was <1>`, and `KafkaIT.testKafkaToKafkaExactlyOnceOnStreaming:1597` timeout. The Kafka log also shows the JUnit/OpenTest4J overlap warning from Issue 1.
- Risk:
Some failures may be unrelated/flaky, but the PR still has a red Build and one PR-owned dependency issue visible in the logs. It should not be merged while Build is red.
- Recommendation:
Fix Issue 1 first, then rerun CI. If the remaining failures are clearly unrelated after rerun, maintainers can make that call with fresh evidence.
- Severity: High
# 2. Code Quality Assessment
## 2.1 Code Style
The new files include ASF headers, and local `git diff --check upstream/dev...HEAD` is clean. There are some verbose `System.out.println` calls and a little non-English test debug text; these are not blockers for this contribution.
## 2.2 Test Coverage
The added Testcontainers coverage is useful and closer to real PostgreSQL behavior than pure string tests. The main `JdbcPostgresIT` E2E flow remains. One future improvement would be making `PostgresDialectTest.testRealUpsertExecution()` actually execute the generated upsert and verify the updated row, but I would not block this PR on that.
## 2.3 Documentation
No docs changes are required because this is test coverage only and does not change user-visible behavior.
# 3. Architecture Assessment
## 3.1 Elegance
This is a precise test-layer improvement. Moving catalog/dialect checks into connector-jdbc tests and keeping E2E focused on job execution is the right direction.
## 3.2 Maintainability
The test layering becomes clearer. After the dependency scope is fixed, this should be easier to maintain than mixing catalog-only assertions into E2E.
## 3.3 Extensibility
`AbstractPostgresContainerTest` gives future PostgreSQL JDBC tests a reusable base. The same pattern can be reused for other JDBC dialects, with attention to CI resources and Windows behavior.
## 3.4 Historical Compatibility
Production code is unchanged, so historical job behavior remains compatible. The dependency scope issue must be fixed so test dependencies do not affect runtime packaging.
# 4. Issue Summary
| No. | Issue | Location | Severity |
|---|---|---|---|
| 1 | `junit-jupiter-api` is added without test scope and leaks into connector-jdbc runtime dependencies | `seatunnel-connectors-v2/connector-jdbc/pom.xml:469` | High |
| 2 | Current Build check is still failing | `seatunnel-connectors-v2/connector-jdbc/pom.xml:469` | High |
# 5. Merge Conclusion
### Conclusion: can merge after fixes
1. Blocking items
- Issue 1: remove `junit-jupiter-api` or restrict it to test scope.
- Issue 2: rerun CI after the dependency fix and get a green Build, or provide fresh maintainer-confirmed evidence that any remaining failures are unrelated.
2. Recommended non-blocking fixes
- Later, consider executing the generated upsert SQL in `testRealUpsertExecution()` and asserting the row update result.
- Later, reduce noisy `System.out.println` output in tests.
Overall, this is a good contribution and the test direction is welcome. The main thing to focus on now is the small POM scope issue and a clean CI rerun. Once those are handled, I think this PR can move forward.
Local analysis record: I fetched the PR into local branch `seatunnel-review-10252`; HEAD is `9dfc82c5932f60e88dbc256b2d00681c389065eb`, merge base is `e24b8c1406110e8466910d89986b0475ad96b684`. I checked `gh pr view 10252 ...`, `git diff --stat upstream/dev...HEAD`, `git diff --check upstream/dev...HEAD`, `git merge-tree $(git merge-base upstream/dev HEAD) upstream/dev HEAD`, check-runs for the head commit, and failing CI job logs. Key results: 5 changed files, `git diff --check` clean, GitHub reports `mergeable=MERGEABLE` and `mergeStateStatus=BLOCKED`, and the Build check is failing.
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org