use of io.spine.base.Event in project core-java by SpineEventEngine.
the class EventPredicatesShould method verify_if_an_event_is_within_time_range.
@Test
public void verify_if_an_event_is_within_time_range() {
final Event event = EventsShould.createEventOccurredMinutesAgo(5);
assertTrue(isBetween(minutesAgo(10), minutesAgo(1)).apply(event));
assertFalse(isBetween(minutesAgo(2), minutesAgo(1)).apply(event));
}
use of io.spine.base.Event in project core-java by SpineEventEngine.
the class ProcessManagerRepository method dispatchCommand.
/**
* Dispatches the command to a corresponding process manager.
*
* <p>If there is no stored process manager with such an ID,
* a new process manager is created and stored after it handles the passed command.
*
* @param envelope a request to dispatch
* @see CommandHandlingEntity#dispatchCommand(CommandEnvelope)
*/
@Override
public void dispatchCommand(CommandEnvelope envelope) {
final Message commandMessage = envelope.getMessage();
final CommandContext context = envelope.getCommandContext();
final CommandClass commandClass = envelope.getMessageClass();
checkCommandClass(commandClass);
final I id = getIdFromCommandMessage.apply(commandMessage, context);
final P manager = findOrCreate(id);
final ProcManTransaction<?, ?, ?> tx = beginTransactionFor(manager);
final List<Event> events = manager.dispatchCommand(envelope);
store(manager);
tx.commit();
postEvents(events);
}
use of io.spine.base.Event in project core-java by SpineEventEngine.
the class CommandHandlerMethod method toEvents.
public static List<Event> toEvents(final Any producerId, @Nullable final Version version, final List<? extends Message> eventMessages, final CommandEnvelope envelope) {
checkNotNull(producerId);
checkNotNull(eventMessages);
checkNotNull(envelope);
final EventFactory eventFactory = EventFactory.newBuilder().setCommandId(envelope.getCommandId()).setProducerId(producerId).setMaxEventCount(eventMessages.size()).setCommandContext(envelope.getCommandContext()).build();
return Lists.transform(eventMessages, new Function<Message, Event>() {
@Override
public Event apply(@Nullable Message eventMessage) {
if (eventMessage == null) {
return Event.getDefaultInstance();
}
final Event result = eventFactory.createEvent(eventMessage, version);
return result;
}
});
}
use of io.spine.base.Event in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method throw_exception_if_dispatch_unknown_event.
@Test(expected = RuntimeException.class)
public void throw_exception_if_dispatch_unknown_event() {
final StringValue unknownEventMessage = StringValue.getDefaultInstance();
final Event event = EventTests.createContextlessEvent(unknownEventMessage);
repository().dispatch(event);
}
use of io.spine.base.Event 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));
}
Aggregations