test: cover inner PROCTRAN HWPT/XRTY catch in CRECUST and UPDCUST#43
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #35.
What
Per-repository unit coverage for the inner PROCTRAN-insert catch in
CrecustRepository.createCustomer(...)andUpdcustRepository.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
40001failures unchanged soCrdbRetrycan retrythem. 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 thetxDsl. Static-mockingDSL.usingis not available (subclass MockMaker doesn't supportmockStatic), so each test now hands the lambda a real jOOQConfigurationbacked by:org.jooq.tools.jdbc.MockConnection+ aMockDataProviderthat:(CUSTOMER_COUNT=0, CUSTOMER_LAST=0)for theCONTROL
SELECT ... FOR UPDATE,1 row affectedfor the CUSTOMERinsert and the CONTROL update, and throws the seeded
SQLExceptionon the PROCTRAN insert.SELECT ... FOR UPDATE,1 row affectedfor the CUSTOMER update,and throws on the PROCTRAN insert.
ExecuteListenerthat calls Spring'sSQLStateSQLExceptionTranslator.translate(...)and re-throws viactx.exception(...). This mirrors whatJooqAutoConfiguration#DefaultExceptionTranslatorExecuteListenerinstalls 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'scatch (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 toinvoke the callable with that real configuration — the lambda's
DSL.using(configuration)returns a realDSLContextwhose statementsflow through the
MockDataProvider.Tests
Four new tests, two per repository:
nonSerializationProctranInsertFailureWrapsAsHwptAbend— non-40001SQLException(e.g.23505) →CbsaAbendException("HWPT", "<PROG> failed to write the audit trail.").serializationProctranInsertFailureSurfacesAsXrtyAfterRetryExhaustion—40001SQLException→ afterCrdbRetryexhausts, the outer catchconverts it to
CbsaAbendException("XRTY", "<PROG> aborted after exhausting Cockroach serialization retries.").Local
./mvnw -B verify: 202/202 (was 198/198 — +4).Notes
UpdcustRepositoryUnitTest's class-Javadoc previously documented whythe inner catch was not unit-tested; that disclaimer is now obsolete
and replaced with the actual coverage description, matching
CrecustRepositoryUnitTest.SQLExceptionfailure injection is the smallest scaffold thatreaches the catch without a real database. Existing
*ServiceIntegrationTest#proctranInsertFailureSurfacesHwptAbendtests(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