Skip to content

GH-1855 - Implement status lookup for MongoDB event publications - #1856

Closed
azunox wants to merge 2 commits into
spring-projects:mainfrom
azunox:fix/mongodb-event-status-query
Closed

azunox wants to merge 2 commits into
spring-projects:mainfrom
azunox:fix/mongodb-event-status-query

Conversation

@azunox

@azunox azunox commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Closes #1855.

The staleness monitor uses EventPublicationRepository.findByStatus(Status) to locate event publications in PUBLISHED, PROCESSING, and RESUBMITTED states before marking stale publications as failed.

MongoDbEventPublicationRepository did not override this method and therefore relied on the interface's default implementation, which always returns an empty list. As a result, stale MongoDB-backed event publications could not be discovered, marked as FAILED, or subsequently resubmitted.

This change implements findByStatus(Status) for the MongoDB repository by querying the existing status field. It reuses defaultQuery(…) and readMapped(…) to retain the repository's existing sorting and document-to-domain mapping behavior.

The existing status lifecycle test has been extended to verify both countByStatus(…) and findByStatus(…) across the following transitions:

  • PUBLISHED after publication creation
  • FAILED after markFailed(…)
  • RESUBMITTED after markResubmitted(…)

For each transition, the test verifies that exactly one publication is returned for the current status and no publications are returned for the other statuses.

The targeted MongoDB repository test suite was executed with Testcontainers:

./mvnw -B \
  -pl spring-modulith-events/spring-modulith-events-mongodb \
  -am \
  -Dtest=MongoDbEventPublicationRepositoryTest \
  -Dsurefire.failIfNoSpecifiedTests=false \
  test

All 55 tests passed with no failures or errors.

…blications.

Signed-off-by: 김우성 <azunox9@gmail.com>
…ng status lookup.

Signed-off-by: 김우성 <azunox9@gmail.com>
@azunox

azunox commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

I found two completion-related edge cases during a follow-up review of this PR: completed publications could still match a non-completed status, and findByStatus(COMPLETED) did not read from the archive collection in ARCHIVE mode.

The implementation now addresses both cases:

  • Completion by publication ID or by event and target sets both completionDate and COMPLETED. The archive operation also persists COMPLETED.
  • Status lookup and counting use the same completion-aware criteria. Non-completed statuses exclude documents with a completion date, and completed status queries use the appropriate collection while preserving publication-date ordering.
  • Previously stored documents with a completion date and an outdated status are treated as completed without requiring a data migration. They are also excluded from failed-publication lookup.
  • markFailed and markResubmitted only update incomplete documents. This prevents a publication completed after candidate lookup from being changed back to failed or claimed for resubmission by that stale candidate list.

Regression coverage now includes all five statuses and result ordering, completion by both entry points, legacy completed documents, deterministic lookup-then-completion interleavings, and the real registry's stale-publication-to-resubmission flow. The latter verifies that stale incomplete publications are resubmitted while completed publications and recently resubmitted publications are excluded.

Validation used the MongoDB Testcontainers-backed repository test class across UPDATE, DELETE, and ARCHIVE:

./mvnw -B -pl spring-modulith-events/spring-modulith-events-mongodb -am \
  -Dtest=MongoDbEventPublicationRepositoryTest \
  -Dsurefire.failIfNoSpecifiedTests=false test

Result: 94 passed, 2 skipped, 0 failures, 0 errors across 96 test cases. The two skips are the existing UPDATE-only cleanup test under the DELETE and ARCHIVE configurations. The full project test suite was not run.

odrotbohm pushed a commit that referenced this pull request Sep 10, 2026
Preserve completed MongoDB publications during status lookup.

Original pull request: GH-1856
Signed-off-by: 김우성 <azunox9@gmail.com>
odrotbohm pushed a commit that referenced this pull request Sep 10, 2026
Preserve completed MongoDB publications during status lookup.

Original pull request: GH-1856
Signed-off-by: 김우성 <azunox9@gmail.com>
odrotbohm pushed a commit that referenced this pull request Sep 10, 2026
Preserve completed MongoDB publications during status lookup.

Original pull request: GH-1856
Signed-off-by: 김우성 <azunox9@gmail.com>
@odrotbohm

Copy link
Copy Markdown
Member

That's merged, polished, and back-ported. Please give the snapshots a try.

@odrotbohm odrotbohm closed this Sep 10, 2026
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.

Unable to mark events as FAILED in MongoDB event registry via the staleness monitor

2 participants