Skip to content

SWATCH-3246: fix subscription configuration properties and add subscription sync component tests#6243

Merged
Sgitario merged 2 commits into
mainfrom
jcarvaja/SWATCH-3246
Jun 10, 2026
Merged

SWATCH-3246: fix subscription configuration properties and add subscription sync component tests#6243
Sgitario merged 2 commits into
mainfrom
jcarvaja/SWATCH-3246

Conversation

@Sgitario

@Sgitario Sgitario commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Jira issue: SWATCH-3246

## Changes
The problem is that in clowdapp.yaml, we use SUBSCRIPTION_IGNORE_EXPIRED_OLDER_THAN=2M and SUBSCRIPTION_IGNORE_STARTING_LATER_THAN=2M.
In Spring, these properties standed for 2 months because it uses a custom duration parser, but in Quarkus, 2M stands for 2 minutes.
The fix is to represent the duration in days: 60d.

Testing

Added four scenarios to extend our coverage for the subscription sync scenario:

  • subscriptions-sync-TC003 - Empty upstream org subscription list
  • subscriptions-sync-TC004 - Upstream org subscription search failure
  • subscriptions-sync-TC005 - Subscription missing from subscription search list
  • subscriptions-sync-TC006 - Expired and replacement both returned from subscription search
  • subscriptions-sync-TC007 - Subscription filtered because upstream start date is null
  • subscriptions-sync-TC008 - Subscription filtered because upstream start date is too far in the future

Summary by CodeRabbit

Release Notes

  • New Features

    • Added date-range filtering capability for SKU capacity queries.
  • Tests

    • Expanded subscription synchronization test coverage with six new scenarios covering reconciliation, search failures, subscription replacements, and edge cases.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 62479193-4c86-4c2f-b7d5-23e6e05d5c49

📥 Commits

Reviewing files that changed from the base of the PR and between 177dac1 and 26a0e9b.

📒 Files selected for processing (5)
  • swatch-contracts/TEST_PLAN.md
  • swatch-contracts/ct/java/api/ContractsSwatchService.java
  • swatch-contracts/ct/java/api/SearchApiStubs.java
  • swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java
  • swatch-contracts/deploy/clowdapp.yaml
✅ Files skipped from review due to trivial changes (2)
  • swatch-contracts/deploy/clowdapp.yaml
  • swatch-contracts/TEST_PLAN.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • swatch-contracts/ct/java/api/ContractsSwatchService.java
  • swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java
  • swatch-contracts/ct/java/api/SearchApiStubs.java

📝 Walkthrough

Walkthrough

This PR extends the swatch-contracts test suite with comprehensive coverage for subscription synchronization and capacity reporting. It introduces a capacity-query API overload supporting time-range parameters, Wiremock stubs for mocking upstream search responses, and six new contract tests that validate reconciliation behavior and daily capacity calculations across various upstream state scenarios.

Changes

Subscription Sync Testing

Layer / File(s) Summary
Capacity Query API Enhancement
swatch-contracts/ct/java/api/ContractsSwatchService.java
New 4-argument getSkuCapacityByProductIdForOrg overload accepts optional beginning and ending timestamps; the existing 2-argument method delegates to it with null parameters.
Subscription Search Stubbing
swatch-contracts/ct/java/api/SearchApiStubs.java
stubSearchSubscriptionsByOrgId and stubSearchSubscriptionsByOrgIdFailure helpers register Wiremock mappings to mock upstream subscription search responses by organization, supporting both successful (200/JSON) and failure (custom status) cases.
Test Framework Setup & Fixtures
swatch-contracts/deploy/clowdapp.yaml, swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java (imports/constants/fixtures)
Deployment config sets ignore-window defaults to 60 days; test constants and static imports define date ranges; subscription fixture builders create and persist test subscriptions with stubbed offerings; sync-trigger helpers produce Kafka messages and stage upstream responses.
Capacity Reporting & Verification Helpers
swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java (helpers)
Capacity report fetching, Awaitility-based subscription polling, daily SOCKETS capacity assertion helpers with tolerance handling, and per-day lookup utilities to extract expected socket values from capacity snapshots.
Test Cases & Documentation
swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java (TC003–TC008), swatch-contracts/TEST_PLAN.md
Six new test scenarios validating subscription reconciliation (empty search, search failure, replacement-only, expired+replacement, null start date, far-future start date); test plan documents expected storage and capacity outcomes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • TommasoLencioni
  • kartikshahc
  • TrayvonMcKnight
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main changes: fixing subscription configuration properties (2M → 60d) and adding subscription sync component tests.
Description check ✅ Passed The PR description explains the issue (2M vs 2 minutes), provides the fix (60d), and lists all six test scenarios added, but lacks testing execution details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jcarvaja/SWATCH-3246

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

⛏️ Workflow Run

🧹 Checkstyle

🧪 JUnit

TestsPassed ✅Skipped ⚠️Failed
JUnit Test Report2191 ran2185 passed6 skipped0 failed
Details
TestResult
No test annotations available

@Sgitario Sgitario changed the title SWATCH-3246: add subscription sync reconcile component tests SWATCH-3246: fix subscription configuration properties and add subscription sync reconcile component tests Jun 10, 2026
@Sgitario Sgitario changed the title SWATCH-3246: fix subscription configuration properties and add subscription sync reconcile component tests SWATCH-3246: fix subscription configuration properties and add subscription sync component tests Jun 10, 2026
@Sgitario Sgitario force-pushed the jcarvaja/SWATCH-3246 branch from 7696725 to 177dac1 Compare June 10, 2026 07:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java (1)

159-159: 💤 Low value

Consider referencing the configuration value or adding a clarifying comment.

The hardcoded 61 assumes SUBSCRIPTION_IGNORE_STARTING_LATER_THAN is configured to 60 days. If that configuration changes, this test boundary won't automatically adjust.

💡 Optional improvement

Add a comment to explain the magic number:

     Subscription subscription = givenExistingSubscription(ACTIVE_SUBSCRIPTION_START, REPORT_END);
-    OffsetDateTime farFutureStart = clock.now().plusDays(61);
+    // 61 days exceeds SUBSCRIPTION_IGNORE_STARTING_LATER_THAN (60d) threshold
+    OffsetDateTime farFutureStart = clock.now().plusDays(61);
     Subscription upstreamFarFutureStart =
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java` at line
159, Test uses a magic number (61) for the future offset which assumes
SUBSCRIPTION_IGNORE_STARTING_LATER_THAN is 60 days; update the test so
farFutureStart is computed from the authoritative configuration (referencing the
SUBSCRIPTION_IGNORE_STARTING_LATER_THAN constant or config accessor) instead of
hardcoding 61, or if that isn't feasible add a clarifying comment next to the
farFutureStart assignment noting it is intentionally one day past
SUBSCRIPTION_IGNORE_STARTING_LATER_THAN to test the boundary, referencing
clock.now() and SUBSCRIPTION_IGNORE_STARTING_LATER_THAN in the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@swatch-contracts/TEST_PLAN.md`:
- Around line 907-909: Update the test plan to use the correct HTTP method for
the subscriptions sync endpoint: change the described request from PUT to POST
for /api/swatch-contracts/internal/rpc/subscriptions/sync; reference the OpenAPI
operation (post in openapi.yaml) and the implementation symbol
ContractsSwatchService.syncAllSubscriptions() which calls
.post(SYNC_ALL_SUBSCRIPTIONS_ENDPOINT) to ensure the documentation matches the
code.

---

Nitpick comments:
In `@swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java`:
- Line 159: Test uses a magic number (61) for the future offset which assumes
SUBSCRIPTION_IGNORE_STARTING_LATER_THAN is 60 days; update the test so
farFutureStart is computed from the authoritative configuration (referencing the
SUBSCRIPTION_IGNORE_STARTING_LATER_THAN constant or config accessor) instead of
hardcoding 61, or if that isn't feasible add a clarifying comment next to the
farFutureStart assignment noting it is intentionally one day past
SUBSCRIPTION_IGNORE_STARTING_LATER_THAN to test the boundary, referencing
clock.now() and SUBSCRIPTION_IGNORE_STARTING_LATER_THAN in the comment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ff863466-ca68-43bf-8d65-029335c8ccce

📥 Commits

Reviewing files that changed from the base of the PR and between 7696725 and 177dac1.

📒 Files selected for processing (8)
  • swatch-contracts/TEST_PLAN.md
  • swatch-contracts/ct/java/api/ContractsSwatchService.java
  • swatch-contracts/ct/java/api/SearchApiStubs.java
  • swatch-contracts/ct/java/domain/Offering.java
  • swatch-contracts/ct/java/domain/Product.java
  • swatch-contracts/ct/java/domain/Subscription.java
  • swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java
  • swatch-contracts/deploy/clowdapp.yaml
✅ Files skipped from review due to trivial changes (1)
  • swatch-contracts/deploy/clowdapp.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
  • swatch-contracts/ct/java/domain/Offering.java
  • swatch-contracts/ct/java/domain/Product.java
  • swatch-contracts/ct/java/domain/Subscription.java
  • swatch-contracts/ct/java/api/SearchApiStubs.java

Comment thread swatch-contracts/TEST_PLAN.md Outdated
@Sgitario Sgitario force-pushed the jcarvaja/SWATCH-3246 branch from 177dac1 to 42b34ae Compare June 10, 2026 07:34

@Mantzounis Mantzounis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: I noticed the additions in domain are not called by any tests, what is the reason for adding them

Comment thread swatch-contracts/ct/java/tests/SubscriptionsSyncComponentTest.java
@Sgitario

Copy link
Copy Markdown
Collaborator Author

question: I noticed the additions in domain are not called by any tests, what is the reason for adding them

I had thought to keep those methods because it was very useful during the investigation, but I'm fine removing them, we can always add it back when it's really used.

@Sgitario Sgitario force-pushed the jcarvaja/SWATCH-3246 branch from 42b34ae to 26a0e9b Compare June 10, 2026 08:25
@Sgitario Sgitario requested a review from Mantzounis June 10, 2026 08:25
@Mantzounis

Copy link
Copy Markdown
Contributor

@Sgitario I'm fine with keeping them there if they are useful for debugging but we should document the decision in a comment to remember its intentional

@Sgitario

Copy link
Copy Markdown
Collaborator Author

@Sgitario I'm fine with keeping them there if they are useful for debugging but we should document the decision in a comment to remember its intentional

no problem, just removed it. we can always add it back, it's not super complicated.

@Mantzounis Mantzounis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks for the updates! lgtm.

@swatch-ci

Copy link
Copy Markdown
Collaborator

IQE Tests: PASSED -- bonfire-integration-tests-pipelinerun-csjpj

  • 336 tests ran in 47.1 min
  • 331 passed, 0 failed, 5 skipped
  • IQE image: quay.io/cloudservices/iqe-tests:rhsm-subscriptions

@Sgitario Sgitario merged commit cabdee2 into main Jun 10, 2026
39 checks passed
@Sgitario Sgitario deleted the jcarvaja/SWATCH-3246 branch June 10, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants