Search in sources :

Example 1 with Version

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

the class EventsShould method setUp.

@Before
public void setUp() {
    final TestActorRequestFactory requestFactory = TestActorRequestFactory.newInstance(getClass());
    final Command cmd = requestFactory.command().create(Time.getCurrentTime());
    final StringValue producerId = Wrapper.forString(getClass().getSimpleName());
    EventFactory eventFactory = EventFactory.newBuilder().setCommandId(Commands.generateId()).setProducerId(producerId).setCommandContext(cmd.getContext()).build();
    event = eventFactory.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
    context = event.getContext();
}
Also used : TestActorRequestFactory(io.spine.test.TestActorRequestFactory) Version(io.spine.base.Version) TestEventFactory(io.spine.test.TestEventFactory) EventFactory(io.spine.server.command.EventFactory) StringValue(com.google.protobuf.StringValue) Before(org.junit.Before)

Example 2 with Version

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

the class Aggregate method applyMessages.

/**
     * Applies the passed event message or {@code Event} to the aggregate.
     *
     * @param eventMessages the event messages or events to apply
     * @param envelope      the envelope of the command which generated the events
     * @see #ensureEventMessage(Message)
     */
private void applyMessages(Iterable<? extends Message> eventMessages, CommandEnvelope envelope) {
    final List<? extends Message> messages = newArrayList(eventMessages);
    final EventFactory eventFactory = createEventFactory(envelope, messages.size());
    final List<Event> events = newArrayListWithCapacity(messages.size());
    Version projectedEventVersion = getVersion();
    for (Message eventOrMessage : messages) {
        // Applying each message would increment the entity version.
        // Therefore we should simulate this behaviour.
        projectedEventVersion = Versions.increment(projectedEventVersion);
        final Message eventMessage = ensureEventMessage(eventOrMessage);
        final Event event;
        if (eventOrMessage instanceof Event) {
            event = importEvent((Event) eventOrMessage, envelope.getCommandContext(), projectedEventVersion);
        } else {
            event = eventFactory.createEvent(eventMessage, projectedEventVersion);
        }
        events.add(event);
    }
    play(events);
    uncommittedEvents.addAll(events);
}
Also used : Events.getMessage(io.spine.base.Events.getMessage) EventApplierMethod.forEventMessage(io.spine.server.reflect.EventApplierMethod.forEventMessage) Message(com.google.protobuf.Message) Version(io.spine.base.Version) EventFactory(io.spine.server.command.EventFactory) Event(io.spine.base.Event)

Aggregations

Version (io.spine.base.Version)2 EventFactory (io.spine.server.command.EventFactory)2 Message (com.google.protobuf.Message)1 StringValue (com.google.protobuf.StringValue)1 Event (io.spine.base.Event)1 Events.getMessage (io.spine.base.Events.getMessage)1 EventApplierMethod.forEventMessage (io.spine.server.reflect.EventApplierMethod.forEventMessage)1 TestActorRequestFactory (io.spine.test.TestActorRequestFactory)1 TestEventFactory (io.spine.test.TestEventFactory)1 Before (org.junit.Before)1