Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private static String getUpdateSql(String table, Status status) {
STATUS = '%s'
WHERE
ID = ?
AND COMPLETION_DATE IS NULL
AND (STATUS IS NULL OR STATUS != '%s')
""".formatted(table, status.name(), status.name()));
}
Expand Down Expand Up @@ -418,6 +419,7 @@ public boolean markResubmitted(UUID identifier, Instant instant) {
LAST_RESUBMISSION_DATE = ?
WHERE
ID = ?
AND COMPLETION_DATE IS NULL
AND (STATUS IS NULL OR STATUS != 'RESUBMITTED')
""".formatted(settings.getTable()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,27 @@ void marksPublicationWithNullStatusColumnAsFailed() {
.containsExactly(publication.getIdentifier());
}

@Test // GH-1925
void doesNotResubmitCompletedPublication() {

var publication = createPublication(new TestEvent("completed"));

repository.markCompleted(publication.getIdentifier(), Instant.now());

assertThat(repository.markResubmitted(publication.getIdentifier(), Instant.now())).isFalse();
}

@Test // GH-1925
void doesNotMarkCompletedPublicationFailed() {

var publication = createPublication(new TestEvent("completed"));

repository.markCompleted(publication.getIdentifier(), Instant.now());
repository.markFailed(publication.getIdentifier());

assertThat(repository.findByStatus(Status.FAILED)).isEmpty();
}

/**
* Simulates a publication persisted by a schema version that predates the {@code STATUS} column, i.e. one for
* which the column was never backfilled and is {@literal null} rather than defaulted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class JpaEventPublicationRepository implements EventPublicationRepository {
update DefaultJpaEventPublication p
set p.status = ?1
where p.id = ?2
and p.completionDate is null
and (status is null or status != ?1)
""";

Expand All @@ -163,6 +164,7 @@ class JpaEventPublicationRepository implements EventPublicationRepository {
p.completionAttempts = p.completionAttempts + 1,
p.lastResubmissionDate = ?1
where p.id = ?2
and p.completionDate is null
and (p.status is null or p.status != org.springframework.modulith.events.EventPublication$Status.RESUBMITTED)
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,33 @@ void marksPublicationWithNullStatusColumnAsFailed() {
.containsExactly(publication.getIdentifier());
}

@Test // GH-1925
void doesNotResubmitCompletedPublication() {

var publication = createPublication(new TestEvent("completed"));

repository.markCompleted(publication.getIdentifier(), Instant.now());
em.flush();
em.clear();

assertThat(repository.markResubmitted(publication.getIdentifier(), Instant.now())).isFalse();
}

@Test // GH-1925
void doesNotMarkCompletedPublicationFailed() {

var publication = createPublication(new TestEvent("completed"));

repository.markCompleted(publication.getIdentifier(), Instant.now());
em.flush();
em.clear();

repository.markFailed(publication.getIdentifier());
em.clear();

assertThat(repository.findByStatus(Status.FAILED)).isEmpty();
}

/**
* Simulates a publication persisted by a schema version that predates the {@code status} column, i.e. one for
* which the column was never backfilled and is {@literal null} rather than defaulted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ class Neo4jEventPublicationRepository implements EventPublicationRepository {

private static final Statement UPDATE_STATUS_STATEMENT = match(EVENT_PUBLICATION_NODE)
.where(EVENT_PUBLICATION_NODE.property(ID).eq(parameter(ID)))
.and(EVENT_PUBLICATION_NODE.property(COMPLETION_DATE).isNull())
.and(EVENT_PUBLICATION_NODE.property(STATUS).isNull()
.or(EVENT_PUBLICATION_NODE.property(STATUS).ne(parameter(STATUS))))
.set(EVENT_PUBLICATION_NODE.property(STATUS).to(parameter(STATUS)))
.build();

private static final Statement RESUBMIT_STATEMENT = match(EVENT_PUBLICATION_NODE)
.where(EVENT_PUBLICATION_NODE.property(ID).eq(parameter(ID)))
.and(EVENT_PUBLICATION_NODE.property(COMPLETION_DATE).isNull())
.and(EVENT_PUBLICATION_NODE.property(STATUS).isNull()
.or(EVENT_PUBLICATION_NODE.property(STATUS).ne(literalOf(Status.RESUBMITTED.name()))))
.set(EVENT_PUBLICATION_NODE.property(STATUS).to(parameter(STATUS)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,27 @@ void marksPublicationWithNullStatusPropertyAsFailed() {
.containsExactly(publication.getIdentifier());
}

@Test // GH-1925
void doesNotResubmitCompletedPublication() {

var publication = createPublication(new TestEvent("completed"));

repository.markCompleted(publication.getIdentifier(), Instant.now());

assertThat(repository.markResubmitted(publication.getIdentifier(), Instant.now())).isFalse();
}

@Test // GH-1925
void doesNotMarkCompletedPublicationFailed() {

var publication = createPublication(new TestEvent("completed"));

repository.markCompleted(publication.getIdentifier(), Instant.now());
repository.markFailed(publication.getIdentifier());

assertThat(repository.findByStatus(EventPublication.Status.FAILED)).isEmpty();
}

/**
* Simulates a publication persisted by a schema version that predates the {@code status} property, i.e. one for
* which the property is missing rather than defaulted.
Expand Down
Loading