Search in sources :

Example 6 with Ack

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

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

the class IdempotencyGuardShould method not_throw_if_another_command_was_handled.

@Test
public void not_throw_if_another_command_was_handled() {
    final TenantId tenantId = newTenantId();
    final ProjectId projectId = newProjectId();
    final Command createCommand = command(createProject(projectId), tenantId);
    final Command startCommand = command(startProject(projectId), tenantId);
    final CommandBus commandBus = boundedContext.getCommandBus();
    final StreamObserver<Ack> noOpObserver = noOpObserver();
    commandBus.post(createCommand, noOpObserver);
    final IgTestAggregate aggregate = repository.loadAggregate(tenantId, projectId);
    final IdempotencyGuard guard = new IdempotencyGuard(aggregate);
    guard.check(of(startCommand));
}
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) Ack(io.spine.core.Ack) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 8 with Ack

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

the class IdempotencyGuardShould method not_throw_when_the_command_was_handled_but_the_snapshot_was_made.

@Test
public void not_throw_when_the_command_was_handled_but_the_snapshot_was_made() {
    repository.setSnapshotTrigger(1);
    final TenantId tenantId = newTenantId();
    final ProjectId projectId = newProjectId();
    final Command createCommand = command(createProject(projectId), tenantId);
    final CommandBus commandBus = boundedContext.getCommandBus();
    final StreamObserver<Ack> noOpObserver = noOpObserver();
    commandBus.post(createCommand, noOpObserver);
    final IgTestAggregate aggregate = repository.loadAggregate(tenantId, 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) Ack(io.spine.core.Ack) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 9 with Ack

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

the class BoundedContextShould method notify_integration_event_subscriber.

@Test
public void notify_integration_event_subscriber() {
    registerAll();
    final MemoizingObserver<Ack> observer = memoizingObserver();
    final IntegrationEvent event = Given.AnIntegrationEvent.projectCreated();
    final Message msg = unpack(event.getMessage());
    boundedContext.notify(event, observer);
    assertEquals(Responses.statusOk(), observer.firstResponse().getStatus());
    assertEquals(subscriber.getHandledEvent(), msg);
}
Also used : Message(com.google.protobuf.Message) Ack(io.spine.core.Ack) IntegrationEvent(io.spine.server.integration.IntegrationEvent) Test(org.junit.Test)

Example 10 with Ack

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

the class DuplicateCommandShould method not_be_acknowledged_on_client_when_not_sent.

@Test
public void not_be_acknowledged_on_client_when_not_sent() {
    final TenantId tenantId = newTenantId();
    final Command command = command(createProject(), tenantId);
    final Ack ack = client.post(command);
    final Status status = ack.getStatus();
    assertTrue(status.hasOk());
}
Also used : Status(io.spine.core.Status) TenantId(io.spine.core.TenantId) DuplicateCommandTestEnv.newTenantId(io.spine.server.command.given.DuplicateCommandTestEnv.newTenantId) Command(io.spine.core.Command) Ack(io.spine.core.Ack) 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