use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class RejectionBusShould method report_dead_messages.
@Test
public void report_dead_messages() {
final MemoizingObserver<Ack> observer = memoizingObserver();
rejectionBus.post(missingOwnerRejection(), observer);
assertTrue(observer.isCompleted());
final Ack result = observer.firstResponse();
assertNotNull(result);
assertEquals(ERROR, result.getStatus().getStatusCase());
final Error error = result.getStatus().getError();
assertEquals(UnhandledRejectionException.class.getCanonicalName(), error.getType());
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class SingleTenantCommandBusShould method propagate_rejections_to_rejection_bus.
@Test
public void propagate_rejections_to_rejection_bus() {
final FaultyHandler faultyHandler = new FaultyHandler(eventBus);
commandBus.register(faultyHandler);
final Command addTaskCommand = clearTenantId(addTask());
final MemoizingObserver<Ack> observer = memoizingObserver();
commandBus.post(addTaskCommand, observer);
final InvalidProjectName throwable = faultyHandler.getThrowable();
final Rejection expectedRejection = toRejection(throwable, addTaskCommand);
final Ack ack = observer.firstResponse();
final Rejection actualRejection = ack.getStatus().getRejection();
assertTrue(isNotDefault(actualRejection));
assertEquals(unpack(expectedRejection.getMessage()), unpack(actualRejection.getMessage()));
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method allow_aggregates_react_on_rejections.
@Test
public void allow_aggregates_react_on_rejections() {
boundedContext.register(new RejectingRepository());
final RejectionReactingRepository repository = new RejectionReactingRepository();
boundedContext.register(repository);
final ProjectId parentId = givenAggregateId("rejectingParent");
final ProjectId childId1 = givenAggregateId("acceptingChild-1");
final ProjectId childId2 = givenAggregateId("acceptingChild-2");
final ProjectId childId3 = givenAggregateId("acceptingChild-3");
final StreamObserver<Ack> observer = StreamObservers.noOpObserver();
final CommandBus commandBus = boundedContext.getCommandBus();
// Create the parent project.
final ImmutableSet<ProjectId> childProjects = ImmutableSet.of(childId1, childId2, childId3);
final Command createParent = requestFactory.createCommand(AggCreateProjectWithChildren.newBuilder().setProjectId(parentId).addAllChildProjectId(childProjects).build());
commandBus.post(createParent, observer);
// Fire a command which would cause rejection.
final Command startProject = requestFactory.createCommand(AggStartProjectWithChildren.newBuilder().setProjectId(parentId).build());
commandBus.post(startProject, observer);
for (ProjectId childProject : childProjects) {
final Optional<RejectionReactingAggregate> optional = repository.find(childProject);
assertTrue(optional.isPresent());
// Check that all the aggregates:
// 1. got Rejections.AggCannotStartArchivedProject;
// 2. produced the state the event;
// 3. applied the event.
final String value = optional.get().getState().getValue();
assertEquals(RejectionReactingAggregate.PARENT_ARCHIVED, value);
}
}
use of io.spine.core.Ack 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.Ack 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);
}
Aggregations