Search in sources :

Example 56 with Command

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

the class AggregateRepositoryViewsShould method postCommand.

/**
 * Creates a command and posts it to {@code CommandBus}
 * for being processed by the repository.
 */
private void postCommand(String cmd) {
    final Command command = requestFactory.command().create(RepoOfAggregateWithLifecycle.createCommandMessage(id, cmd));
    boundedContext.getCommandBus().post(command, StreamObservers.<Ack>noOpObserver());
}
Also used : Command(io.spine.core.Command)

Example 57 with Command

use of io.spine.core.Command 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 58 with Command

use of io.spine.core.Command 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)

Example 59 with Command

use of io.spine.core.Command 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());
}
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 60 with Command

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

the class IdempotencyGuardShould method not_throw_if_the_command_was_not_handled.

@Test
public void not_throw_if_the_command_was_not_handled() {
    final TenantId tenantId = newTenantId();
    final ProjectId projectId = newProjectId();
    final Command createCommand = command(createProject(projectId), tenantId);
    final IgTestAggregate aggregate = new IgTestAggregate(projectId);
    final IdempotencyGuard guard = new IdempotencyGuard(aggregate);
    guard.check(of(createCommand));
}
Also used : IdempotencyGuardTestEnv.newTenantId(io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) IgTestAggregate(io.spine.server.aggregate.given.aggregate.IgTestAggregate) IdempotencyGuardTestEnv.newProjectId(io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId) ProjectId(io.spine.test.aggregate.ProjectId) Test(org.junit.Test)

Aggregations

Command (io.spine.core.Command)137 Test (org.junit.Test)87 Event (io.spine.core.Event)19 TenantId (io.spine.core.TenantId)17 Ack (io.spine.core.Ack)15 Message (com.google.protobuf.Message)14 Rejection (io.spine.core.Rejection)13 CommandEnvelope (io.spine.core.CommandEnvelope)11 Timestamp (com.google.protobuf.Timestamp)9 Error (io.spine.base.Error)9 CommandContext (io.spine.core.CommandContext)9 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)8 CommandRecord (io.spine.server.commandbus.CommandRecord)8 ProjectId (io.spine.test.aggregate.ProjectId)8 CommandBus (io.spine.server.commandbus.CommandBus)7 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)7 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Any (com.google.protobuf.Any)6 CommandId (io.spine.core.CommandId)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6