Skip to content

Commit 015318c

Browse files
BK202503odrotbohm
authored andcommitted
GH-1683 - Return persisted status from JpaEventPublicationAdapter.getStatus().
Previously, the JPA adapter derived the status from `completionDate` alone, returning either COMPLETED or PUBLISHED. As a result, publications that were marked FAILED (or RESUBMITTED) by `markFailed` / `markResubmitted` — both of which already write the correct value into the `status` column — appear as PUBLISHED when read back through `getStatus()`. Mirror the JdbcEventPublicationRepositoryV2 adapter: return the persisted `status` when set, falling back to the previous derivation (with PROCESSING as the default, matching the JPA entity's own constructor) when older rows have a null status column. The added integration test demonstrates the bug — without the fix it returns PUBLISHED after `markFailed` — and clears the persistence context between the JPQL update and the re-read so the test loads a fresh entity. Signed-off-by: BK202503 <199436087+BK202503@users.noreply.github.com> Original pull request: GH-1714.
1 parent 976e936 commit 015318c

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,12 @@ public void markCompleted(Instant instant) {
617617
*/
618618
@Override
619619
public Status getStatus() {
620-
return publication.completionDate != null ? Status.COMPLETED : Status.PUBLISHED;
620+
621+
if (publication.status != null) {
622+
return publication.status;
623+
}
624+
625+
return publication.completionDate != null ? Status.COMPLETED : Status.PROCESSING;
621626
}
622627

623628
/*

spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,26 @@ void looksUpFailedPublicationWithReferenceDate() throws Exception {
448448
.containsExactly(publication.getIdentifier());
449449
}
450450

451+
@Test // GH-1683
452+
void exposesPersistedStatusOnReload() {
453+
454+
var event = new TestEvent("first");
455+
var publication = createPublication(event);
456+
457+
repository.markFailed(publication.getIdentifier());
458+
459+
// markFailed issues a JPQL update; clear the persistence context so the
460+
// next query loads a fresh entity from the database rather than the
461+
// cached, stale version.
462+
em.flush();
463+
em.clear();
464+
465+
var reloaded = repository.findFailedPublications(FailedCriteria.ALL.withItemsToRead(10));
466+
467+
assertThat(reloaded).hasSize(1);
468+
assertThat(reloaded.get(0).getStatus()).isEqualTo(Status.FAILED);
469+
}
470+
451471
private List<JpaEventPublication> getIncompletePublications() {
452472
return em.createQuery("select p from DefaultJpaEventPublication p", JpaEventPublication.class).getResultList();
453473
}

0 commit comments

Comments
 (0)