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