use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class CommandServiceShould method verifyPostsCommand.
private void verifyPostsCommand(Command cmd) {
final MemoizingObserver<Ack> observer = memoizingObserver();
service.post(cmd, observer);
assertNull(observer.getError());
assertTrue(observer.isCompleted());
final Ack acked = observer.firstResponse();
final CommandId id = AnyPacker.unpack(acked.getMessageId());
assertEquals(cmd.getId(), id);
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class AbstractCommandRouter method checkSent.
private static void checkSent(Command command, Ack ack) {
final Status status = ack.getStatus();
final CommandId routedCommandId = unpack(ack.getMessageId());
final CommandId commandId = command.getId();
checkState(commandId.equals(routedCommandId), "Unexpected command posted. Intending (%s) but was (%s).", commandId, routedCommandId);
checkState(status.getStatusCase() == Status.StatusCase.OK, "Command posting failed with status: %s.", status);
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class AbstractCommandBusTestSuite method checkCommandError.
static void checkCommandError(Ack sendingResult, CommandValidationError validationError, String errorType, Command cmd) {
final Status status = sendingResult.getStatus();
assertEquals(status.getStatusCase(), Status.StatusCase.ERROR);
final CommandId commandId = cmd.getId();
assertEquals(commandId, unpack(sendingResult.getMessageId()));
final Error error = status.getError();
assertEquals(errorType, error.getType());
assertEquals(validationError.getNumber(), error.getCode());
assertFalse(error.getMessage().isEmpty());
if (validationError == INVALID_COMMAND) {
assertFalse(error.getValidationError().getConstraintViolationList().isEmpty());
}
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class IdempotencyGuard method didHandleSinceLastSnapshot.
/**
* Checks if the command was already handled by the aggregate since last snapshot.
*
* <p>The check is performed by searching for an event caused by this command that was
* committed since last snapshot.
*
* <p>This functionality supports the ability to stop duplicate commands from being dispatched
* to the aggregate.
*
* @param envelope the command to check
* @return {@code true} if the command was handled since last snapshot, {@code false} otherwise
*/
private boolean didHandleSinceLastSnapshot(CommandEnvelope envelope) {
final CommandId newCommandId = envelope.getId();
final Iterator<Event> iterator = aggregate.historyBackward();
while (iterator.hasNext()) {
final Event event = iterator.next();
final CommandId eventRootCommandId = getRootCommandId(event);
if (newCommandId.equals(eventRootCommandId)) {
return true;
}
}
return false;
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class CommandScheduler method rememberAsScheduled.
private static void rememberAsScheduled(Command command) {
final CommandId id = command.getId();
scheduledCommandIds.add(id);
}
Aggregations