Search in sources :

Example 11 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method perform_bulk_catch_up_if_required.

// Due to mockito matcher usage
@SuppressWarnings("unchecked")
@Test
public void perform_bulk_catch_up_if_required() {
    final ProjectId projectId = ProjectId.newBuilder().setId("mock-project-id").build();
    final Message eventMessage = ProjectCreated.newBuilder().setProjectId(projectId).build();
    final Event event = createEvent(pack(projectId), eventMessage);
    appendEvent(boundedContext.getEventBus().getEventStore(), event);
    // Set up repository
    final Duration duration = Durations2.seconds(10L);
    final ProjectionRepository repository = spy(new ManualCatchupProjectionRepository(boundedContext, duration));
    repository.initStorage(storageFactory());
    repository.catchUp();
    // Check bulk write
    verify(repository).store(any(Collection.class));
    verify(repository, never()).store(any(TestProjection.class));
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Example 12 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method use_id_set_function.

@Test
public void use_id_set_function() {
    final IdSetEventFunction<ProjectId, ProjectCreated> delegateFn = new IdSetEventFunction<ProjectId, ProjectCreated>() {

        @Override
        public Set<ProjectId> apply(ProjectCreated message, EventContext context) {
            return newHashSet();
        }
    };
    final IdSetEventFunction<ProjectId, ProjectCreated> idSetFunction = spy(delegateFn);
    repository().addIdSetFunction(ProjectCreated.class, idSetFunction);
    final Event event = createEvent(PRODUCER_ID, projectCreated());
    repository().dispatch(event);
    final ProjectCreated expectedEventMessage = Events.getMessage(event);
    final EventContext context = event.getContext();
    verify(idSetFunction).apply(eq(expectedEventMessage), eq(context));
}
Also used : EventContext(io.spine.base.EventContext) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) IdSetEventFunction(io.spine.server.entity.idfunc.IdSetEventFunction) ProjectCreated(io.spine.test.projection.event.ProjectCreated) Test(org.junit.Test)

Example 13 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventsShould method have_event_comparator.

@Test
public void have_event_comparator() {
    final Event event1 = createEventOccurredMinutesAgo(120);
    final Event event2 = createEventOccurredMinutesAgo(2);
    final Comparator<Event> comparator = Events.eventComparator();
    assertTrue(comparator.compare(event1, event2) < 0);
    assertTrue(comparator.compare(event2, event1) > 0);
    assertTrue(comparator.compare(event1, event1) == 0);
}
Also used : Event(io.spine.base.Event) Test(org.junit.Test)

Example 14 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventsShould method get_timestamp_from_event.

@Test
public void get_timestamp_from_event() {
    final Event event = createEventWithContext(stringValue);
    assertEquals(context.getTimestamp(), getTimestamp(event));
}
Also used : Event(io.spine.base.Event) Test(org.junit.Test)

Example 15 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventsShould method sort_events_by_time.

@Test
public void sort_events_by_time() {
    final Event event1 = createEventOccurredMinutesAgo(30);
    final Event event2 = createEventOccurredMinutesAgo(20);
    final Event event3 = createEventOccurredMinutesAgo(10);
    final List<Event> sortedEvents = newArrayList(event1, event2, event3);
    final List<Event> eventsToSort = newArrayList(event2, event1, event3);
    sort(eventsToSort);
    assertEquals(sortedEvents, eventsToSort);
}
Also used : Event(io.spine.base.Event) Test(org.junit.Test)

Aggregations

Event (io.spine.base.Event)32 Test (org.junit.Test)14 Message (com.google.protobuf.Message)7 EventContext (io.spine.base.EventContext)4 IntegrationEvent (io.spine.server.integration.IntegrationEvent)4 StringValue (com.google.protobuf.StringValue)3 EventFactory (io.spine.server.command.EventFactory)3 TestEventFactory (io.spine.test.TestEventFactory)3 ProjectId (io.spine.test.projection.ProjectId)3 ProjectCreated (io.spine.test.projection.event.ProjectCreated)3 Duration (com.google.protobuf.Duration)2 Command (io.spine.base.Command)2 EventId (io.spine.base.EventId)2 EventStore (io.spine.server.event.EventStore)2 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 Any (com.google.protobuf.Any)1 Timestamp (com.google.protobuf.Timestamp)1 CommandContext (io.spine.base.CommandContext)1 Events.getMessage (io.spine.base.Events.getMessage)1