Skip to content

feat(simulator): add SQL execution support with MySQL and PostgreSQL#375

Open
chhil wants to merge 2 commits into
jpos:mainfrom
chhil:feature/clientsim-sql-support
Open

feat(simulator): add SQL execution support with MySQL and PostgreSQL#375
chhil wants to merge 2 commits into
jpos:mainfrom
chhil:feature/clientsim-sql-support

Conversation

@chhil

@chhil chhil commented May 13, 2026

Copy link
Copy Markdown
Contributor

Implements optional pre/post-SQL execution in test cases with configurable error handling.

Summary

  • Add preSQL and postSQL fields to TestCase with getters/setters
  • Add continueOnSqlError option to control SQL failure behavior (default: continue)
  • Add SQLFailureException for strict SQL error handling
  • Add executeSQL() method to TestRunner using Hibernate Work interface
  • Parse pre-sql/post-sql XML elements in test suite configuration
  • Support continue-on-sql-error attribute on test elements
  • Execute SQL before request (preSQL) and after response (postSQL)
  • Support semicolon-separated multiple SQL statements
  • Log SELECT results and affected row counts
  • Add MySQL test support via Testcontainers

Documentation

  • Complete SQL execution support documentation with examples
  • Execution order: init, pre-sql, request/response, post, post-sql
  • When to use SQL execution (balance setup, limits, state reset)
  • Database configuration and db.properties examples
  • init script scoping with suite-level and test-level differences
  • Database dependencies (PostgreSQL, MySQL, H2) for Gradle
  • Supported databases with behavioral differences

Tests

  • 36 tests covering SQL functionality, backward compatibility, and error handling
  • Tests run against both PostgreSQL (default) and MySQL via test.clientsim_db_driver
  • Driver-aware DDL syntax ensures cross-database compatibility

Behavior

  • By default, SQL errors are logged but don't fail the test (backward compatible)
  • Set continue-on-sql-error="no" to fail test on SQL error
  • SQL feature is purely opt-in - existing configs work unchanged

Assisted-by

Qwen36

Implements optional pre/post-SQL execution in test cases with
configurable error handling.

Changes:
- Add preSQL and postSQL fields to TestCase with getters/setters
- Add continueOnSqlError option to control SQL failure behavior
(default: continue)
- Add SQLFailureException for strict SQL error handling
- Add executeSQL() method to TestRunner using Hibernate Work interface
- Parse pre-sql/post-sql XML elements in test suite configuration
- Support continue-on-sql-error attribute on test elements
- Execute SQL before request (preSQL) and after response (postSQL)
- Support semicolon-separated multiple SQL statements
- Log SELECT results and affected row counts
- Add MySQL test support via Testcontainers (db-mysql,
testcontainers.mysql)
- Add commons-codec runtime dependency for testcontainers tar operations

Documentation:
- Complete SQL execution support documentation with examples
- Execution order: init, pre-sql, request/response, post, post-sql
- When to use SQL execution (balance setup, limits, state reset)
- Database configuration and db.properties examples
- init script scoping with suite-level and test-level differences
- Database dependencies (PostgreSQL, MySQL, H2) for Gradle
- Supported databases with behavioral differences

Tests:
- 36 tests covering SQL functionality, backward compatibility, and error
handling
- Tests run against both PostgreSQL (default) and MySQL via property
test.clientsim_db_driver
- Driver-aware DDL syntax ensures cross-database compatibility

Fixes:
- doc/build.gradle and doc/buildSrc/build.gradle - Java compatibility
fixes for Gradle 9.x
@ar-agt

ar-agt commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this contribution. SQL setup/cleanup around Client Simulator tests is a very useful addition and will come in handy for stateful simulator scenarios, especially balance setup, limits, and deterministic cleanup between cases.

I think this needs a small rework before merge:

  1. continue-on-sql-error="no" can still report the test as OK in some paths.

    • For pre-sql, runSuite sets FAILURE on SQLFailureException, but when continue="yes" is set it falls through and still sends the request; assertResponse can then overwrite the result to OK.
    • For fire-and-forget tests, a strict post-sql failure sets FAILURE, but the path later unconditionally calls tc.setResultCode(TestCase.OK).
  2. The tests should exercise the new TestRunner path directly. Right now several SQL tests open DB and execute JDBC work directly, so they do not prove that executeSQL, XML parsing of pre-sql/post-sql, or the runSuite ordering/error handling work correctly.

  3. Please fix the Javadoc markup errors introduced by the new docs (unexpected end tag: </p> in TestRunner, TestCase, and SQLFailureException). The current build does not fail on those errors, but we should not add known broken Javadocs.

  4. Please keep the diff tighter if possible. The feature is good, but the broad reformatting/Javadoc churn around existing code makes review harder than it needs to be.

Verification I ran:

  • ./gradlew :modules:client-simulator:test passed with PostgreSQL.
  • ./gradlew :modules:client-simulator:test -Dtest.clientsim_db_driver=mysql passed.
  • A local no-commit merge with current origin/main, then ./gradlew :modules:client-simulator:test :modules:client-simulator:build, passed, with the Javadoc errors noted above.

Fix a bug in fire-and-forget path where SQL failure result code was
overwritten by unconditional OK.
Tighten SQL error breaks in runSuite to always exit the repetition loop
when continue-on-sql-error=no.
Clean up Javadoc across SQLFailureException, TestCase, and TestRunner:
remove orphaned </p> tags, align asterisks,
normalize indentation, and update preSQL→pre-SQL in lifecycle docs.
Add TestRunnerSQLIntegrationTest covering SQL XML parsing, strict vs
lenient error modes, multi-statement execution, and table cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants