use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class CommandStoreShould method set_command_status_to_failure_when_handler_throws_failure.
@Test
public void set_command_status_to_failure_when_handler_throws_failure() {
final TestFailure failure = new TestFailure();
final Command command = givenThrowingHandler(failure);
final CommandId commandId = command.getId();
final Message commandMessage = getMessage(command);
commandBus.post(command, responseObserver);
// Check that the logging was called.
verify(log).failureHandling(eq(failure), eq(commandMessage), eq(commandId));
// Check that the status has the correct code,
// and the failure matches the thrown failure.
final TenantId tenantId = command.getContext().getActorContext().getTenantId();
final ProcessingStatus status = getStatus(commandId, tenantId);
assertEquals(CommandStatus.FAILURE, status.getCode());
assertEquals(failure.toFailure(command).getMessage(), status.getFailure().getMessage());
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class StorageShould method store_command_with_error.
// We get right after we store.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void store_command_with_error() {
final Command command = Given.Command.createProject();
final CommandId commandId = command.getId();
final Error error = newError();
storage.store(command, error);
final CommandRecord record = read(commandId).get();
checkRecord(record, command, ERROR);
assertEquals(error, record.getStatus().getError());
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class CommandTestUtil method checkRecord.
static void checkRecord(CommandRecord record, Command cmd, CommandStatus statusExpected) {
final CommandContext context = cmd.getContext();
final CommandId commandId = cmd.getId();
final CreateProject message = unpack(cmd.getMessage());
assertEquals(cmd.getMessage(), record.getCommand().getMessage());
assertTrue(record.getTimestamp().getSeconds() > 0);
assertEquals(message.getClass().getSimpleName(), record.getCommandType());
assertEquals(commandId, record.getCommandId());
assertEquals(statusExpected, record.getStatus().getCode());
assertEquals(context, record.getCommand().getContext());
switch(statusExpected) {
case RECEIVED:
case OK:
case SCHEDULED:
assertTrue(isDefault(record.getStatus().getError()));
assertTrue(isDefault(record.getStatus().getFailure()));
break;
case ERROR:
assertTrue(isNotDefault(record.getStatus().getError()));
break;
case FAILURE:
assertTrue(isNotDefault(record.getStatus().getFailure()));
break;
case UNDEFINED:
case UNRECOGNIZED:
break;
}
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class Validator method validate.
/**
* Validates a command checking that its required fields are valid and
* validates a command message according to Spine custom protobuf options.
*
* @param envelope a command to validate
* @return constraint violations found
*/
List<ConstraintViolation> validate(CommandEnvelope envelope) {
final ImmutableList.Builder<ConstraintViolation> result = ImmutableList.builder();
final Message message = envelope.getMessage();
final CommandContext context = envelope.getCommandContext();
final CommandId id = envelope.getCommandId();
validateCommandId(id, result);
validateMessage(message, result);
validateContext(context, result);
validateTargetId(message, result);
return result.build();
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class CommandStore method getStatus.
/**
* Obtains the processing status for the command with the passed ID.
*/
public ProcessingStatus getStatus(CommandId commandId) {
final Func<CommandId, ProcessingStatus> func = new Func<CommandId, ProcessingStatus>(this) {
@Override
public ProcessingStatus apply(@Nullable CommandId input) {
checkNotNull(input);
final ProcessingStatus status = storage.getStatus(input);
return status;
}
};
return func.execute(commandId);
}
Aggregations