GH-1056 - Switch to object identity comparison when looking up event publications.
We now rather use an object identity comparison in TargetEventPublication.isAssociatedWith(…) instead of an ….equals(…) as that would return the wrong publication for identical events.
This commit is contained in:
@@ -75,7 +75,7 @@ public interface TargetEventPublication extends Completable, org.springframework
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the {@link TargetEventPublication} is associated with the given event and
|
||||
* Returns whether the {@link TargetEventPublication} is associated with the given event instance and
|
||||
* {@link PublicationTargetIdentifier}.
|
||||
*
|
||||
* @param event must not be {@literal null}.
|
||||
@@ -87,6 +87,6 @@ public interface TargetEventPublication extends Completable, org.springframework
|
||||
Assert.notNull(event, "Event must not be null!");
|
||||
Assert.notNull(identifier, "PublicationTargetIdentifier must not be null!");
|
||||
|
||||
return isIdentifiedBy(identifier) && getEvent().equals(event);
|
||||
return isIdentifiedBy(identifier) && getEvent() == event;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,24 @@ class DefaultEventPublicationRegistryUnitTests {
|
||||
assertThat(registry.getPublicationsInProgress()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // GH-1056
|
||||
void obtainsCorrectInProgressPublicationForIdenticalEvents() {
|
||||
|
||||
var inProgress = createRegistry(Instant.now()).getPublicationsInProgress();
|
||||
|
||||
var identifier = PublicationTargetIdentifier.of("id");
|
||||
|
||||
var firstEvent = new SampleEvent("Foo");
|
||||
var secondEvent = new SampleEvent("Foo");
|
||||
|
||||
var first = inProgress.register(TargetEventPublication.of(firstEvent, identifier));
|
||||
var second = inProgress.register(TargetEventPublication.of(secondEvent, identifier));
|
||||
|
||||
assertThat(inProgress.getPublication(firstEvent, identifier)).containsSame(first);
|
||||
assertThat(inProgress.getPublication(secondEvent, identifier)).containsSame(second);
|
||||
|
||||
}
|
||||
|
||||
private DefaultEventPublicationRegistry createRegistry(Instant instant) {
|
||||
|
||||
var clock = Clock.fixed(instant, ZoneId.systemDefault());
|
||||
@@ -94,4 +112,6 @@ class DefaultEventPublicationRegistryUnitTests {
|
||||
throw new IllegalStateException();
|
||||
};
|
||||
}
|
||||
|
||||
record SampleEvent(String payload) {}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,19 @@ class TargetEventPublicationUnitTests {
|
||||
assertThat(publication.isCompleted()).isFalse();
|
||||
assertThat(publication.getCompletionDate()).isNotPresent();
|
||||
}
|
||||
|
||||
@Test // GH-1056
|
||||
void isOnlyAssociatedWithTheVerySameEventInstance() {
|
||||
|
||||
var first = new SampleEvent("Foo");
|
||||
var second = new SampleEvent("Foo");
|
||||
|
||||
var identifier = PublicationTargetIdentifier.of("id");
|
||||
var publication = TargetEventPublication.of(first, identifier);
|
||||
|
||||
assertThat(publication.isAssociatedWith(first, identifier)).isTrue();
|
||||
assertThat(publication.isAssociatedWith(second, identifier)).isFalse();
|
||||
}
|
||||
|
||||
record SampleEvent(String payload) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user