Search in sources :

Example 1 with IgTestAggregate

use of io.spine.server.aggregate.given.aggregate.IgTestAggregate 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)

Example 2 with IgTestAggregate

use of io.spine.server.aggregate.given.aggregate.IgTestAggregate 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 3 with IgTestAggregate

use of io.spine.server.aggregate.given.aggregate.IgTestAggregate 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 4 with IgTestAggregate

use of io.spine.server.aggregate.given.aggregate.IgTestAggregate in project core-java by SpineEventEngine.

the class IdempotencyGuardShould method throw_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot.

@Test(expected = DuplicateCommandException.class)
public void throw_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot() {
    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)

Aggregations

Command (io.spine.core.Command)4 TenantId (io.spine.core.TenantId)4 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)4 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)4 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)4 ProjectId (io.spine.test.aggregate.ProjectId)4 Test (org.junit.Test)4 Ack (io.spine.core.Ack)3 CommandBus (io.spine.server.commandbus.CommandBus)3