Skip to content

Commit

Permalink
ima
Browse files Browse the repository at this point in the history
  • Loading branch information
uweschaefer committed May 7, 2024
2 parents 84c4ad1 + 08a3913 commit 09e6f49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ public void onFastForward(@NonNull FactStreamPosition factIdToFfwdTo) {
if (projection instanceof FactStreamPositionAware) {
((FactStreamPositionAware) projection).factStreamPosition(factIdToFfwdTo);
}
positionOfLastFactApplied.set(factIdToFfwdTo);

// only persist ffwd if we ever had a state or applied facts in this catchup
if (stateOrNull != null || positionOfLastFactApplied.get() != null) {
positionOfLastFactApplied.set(factIdToFfwdTo);
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@
import org.factcast.factus.snapshot.SnapshotSerializerSupplier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.*;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
@Tag("integration") // technically unit, but it takes some time due to waiting
class FactusImplTest {

@Mock private FactCast fc;
Expand Down Expand Up @@ -1423,6 +1421,33 @@ void createSnapshot(SnapshotProjection projection, UUID state) {
@SuppressWarnings("resource")
@Nested
class WhenCatchingUp {
@Test
@SneakyThrows
void returnsFactIdOfFastForward() {
Projector pro = mock(Projector.class);
Subscription sub = mock(Subscription.class);
FactSpec spec1 = FactSpec.from(NameEvent.class);
CompletableFuture<Void> cf = new CompletableFuture<>();

Fact f = new TestFact();
UUID id = f.id();
FactStreamPosition pos = FactStreamPosition.of(id, 42L);

when(ehFactory.create(any())).thenReturn(pro);
when(fc.subscribe(any(SubscriptionRequest.class), any(FactObserver.class)))
.thenAnswer(
i -> {
FactObserver fo = i.getArgument(1);
fo.onFastForward(pos);
return sub;
});
when(pro.createFactSpecs()).thenReturn(Lists.newArrayList(spec1));

SomeSnapshotProjection p = new SomeSnapshotProjection();
UUID ret = underTest.catchupProjection(p, UUID.randomUUID(), null);

Assertions.assertThat(ret).isNotNull().isEqualTo(id);
}

@Test
@SneakyThrows
Expand Down Expand Up @@ -1453,7 +1478,7 @@ void returnsFactIdOfLastFactApplied() {
}

@Test
void returnsFactIdForwardTarget() {
void returnsNoFactIdForwardTarget() {

Projector pro = mock(Projector.class);
Subscription sub = mock(Subscription.class);
Expand All @@ -1476,7 +1501,7 @@ void returnsFactIdForwardTarget() {
SomeSnapshotProjection p = new SomeSnapshotProjection();
UUID ret = underTest.catchupProjection(p, null, null);

Assertions.assertThat(ret).isNotNull().isEqualTo(id);
Assertions.assertThat(ret).isNull();
}
}
}
Expand Down

0 comments on commit 09e6f49

Please sign in to comment.