Search in sources :

Example 16 with Event

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));
}
Also used : Event(io.spine.base.Event) Test(org.junit.Test)

Example 17 with 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);
}
Also used : Message(com.google.protobuf.Message) CommandContext(io.spine.base.CommandContext) Event(io.spine.base.Event) CommandClass(io.spine.type.CommandClass)

Example 18 with Event

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;
        }
    });
}
Also used : Message(com.google.protobuf.Message) EventFactory(io.spine.server.command.EventFactory) Event(io.spine.base.Event)

Example 19 with Event

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);
}
Also used : Event(io.spine.base.Event) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 20 with 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));
}
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)

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