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));
}
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));
}
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);
}
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));
}
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);
}
Aggregations