Repository navigation
Fixes 33641: scope the JDBI test decorators on Predicate<StatementContext> - #33642
Conversation
Three PRs in the #32946 stack each carry their own copy of these decorators and now collide with the versions #33539 landed on main: CONFLICT (add/add) SqlQueryCounter.java #33344, #33355 CONFLICT (add/add) SqlFailureProbe.java #33362 Their copies are not gratuitous - they scope on Predicate<StatementContext> rather than the BooleanSupplier that merged, and #33344 and #33355 already call the three-argument forRequests and deadlockOnce. This makes main's copy the one they call, so the dedup on rebase is a deletion rather than a rewrite. Predicate<StatementContext> is also the better answer to the review on #33539 that forRequests was too broad. A fragment alone cannot tell the request under test apart from a concurrent one running the same SQL; the caller needs a look at each candidate statement. SqlFailureProbe.forRequests therefore returns, but requiring the caller's predicate rather than matching any in-flight request. SqlFailureProbe.deadlockOnce covers #33344's SqlQueryCounter.deadlockOnce so EntityRepositoryGoldenIT becomes a one-line swap. Injection stays in the probe rather than moving into the counter: a counter that also throws is two jobs in one class, and the probe's one-shot claim is already a compareAndSet. 16 unit tests, both guards verified to fail without the code that satisfies them - dropping the predicate gate gives "a matching statement the predicate rejects must not be counted", and replacing the CAS with a check-then-act gives "both threads were past the guard at once ... expected: <1> but was: <2>". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
Review feedback, and correct: forRequests was called by nothing but itself. The unit tests injected predicates through the package-private constructor and SqlTestDecoratorsIT only used the calling-thread ones, so the composed scope - "a request is in flight AND the caller's predicate accepts" - was the one line in these classes with no coverage. It is also the line where a regression is silent: get it wrong and every REST-driven statement is rejected, or every one is accepted, and a test supplying its own predicate would never notice. RequestLatencyContext.startRequest and clearContext are public statics, so the composition is testable without a server. Four tests, two per class: a matching statement outside any request is not counted or claimed, the same statement inside one is, and a caller predicate that rejects still wins while a request is in flight. Each half is independently guarded. Dropping the request check fails with "no request in flight, so there is nothing to attribute the statement to"; dropping the caller predicate fails with "a request is in flight but the caller's predicate rejects this statement". Verified both ways. 20 unit tests total. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
🚦 Removed from the merge queue —
|
manerow
left a comment
There was a problem hiding this comment.
Approving. Test-only change, no production code, and nothing on main regresses: only the package-private constructors changed signature, and every existing caller (SqlTestDecoratorsIT, MultiTeamUserFanOutIT) goes through the public constructors or the 2-arg forRequests, both preserved.
Verified locally: mvn -pl openmetadata-integration-tests test -Dtest='SqlQueryCounterTest,SqlFailureProbeTest,TransactionCounterTest' gives 20 tests, 0 failures. Also checked that deadlockOnce raises the shape DeadlockRetry.isDeadlock actually matches (it walks the cause chain for SQLSTATE 40001 or vendor code 1213), and that calling RequestLatencyContext.startRequest from a unit test is safe (thread-local plus a timer on globalRegistry, no wiring needed, and both new tests clear it in a finally). CI is green across all lanes.
One follow-up that does not block this merge, about the claim that SqlFailureProbe.deadlockOnce makes #33344's call site a one-line swap:
- Scope differs. #33344's
deadlockOnceis request-scoped (RequestLatencyContext.getContext() != null); this one goes through the 3-arg constructor, so it is calling-thread-scoped. Its only known call site,EntityRepositoryGoldenIT:428, drives a PATCH over REST, so the statement runs on a Jetty thread and the probe would never fire. The test would go green without testing the replay. Request-scoping it, or taking the scope as a parameter, or at least saying "on the calling thread" in the javadoc (it currently only says "after the first matching statement") would close that. - That call site also does double duty: it injects and asserts
assertEquals(2, writes.count(), ...).SqlFailureProbehas nocount(), so the swap needs more than one line. SqlQueryCounter.afterFirst(jdbi, fragment, Runnable)is used by #33344 atEntityCacheRecoveryIT:77and is not added here, so that PR still cannot delete its copy outright.
Happy for this to land as is and for the deadlockOnce scope to be settled either here or when #33344 rebases.
Review follow-up from @manerow, and the trap is real. deadlockOnce built its probe through the calling-thread constructor, while the #33344 factory it was meant to replace is request-scoped. Its only call site, EntityRepositoryGoldenIT, drives a PATCH over REST, so the statement runs on a Jetty worker: a calling-thread probe never fires, and the replay test goes green without ever exercising the replay. Silent false pass, in the one place whose job is to prove a deadlock is retried. A convenience that has to guess a scope will keep guessing wrong, so there is no longer one. deadlock() returns the failure shape DeadlockRetry replays and composes with either scope, which makes the mistake impossible to make by accident: new SqlFailureProbe(jdbi, fragment, deadlock()) // this thread SqlFailureProbe.forRequests(jdbi, fragment, deadlock(), mine::match) // a request Two claims in this PR were also wrong and are corrected in the description. The #33344 call site counts as well as injects - assertEquals(2, writes.count()) - and no factory here does both, so the swap is not one line; it nests a counter around a probe. And SqlQueryCounter.afterFirst is still not provided, so #33344 cannot delete its copy outright either. A new test pins the nesting: the probe sits outermost while both are open, closing it hands the logger back to the counter rather than the application, and the chain unwinds to the original. 21 unit tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…-scope-v2' into harshach/it-decorators-predicate-scope-v2
|
Thanks — all three land, and the first one is worse than a nit, so I've fixed it rather than The scope mismatch is a silent false passConfirmed exactly as you describe. #33344's factory is try (var writes = SqlQueryCounter.deadlockOnce(Entity.getJdbi(), "update " + table)) {
patch(path(), "description", "replayed");
assertEquals(2, writes.count(), "One rolled-back write and one committed replay");
}The statement runs on a Jetty worker, so a calling-thread probe never fires and So there is no longer a convenience that guesses a scope. new SqlFailureProbe(jdbi, fragment, deadlock()) // this thread
SqlFailureProbe.forRequests(jdbi, fragment, deadlock(), mine::match) // a requestTaking the scope as a parameter would have worked too, but a factory that cannot pick a scope at all Your other two points were claims of mine that were simply wrongNot a one-line swap. That call site counts and injects, and no factory here does both — the
I've corrected both claims in the PR description. Where the fix is#33642 was already in the merge queue when I pushed, so the branch is locked and I did not dequeue an |
🚦 Removed from the merge queue —
|
|
Folded the
21 unit tests green. CI re-running. |
Review feedback, and correct: assertSame on the SqlLogger chain is wiring, not behaviour, and passes even if delegation stops invoking the inner decorator - the one failure it needed to catch. I had justified it by saying a real StatementContext could not be built here. That was wrong twice over. StatementContext is not final; it has a private constructor that reflection can reach. But the signature is not stable: this module resolves jdbi3-core 3.37.1, whose constructor takes (ConfigRegistry, ExtensionMethod), while 3.47.0 takes a third Type argument. A unit test built on that would break on a minor dependency bump. So the test moves to SqlTestDecoratorsIT, where real statements produce real contexts and no reflection is needed. It now asserts what one statement does to both decorators: the outer probe fires, the inner counter still sees the same statement, and once the probe is spent the counter keeps counting through it. The unit-level wiring assertion is deleted rather than kept alongside. 20 unit tests; the composition case runs in the IT lane. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
#33539 landed SqlQueryCounter on main, and this PR carried its own, so the two collided add/add. This PR's copy is dropped in favour of main's. That is a pure dedup rather than a compromise: TableMetadataReadIT only calls the two-argument forRequests and the public constructor, both of which main's copy has with the same semantics - calling-thread scope for the constructor, "a request is in flight" for forRequests. Nothing here used the three-argument forRequests, deadlockOnce or afterFirst that the dropped copy also carried, so this does not depend on #33642. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Code Review ✅ Approved🟡 Medium risk · Test decorators now scope SQL counting and failure injection per statement. Refactors JDBI test decorators to scope on OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Describe your changes:
Fixes #33641. First in the merge order for #32946 — it unblocks #33344, #33355 and #33362.
#33539 landed the three JDBI test decorators on
main. Three PRs in the epic still add their owncopies of two of them, so all three now fail to merge:
Their copies are not gratuitous. They scope on
Predicate<StatementContext>where the mergedversion scopes on a
BooleanSupplier, and #33344 and #33355 already call the three-argumentforRequestsanddeadlockOnce. Deleting their copies in favour ofmain's would break those callsites. This makes
main's copy the one they already call, so the dedup on rebase is a deletionrather than a rewrite.
It also settles an open review point on #33539. The review there raised that
forRequestswastoo broad — it matches any in-flight request, so a concurrent request running a matching statement
can consume the injection meant for the test. I resolved it then by removing
SqlFailureProbe.forRequests, becauseRequestLatencyContextcarries no test identity and aBooleanSuppliergives the caller nothing to discriminate on. APredicate<StatementContext>does.So
forRequestsreturns — now requiring the caller's predicate rather than matching any request.Injection stays in the probe rather than moving into the counter: a counter that also throws is two
jobs in one class, and the probe's one-shot claim is already a
compareAndSet(whereas #33344'scounter holds that state in plain mutable fields written from whichever thread ran the statement).
Correction (was wrong in the first revision of this description). I originally added
SqlFailureProbe.deadlockOnceand claimed it made #33344's call site a one-line swap. Both halveswere wrong, as @manerow caught in review:
deadlockOncebuilt its probe on the calling thread,while the Fixes 32946: Pin entity repository lifecycle and cache contracts (1/7) #33344 factory it replaces is request-scoped. Its only call site drives a PATCH over
REST, so the statement runs on a Jetty worker — the probe would never fire and
deadlock-replaywould pass without exercising a replay. It is replaced by
deadlock(), aSupplier<RuntimeException>that composes with either scope, so the scope can no longer be pickedwrongly by default.
(
assertEquals(2, writes.count(), …)), and no factory here does both — the migration nests acounter around a probe. A test pins that they compose: the probe sits outermost while both are
open, closing it hands the logger back to the counter rather than the application, and the chain
unwinds to the original.
SqlQueryCounter.afterFirstis also still not provided, so #33344 cannot delete its copy outright —it has one call site and runs an action without failing anything, which does not fit a class named
FailureProbe. Happy to add it under a better name if a reviewer would rather it were shared.Type of change:
High-level design:
Test infrastructure only; no production code. The scope type widens from
BooleanSuppliertoPredicate<StatementContext>on both classes, the existing no-argumentforRequestsis preserved asthe permissive default, and a new overload takes the caller's predicate.
TransactionCounterisuntouched.
Tests:
Use cases covered
than to any request in flight.
DeadlockRetryreplays gets it from the probe.Unit tests
21, all green. Two are new and both were verified to fail without the code that satisfies them:
a matching statement the predicate rejects must not be counted ==> expected: <false> but was: <true>both threads were past the guard at once … expected: <1> but was: <2>The concurrency test is deterministic on purpose — a
CyclicBarrier(2)inside the scope predicateholds both threads within the check-then-set window. Racing threads and hoping for a collision
passed against the unsynchronised version on every run.
Backend integration tests
Not applicable — this is integration-test infrastructure.
SqlTestDecoratorsITonmaincontinuesto cover the Jdbi wiring end to end.
Ingestion integration tests
Not applicable.
Playwright (UI) tests
Not applicable.
Manual testing performed
mvn -pl openmetadata-integration-tests test -Dtest='SqlQueryCounterTest,SqlFailureProbeTest,TransactionCounterTest'— 16 tests, BUILD SUCCESS.mvn spotless:apply -pl openmetadata-integration-tests— clean.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #33641.🤖 Generated with Claude Code
The PR appears safe to merge; no actionable defects or outstanding previous findings remain.
Findings
Summary
This PR improves JDBI test decorators so REST-driven tests can scope counters and failure probes with
Predicate<StatementContext>, adds a reusable deadlock-shaped failure supplier, and verifies decorator composition through observable SQL behavior.Reviews (6) · Last reviewed commit: "Move the composition test to the IT, whe..."