use of io.spine.server.event.EventStore in project core-java by SpineEventEngine.
the class BoundedContextShould method do_not_set_storage_factory_if_EventStore_is_set.
@Test
public void do_not_set_storage_factory_if_EventStore_is_set() {
final EventStore eventStore = mock(EventStore.class);
final BoundedContext bc = BoundedContext.newBuilder().setEventBus(EventBus.newBuilder().setEventStore(eventStore)).build();
assertEquals(eventStore, bc.getEventBus().getEventStore());
}
use of io.spine.server.event.EventStore in project core-java by SpineEventEngine.
the class EmptyEventStoreTest method notAppend.
@Test
@DisplayName("do nothing on `append(Event)`")
void notAppend() {
EventStore store = new EmptyEventStore();
store.append(Event.getDefaultInstance());
assertEmpty(store);
}
use of io.spine.server.event.EventStore in project core-java by SpineEventEngine.
the class ProjectionRepository method catchUp.
/**
* Updates projections from the event stream obtained from {@code EventStore}.
*/
public void catchUp() {
setStatus(Status.CATCHING_UP);
final AllTenantOperation op = new AllTenantOperation(boundedContext.getTenantIndex()) {
private final EventStore eventStore = getBoundedContext().getEventBus().getEventStore();
private final Set<EventFilter> eventFilters = getEventFilters();
@Override
public void run() {
// Get the timestamp of the last event. This also ensures we have the storage.
final Timestamp timestamp = nullToDefault(projectionStorage().readLastHandledEventTime());
final EventStreamQuery query = EventStreamQuery.newBuilder().setAfter(timestamp).addAllFilter(eventFilters).build();
eventStore.read(query, new EventStreamObserver(ProjectionRepository.this));
}
};
op.execute();
completeCatchUp();
logCatchUpComplete();
}
use of io.spine.server.event.EventStore in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method skip_all_the_events_after_catch_up_outdated.
// Due to mockito matcher usage
@SuppressWarnings("unchecked")
@Test
public void skip_all_the_events_after_catch_up_outdated() throws InterruptedException {
// Set up bounded context
final BoundedContext boundedContext = TestBoundedContextFactory.MultiTenant.newBoundedContext();
final int eventsCount = 10;
final EventStore eventStore = boundedContext.getEventBus().getEventStore();
for (int i = 0; i < eventsCount; i++) {
final ProjectId projectId = ProjectId.newBuilder().setId(valueOf(i)).build();
final Message eventMessage = ProjectCreated.newBuilder().setProjectId(projectId).build();
final Event event = createEvent(pack(projectId), eventMessage);
appendEvent(eventStore, event);
}
// Set up repository
final Duration duration = Durations2.nanos(1L);
final ProjectionRepository repository = spy(new ManualCatchupProjectionRepository(boundedContext, duration));
repository.initStorage(storageFactory());
repository.catchUp();
// Check bulk write
verify(repository, never()).store(any(Projection.class));
}
use of io.spine.server.event.EventStore in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method ensureCatchesUpFromEventStorage.
private void ensureCatchesUpFromEventStorage(ProjectionRepository<ProjectId, TestProjection, Project> repo) {
final EventStore eventStore = boundedContext.getEventBus().getEventStore();
final TestEventFactory eventFactory = newEventFactory(PRODUCER_ID);
// Put events into the EventStore.
final ProjectCreated projectCreated = ProjectCreated.newBuilder().setProjectId(ID).build();
final Event projectCreatedEvent = eventFactory.createEvent(projectCreated);
appendEvent(eventStore, projectCreatedEvent);
final TaskAdded taskAdded = TaskAdded.newBuilder().setProjectId(ID).build();
final Event taskAddedEvent = eventFactory.createEvent(taskAdded);
appendEvent(eventStore, taskAddedEvent);
final ProjectStarted projectStarted = ProjectStarted.newBuilder().setProjectId(ID).build();
final Event projectStartedEvent = eventFactory.createEvent(projectStarted);
appendEvent(eventStore, projectStartedEvent);
repo.catchUp();
assertTrue(TestProjection.processed(projectCreated));
assertTrue(TestProjection.processed(taskAdded));
assertTrue(TestProjection.processed(projectStarted));
}
Aggregations