Search in sources :

Example 86 with Event

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

the class EventRootCommandIdShould method match_the_id_of_a_command_handled_by_an_aggregate_for_multiple_events.

@Test
public void match_the_id_of_a_command_handled_by_an_aggregate_for_multiple_events() {
    final Command command = command(addTasks(projectId(), 3));
    postCommand(command);
    final List<Event> events = readEvents();
    assertSize(3, events);
    assertEquals(command.getId(), getRootCommandId(events.get(0)));
    assertEquals(command.getId(), getRootCommandId(events.get(1)));
    assertEquals(command.getId(), getRootCommandId(events.get(2)));
}
Also used : Command(io.spine.core.Command) Event(io.spine.core.Event) Test(org.junit.Test)

Example 87 with Event

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

the class EventRootCommandIdShould method readEvents.

/**
 * Reads all events from the bounded context event store.
 */
private List<Event> readEvents() {
    final MemoizingObserver<Event> observer = StreamObservers.memoizingObserver();
    final TenantAwareOperation operation = new TenantAwareOperation(TENANT_ID) {

        @Override
        public void run() {
            boundedContext.getEventBus().getEventStore().read(allEventsQuery(), observer);
        }
    };
    operation.execute();
    final List<Event> results = observer.responses();
    return results;
}
Also used : Event(io.spine.core.Event) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 88 with Event

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

the class EventRootCommandIdShould method match_the_id_of_an_external_event_handled_by_an_aggregate.

/**
 * Ensures root command ID is matched by the property of the event which is created as
 * a reaction to another event.
 *
 * <p> Two events are expected to be found in the {@linkplain EventStore} created by different
 * aggregates:
 * <ol>
 *     <li>{@link io.spine.server.event.given.EventRootCommandIdTestEnv.ProjectAggregate} —
 *     {@link ProjectCreated}</li>
 *     <li>{@link io.spine.server.event.given.EventRootCommandIdTestEnv.TeamAggregate} —
 *     {@link EvTeamProjectAdded} created as a reaction to {@link ProjectCreated}</li>
 * </ol>
 */
@Test
public void match_the_id_of_an_external_event_handled_by_an_aggregate() {
    final Command command = command(createProject(projectId(), teamId()));
    postCommand(command);
    final List<Event> events = readEvents();
    assertSize(2, events);
    final Event reaction = events.get(1);
    assertEquals(command.getId(), getRootCommandId(reaction));
}
Also used : Command(io.spine.core.Command) Event(io.spine.core.Event) Test(org.junit.Test)

Example 89 with Event

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

the class EventStoreShould method read_events_by_type.

@Test
public void read_events_by_type() {
    final Timestamp now = getCurrentTime();
    final Event taskAdded1 = taskAdded(now);
    final Event projectCreated = projectCreated(now);
    final Event teasAdded2 = taskAdded(now);
    eventStore.append(taskAdded1);
    eventStore.append(projectCreated);
    eventStore.append(teasAdded2);
    final EventFilter taskAddedType = EventFilter.newBuilder().setEventType(of(TaskAdded.class).value()).build();
    final EventStreamQuery query = EventStreamQuery.newBuilder().addFilter(taskAddedType).build();
    final AtomicBoolean done = new AtomicBoolean(false);
    final Collection<Event> resultEvents = newConcurrentHashSet();
    eventStore.read(query, new ResponseObserver(resultEvents, done));
    assertDone(done);
    assertSize(2, resultEvents);
    assertContainsAll(resultEvents, taskAdded1, teasAdded2);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskAdded(io.spine.test.event.TaskAdded) Event(io.spine.core.Event) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 90 with Event

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

the class EventStoreShould method fail_to_store_events_of_different_tenants_in_a_single_operation.

@Test(expected = IllegalArgumentException.class)
public void fail_to_store_events_of_different_tenants_in_a_single_operation() {
    final TenantId firstTenantId = TenantId.newBuilder().setValue("abc").build();
    final TenantId secondTenantId = TenantId.newBuilder().setValue("xyz").build();
    final ActorContext firstTenantActor = ActorContext.newBuilder().setTenantId(firstTenantId).build();
    final ActorContext secondTenantActor = ActorContext.newBuilder().setTenantId(secondTenantId).build();
    final CommandContext firstTenantCommand = CommandContext.newBuilder().setActorContext(firstTenantActor).build();
    final CommandContext secondTenantCommand = CommandContext.newBuilder().setActorContext(secondTenantActor).build();
    final EventContext firstTenantContext = EventContext.newBuilder().setCommandContext(firstTenantCommand).build();
    final EventContext secondTenantContext = EventContext.newBuilder().setCommandContext(secondTenantCommand).build();
    final Event firstTenantEvent = Event.newBuilder().setContext(firstTenantContext).build();
    final Event secondTenantEvent = Event.newBuilder().setContext(secondTenantContext).build();
    final Collection<Event> event = ImmutableSet.of(firstTenantEvent, secondTenantEvent);
    eventStore.appendAll(event);
}
Also used : EventContext(io.spine.core.EventContext) TenantId(io.spine.core.TenantId) CommandContext(io.spine.core.CommandContext) Event(io.spine.core.Event) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Aggregations

Event (io.spine.core.Event)115 Test (org.junit.Test)75 Command (io.spine.core.Command)19 EventContext (io.spine.core.EventContext)12 BoundedContext (io.spine.server.BoundedContext)12 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)12 Version (io.spine.core.Version)10 TestEventFactory (io.spine.server.command.TestEventFactory)10 Message (com.google.protobuf.Message)9 EventEnvelope (io.spine.core.EventEnvelope)9 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)9 Timestamp (com.google.protobuf.Timestamp)6 Ack (io.spine.core.Ack)6 TenantId (io.spine.core.TenantId)6 Error (io.spine.base.Error)5 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)5 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)5 StringValue (com.google.protobuf.StringValue)4 GivenEvent (io.spine.core.given.GivenEvent)4 Duration (com.google.protobuf.Duration)3