Skip to content

test: cover inner PROCTRAN HWPT/XRTY catch in CRECUST and UPDCUST#43

Merged
a2chang merged 1 commit into
mainfrom
polish/issue-35-inner-proctran-unit-tests
May 1, 2026
Merged

test: cover inner PROCTRAN HWPT/XRTY catch in CRECUST and UPDCUST#43
a2chang merged 1 commit into
mainfrom
polish/issue-35-inner-proctran-unit-tests

Conversation

@a2chang
Copy link
Copy Markdown
Contributor

@a2chang a2chang commented May 1, 2026

Closes #35.

What

Per-repository unit coverage for the inner PROCTRAN-insert catch in
CrecustRepository.createCustomer(...) and UpdcustRepository.updateCustomer(...).
That catch (added in #34) wraps non-retryable PROCTRAN failures as
CbsaAbendException("HWPT", "<PROGRAM> failed to write the audit trail.")
and re-throws SQLSTATE 40001 failures unchanged so CrdbRetry can retry
them. Until now both behaviours were exercised only indirectly via
DbcrfunRepositoryUnitTest (same catch pattern) and integration tests
(happy-path only).

How

The inner block sits inside dsl.transactionResult(configuration -> ...)
and uses DSL.using(configuration) to build the txDsl. Static-mocking
DSL.using is not available (subclass MockMaker doesn't support
mockStatic), so each test now hands the lambda a real jOOQ
Configuration backed by:

  • org.jooq.tools.jdbc.MockConnection + a MockDataProvider that:
    • CRECUST: returns (CUSTOMER_COUNT=0, CUSTOMER_LAST=0) for the
      CONTROL SELECT ... FOR UPDATE, 1 row affected for the CUSTOMER
      insert and the CONTROL update, and throws the seeded
      SQLException on the PROCTRAN insert.
    • UPDCUST: returns one synthesised CUSTOMER row for the
      SELECT ... FOR UPDATE, 1 row affected for the CUSTOMER update,
      and throws on the PROCTRAN insert.
  • A small inline ExecuteListener that calls Spring's
    SQLStateSQLExceptionTranslator.translate(...) and re-throws via
    ctx.exception(...). This mirrors what
    JooqAutoConfiguration#DefaultExceptionTranslatorExecuteListener
    installs in production (polish: jOOQ DataAccessException catches don't fire because Spring Boot translator substitutes Spring DAE #36 / fix(repos): catch Spring DataAccessException so CrdbRetry and PROCTRAN abends fire #37) — without it the test would surface
    a raw org.jooq.exception.DataAccessException, which the repository's
    catch (org.springframework.dao.DataAccessException) does not match.
    (Spring Boot's listener class is package-private; we cannot reuse it
    directly, so the test reproduces its one-line behaviour.)

dsl.transactionResult(callable) on the outer mock is then stubbed to
invoke the callable with that real configuration — the lambda's
DSL.using(configuration) returns a real DSLContext whose statements
flow through the MockDataProvider.

Tests

Four new tests, two per repository:

  • nonSerializationProctranInsertFailureWrapsAsHwptAbend — non-40001
    SQLException (e.g. 23505) → CbsaAbendException("HWPT", "<PROG> failed to write the audit trail.").
  • serializationProctranInsertFailureSurfacesAsXrtyAfterRetryExhaustion
    40001 SQLException → after CrdbRetry exhausts, the outer catch
    converts it to CbsaAbendException("XRTY", "<PROG> aborted after exhausting Cockroach serialization retries.").

Local ./mvnw -B verify: 202/202 (was 198/198 — +4).

Notes

  • No production code touched.
  • UpdcustRepositoryUnitTest's class-Javadoc previously documented why
    the inner catch was not unit-tested; that disclaimer is now obsolete
    and replaced with the actual coverage description, matching
    CrecustRepositoryUnitTest.
  • The per-SQLException failure injection is the smallest scaffold that
    reaches the catch without a real database. Existing
    *ServiceIntegrationTest#proctranInsertFailureSurfacesHwptAbend tests
    (added in fix(repos): catch Spring DataAccessException so CrdbRetry and PROCTRAN abends fire #37) keep the integration-level assertion that the listener
    is actually wired in production.

augment review

Use MockConnection + MockDataProvider + a Spring exception-translator
ExecuteListener to drive the public createCustomer/updateCustomer
through to the inner PROCTRAN-insert catch:

  - non-40001 SQLException -> CbsaAbendException("HWPT", "<PROG>
    failed to write the audit trail.")
  - 40001 SQLException -> rethrown unchanged so CrdbRetry retries;
    after exhaustion the outer catch surfaces XRTY

The inline ExecuteListener mirrors JooqAutoConfiguration's
DefaultExceptionTranslatorExecuteListener (package-private, so we
reproduce it via SQLStateSQLExceptionTranslator).

Closes #35.
Copy link
Copy Markdown

@augment-app-staging augment-app-staging Bot left a comment

Choose a reason for hiding this comment

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

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@a2chang a2chang merged commit 24390d1 into main May 1, 2026
1 check passed
@a2chang a2chang mentioned this pull request May 1, 2026
22 tasks
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.

Per-repository unit coverage for inner PROCTRAN catch in CRECUST / UPDCUST

1 participant