Skip to content

Add RequireServerVersion annotation for tests - #3939

Merged
sehrope merged 3 commits into
pgjdbc:masterfrom
sehrope:feat-require-server-version-annotation
Feb 24, 2026
Merged

sehrope merged 3 commits into
pgjdbc:masterfrom
sehrope:feat-require-server-version-annotation

Conversation

@sehrope

@sehrope sehrope commented Feb 14, 2026

Copy link
Copy Markdown
Member

Three commits here which:

  • Add a new @RequireServerVersion annotation for tests that allows declaring the applicable server versions.
  • Replaces the @DisabledIfServerVersionBelow and @DisabledIfServerVersionGreater usage with @RequireServerVersion
  • Removes the unused annotations

Main driver for this was trying to understand which test is running when. The double negative for the annotation vs the check makes it confusing (e.g., it runs when it's not disabled and that is driven by the version being below...).

It's also ambiguous if something like "Greater than 10" really means greater than or equal 10.0.

The new approach positive affirms the situations where we want the thing to run with annotation args for:

  • lt - Less than
  • lte - Less than or equal
  • gt - Greater than
  • gte - Greater than or equal

I'd expect that lt and gte are going to be the most useful. The "less than" makes sense if you want all versions older than X (where presumably it breaks). And "greater than or equal" makes sense when X is the first version that supports a given feature that is being tested. Ex:

@@ -297,7 +297,7 @@ class LogicalReplicationStatusTest {
    * Test fail on PG version 9.4.5 because postgresql have bug.
    */
   @Test
-  @DisabledIfServerVersionBelow("9.4.8")
+  @RequireServerVersion(gte = "9.4.8")
   void applyLocationDoNotDependOnFlushLocation() throws Exception {
     PGConnection pgConnection = (PGConnection) replicationConnection;

Note that the old @DisabledIfServerVersionGreater("19") name implied a > check, but its implementation actually used >=, disabling the test for version 19 and above. The migration to @RequireServerVersion(lt = "19") preserves that existing runtime behavior while making the boundary semantics explicit.

One minor improvement to the old approach was caching the server response in the junit context. That shaves a connection open / close per annotation call. I doubt it's meaningfully different (24 uses of the annotation times 10ms per connection rounds to nothing) but nice to have an example of that in the test code. It may be useful somewhere else too.

@vlsi

vlsi commented Feb 14, 2026

Copy link
Copy Markdown
Member

@sehrope
sehrope force-pushed the feat-require-server-version-annotation branch from 9061529 to 5794e33 Compare February 14, 2026 21:39
@sehrope

sehrope commented Feb 14, 2026

Copy link
Copy Markdown
Member Author

Renamed to @EnabledForServerVersionRange. I kept it positive (i.e. "EnabledFor" v.s. "DisabledFor") as the whole point is that it's easier to reason about what it's doing when you don't have to double negate it.

@vlsi

vlsi commented Feb 14, 2026

Copy link
Copy Markdown
Member

EnabledFor v.s. DisabledFor

It might be reasonable to have both.

@davecramer

Copy link
Copy Markdown
Member

EnabledFor v.s. DisabledFor

It might be reasonable to have both.

I agree, It's plain to say disabled for.

@sehrope

sehrope commented Feb 16, 2026

Copy link
Copy Markdown
Member Author

Do you mean add @DisabledForServerVersionRange (and it's condition handler) with nothing using them as an option for the future? Or replace the @EnabledForServerVersionRange with @DisabledForServerVersionRange?

@vlsi

vlsi commented Feb 16, 2026

Copy link
Copy Markdown
Member

I mean we could add DisabledForServerVersionRange either now (even if it not used) or later when it would be helpful.
Having both at the same time might be helpful for different cases.

@davecramer

Copy link
Copy Markdown
Member

@sehrope are we waiting for something? Might as well merge this

@vlsi vlsi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a clear improvement. I post several comments, however, feel free to decide if you want to address them or not.

The PR title and description refer to @RequireServerVersion but the actual implementation uses @EnabledForServerVersionRange. The title should be updated to match.

@vlsi

vlsi commented Feb 23, 2026

Copy link
Copy Markdown
Member

For reference, JUnit has both @DisabledForJreRange and @EnabledForJreRange because their min and max are always inclusive, so they need two annotations to distinguish between less than and less or equal than.

However, if we allow minInclusive / maxInclusive customization (or the current lt/lte/gt/gte), we don't really need a counterpart @Disabled... annotation.

@sehrope

sehrope commented Feb 23, 2026

Copy link
Copy Markdown
Member Author

Was mostly done addressing the feedback but didn't get a chance yet to finish testing the changes.

Snowed in for the day so figure will get to wrapping it up by this afternoon.

@sehrope
sehrope force-pushed the feat-require-server-version-annotation branch from 5794e33 to 615c7c0 Compare February 23, 2026 21:49
@sehrope

sehrope commented Feb 23, 2026

Copy link
Copy Markdown
Member Author

Rebased and force pushed. Adds @DisabledForServerVersionRange as well (with no usage yet but ready if someone wants to use it).

Added a base parent for both as the majority of the version related code is the same. Each just defines how it matches and whether it's negative or positive result.

Also includes checks that:

  • At least one of lt / lte / gte / gt is populated
  • Both lt / lte cannot be populated
  • Both gt / gte cannot be populated

To unify the code both are implemented by deciding if we match, and then returning either the enabled or disabled result depending on the annotation. Note that the "matches" logic for the disabled annotation is backwards. If it matches, the test is disabled.

The response message is slightly worse than before for the enabled annotation as we only say whether we did not match at all (previously we would explicitly say which of the lt / lte / gte / gt clauses was violated). But that was done because the same approach does not work for the disabled annotation and wanted to keep the code consistent. If someone is investigating can always look at the actual annotations anyway.

I'll merge this tomorrow if there's nothing new.

@sehrope
sehrope merged commit 615c7c0 into pgjdbc:master Feb 24, 2026
19 checks passed
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.

3 participants