Search in sources :

Example 1 with EventStore

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());
}
Also used : EventStore(io.spine.server.event.EventStore) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 2 with EventStore

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);
}
Also used : EventStore(io.spine.server.event.EventStore) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with EventStore

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();
}
Also used : EventStore(io.spine.server.event.EventStore) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) EventStreamQuery(io.spine.server.event.EventStreamQuery) Timestamp(com.google.protobuf.Timestamp) AllTenantOperation(io.spine.server.tenant.AllTenantOperation)

Example 4 with EventStore

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));
}
Also used : EventStore(io.spine.server.event.EventStore) Message(com.google.protobuf.Message) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) MultiTenant.newBoundedContext(io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext) BoundedContext(io.spine.server.BoundedContext) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Example 5 with EventStore

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));
}
Also used : EventStore(io.spine.server.event.EventStore) TestEventFactory(io.spine.test.TestEventFactory) ProjectStarted(io.spine.test.projection.event.ProjectStarted) TaskAdded(io.spine.test.projection.event.TaskAdded) Event(io.spine.base.Event) ProjectCreated(io.spine.test.projection.event.ProjectCreated)

Aggregations

EventStore (io.spine.server.event.EventStore)7 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 Event (io.spine.base.Event)2 BoundedContext (io.spine.server.BoundedContext)2 Test (org.junit.Test)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Duration (com.google.protobuf.Duration)1 Message (com.google.protobuf.Message)1 Timestamp (com.google.protobuf.Timestamp)1 EventStreamQuery (io.spine.server.event.EventStreamQuery)1 AllTenantOperation (io.spine.server.tenant.AllTenantOperation)1 TestEventFactory (io.spine.test.TestEventFactory)1 ProjectId (io.spine.test.projection.ProjectId)1 ProjectCreated (io.spine.test.projection.event.ProjectCreated)1 ProjectStarted (io.spine.test.projection.event.ProjectStarted)1 TaskAdded (io.spine.test.projection.event.TaskAdded)1 MultiTenant.newBoundedContext (io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext)1 Set (java.util.Set)1