use of io.spine.core.Event in project core-java by SpineEventEngine.
the class AggregateShould method traverse_the_history_iterating_through_newest_events_first.
@Test
public void traverse_the_history_iterating_through_newest_events_first() {
final TenantId tenantId = newTenantId();
final Command createCommand = command(createProject, tenantId);
final Command startCommand = command(startProject, tenantId);
final Command addTaskCommand = command(addTask, tenantId);
final Command addTaskCommand2 = command(addTask, tenantId);
final CommandBus commandBus = boundedContext.getCommandBus();
final StreamObserver<Ack> noOpObserver = noOpObserver();
commandBus.post(createCommand, noOpObserver);
commandBus.post(addTaskCommand, noOpObserver);
commandBus.post(newArrayList(addTaskCommand2, startCommand), noOpObserver);
final TestAggregate aggregate = repository.loadAggregate(tenantId, ID);
final Iterator<Event> history = aggregate.historyBackward();
assertEquals(startCommand.getId(), getRootCommandId(history.next()));
assertEquals(addTaskCommand2.getId(), getRootCommandId(history.next()));
assertEquals(addTaskCommand.getId(), getRootCommandId(history.next()));
assertEquals(createCommand.getId(), getRootCommandId(history.next()));
assertFalse(history.hasNext());
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class AggregateShould method create_single_event_for_a_pair_of_events_with_empty_for_a_command_dispatch.
/**
* Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second
* optional value returned from a command handler stores a single event.
*
* <p>The command handler that should return a pair is
* {@link TaskAggregate#handle(AggAssignTask)
* TaskAggregate#handle(AggAssignTask)}.
*/
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_a_command_dispatch() {
final BoundedContext boundedContext = newTaskBoundedContext();
final TenantId tenantId = newTenantId();
final Command command = command(createTask(), tenantId);
final MemoizingObserver<Ack> observer = memoizingObserver();
boundedContext.getCommandBus().post(command, observer);
assertNull(observer.getError());
final List<Ack> responses = observer.responses();
assertSize(1, responses);
final Ack response = responses.get(0);
final io.spine.core.Status status = response.getStatus();
final Error emptyError = Error.getDefaultInstance();
assertEquals(emptyError, status.getError());
final Rejection emptyRejection = Rejection.getDefaultInstance();
assertEquals(emptyRejection, status.getRejection());
final List<Event> events = readAllEvents(boundedContext, tenantId);
assertSize(1, events);
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class AggregateShould method traverse_the_history_up_to_the_latest_snapshot.
@Test
public void traverse_the_history_up_to_the_latest_snapshot() {
repository.setSnapshotTrigger(3);
final TenantId tenantId = newTenantId();
final Command createCommand = command(createProject, tenantId);
final Command startCommand = command(startProject, tenantId);
final Command addTaskCommand = command(addTask, tenantId);
final Command addTaskCommand2 = command(addTask, tenantId);
final CommandBus commandBus = boundedContext.getCommandBus();
final StreamObserver<Ack> noOpObserver = noOpObserver();
commandBus.post(createCommand, noOpObserver);
commandBus.post(startCommand, noOpObserver);
commandBus.post(newArrayList(addTaskCommand, addTaskCommand2), noOpObserver);
final TestAggregate aggregate = repository.loadAggregate(tenantId, ID);
final Iterator<Event> history = aggregate.historyBackward();
assertEquals(addTaskCommand2.getId(), getRootCommandId(history.next()));
assertFalse(history.hasNext());
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class AggregateStorageShould method writeAndReadEventTest.
// OK as we write right before we get.
@SuppressWarnings("OptionalGetWithoutIsPresent")
private <I> void writeAndReadEventTest(I id, AggregateStorage<I> storage) {
final Event expectedEvent = eventFactory.createEvent(Time.getCurrentTime());
storage.writeEvent(id, expectedEvent);
final AggregateReadRequest<I> readRequest = new AggregateReadRequest<>(id, MAX_VALUE);
final AggregateStateRecord events = storage.read(readRequest).get();
assertEquals(1, events.getEventCount());
final Event actualEvent = events.getEvent(0);
assertEquals(expectedEvent, actualEvent);
close(storage);
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class AggregateStorageShould method not_store_enrichment_for_EventContext.
@Test
public void not_store_enrichment_for_EventContext() {
final EventContext enrichedContext = EventContext.newBuilder().setEnrichment(withOneAttribute()).build();
final Event event = Event.newBuilder().setId(newEventId()).setContext(enrichedContext).setMessage(Any.getDefaultInstance()).build();
storage.writeEvent(id, event);
final EventContext loadedContext = storage.read(newReadRequest(id)).get().getEvent(0).getContext();
assertTrue(isDefault(loadedContext.getEnrichment()));
}
Aggregations