Search in sources :

Example 1 with Ack

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

Example 2 with Ack

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()));
}
Also used : Rejections.toRejection(io.spine.core.Rejections.toRejection) Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) InvalidProjectName(io.spine.test.reflect.InvalidProjectName) Ack(io.spine.core.Ack) Test(org.junit.Test)

Example 3 with Ack

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);
    }
}
Also used : RejectingRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectingRepository) RejectionReactingRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingRepository) Command(io.spine.core.Command) RejectionReactingAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingAggregate) ProjectId(io.spine.test.aggregate.ProjectId) Ack(io.spine.core.Ack) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 4 with Ack

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());
}
Also used : AggregateTestEnv.newTenantId(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) TestAggregate(io.spine.server.aggregate.given.aggregate.TestAggregate) Ack(io.spine.core.Ack) Event(io.spine.core.Event) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 5 with Ack

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);
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) AggregateMessageDispatcher.dispatchRejection(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection) Rejection(io.spine.core.Rejection) AggregateTestEnv.newTenantId(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) AggregateTestEnv.newTaskBoundedContext(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext) Test(org.junit.Test)

Aggregations

Ack (io.spine.core.Ack)29 Test (org.junit.Test)18 Command (io.spine.core.Command)15 Error (io.spine.base.Error)11 TenantId (io.spine.core.TenantId)11 CommandBus (io.spine.server.commandbus.CommandBus)7 Any (com.google.protobuf.Any)6 Event (io.spine.core.Event)6 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6 Rejection (io.spine.core.Rejection)5 BoundedContext (io.spine.server.BoundedContext)5 ProjectId (io.spine.test.aggregate.ProjectId)4 Status (io.spine.core.Status)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)3 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)3 Rejections.toRejection (io.spine.core.Rejections.toRejection)2