use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.
the class AggregateShould method acknowledge_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot.
@Test
public void acknowledge_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot() {
final TenantId tenantId = newTenantId();
final Command createCommand = command(createProject, tenantId);
final CommandBus commandBus = boundedContext.getCommandBus();
final StreamObserver<Ack> noOpObserver = noOpObserver();
final MemoizingObserver<Ack> memoizingObserver = memoizingObserver();
commandBus.post(createCommand, noOpObserver);
commandBus.post(createCommand, memoizingObserver);
final List<Ack> responses = memoizingObserver.responses();
final Ack ack = responses.get(0);
assertTrue(ack.getStatus().hasError());
final String errorType = DuplicateCommandException.class.getCanonicalName();
assertEquals(errorType, ack.getStatus().getError().getType());
}
use of io.spine.server.commandbus.CommandBus 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));
}
use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.
the class ProcessManager method newRouterFor.
/**
* Creates a new {@link CommandRouter}.
*
* <p>A {@code CommandRouter} allows to create and post one or more commands
* in response to a command received by the {@code ProcessManager}.
*
* <p>A typical usage looks like this:
*
* <pre>
* {@literal @}Assign
* CommandRouted on(MyCommand message, CommandContext context) {
* // Create new command messages here.
* return newRouterFor(message, context)
* .add(messageOne)
* .add(messageTwo)
* .routeAll();
* }
* </pre>
*
* <p>The routed commands are created on behalf of the actor of the original command.
* That is, the {@code actor} and {@code zoneOffset} fields of created {@code CommandContext}
* instances will be the same as in the incoming command.
*
* @param commandMessage the source command message
* @param commandContext the context of the source command
* @return new {@code CommandRouter}
*/
protected CommandRouter newRouterFor(Message commandMessage, CommandContext commandContext) {
checkNotNull(commandMessage);
checkNotNull(commandContext);
final CommandBus commandBus = ensureCommandBus();
final CommandRouter router = new CommandRouter(commandBus, commandMessage, commandContext);
return router;
}
Aggregations