use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class Records method newRecordBuilder.
/**
* Creates a command storage record builder passed on the passed parameters.
*
* <p>{@code targetId} and {@code targetIdType} are set to empty strings if
* the command is not for an entity.
*
* @param command
* a command to convert to a record. This includes instances of faulty commands.
* An example of such a fault is missing command ID.
* @param status
* a command status to set in the record
* @param generatedCommandId
* a command ID to be used because the passed command does not have own ID.
* If the command has own ID, this parameter is {@code null}.
* @return a storage record
*/
static CommandRecord.Builder newRecordBuilder(Command command, CommandStatus status, @Nullable CommandId generatedCommandId) {
final CommandId commandId = generatedCommandId != null ? generatedCommandId : command.getId();
final String commandType = TypeName.ofCommand(command).getSimpleName();
final CommandRecord.Builder builder = CommandRecord.newBuilder().setCommandId(commandId).setCommandType(commandType).setCommand(command).setTimestamp(getCurrentTime()).setStatus(ProcessingStatus.newBuilder().setCode(status));
return builder;
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class FailuresShould method generate_failure_id_upon_command_id.
@Test
public void generate_failure_id_upon_command_id() {
final CommandId commandId = Commands.generateId();
final FailureId actual = Failures.generateId(commandId);
final String expected = String.format(FAILURE_ID_FORMAT, commandId.getUuid());
assertEquals(expected, actual.getValue());
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class CommandStoreShould method set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed.
@Test
public void set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed() {
final List<Command> commands = newArrayList(createProject(), addTask(), startProject());
final Duration delay = fromMinutes(5);
// time to post passed
final Timestamp schedulingTime = TimeTests.Past.minutesAgo(10);
storeAsScheduled(commands, delay, schedulingTime);
commandBus.rescheduleCommands();
for (Command cmd : commands) {
final CommandEnvelope envelope = CommandEnvelope.of(cmd);
final Message msg = envelope.getMessage();
final CommandId id = envelope.getCommandId();
// Check the expired status error was set.
final ProcessingStatus status = getProcessingStatus(envelope);
// Check that the logging was called.
verify(log).errorExpiredCommand(msg, id);
final Error expected = CommandExpiredException.commandExpiredError(msg);
assertEquals(expected, status.getError());
}
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class CommandStoreShould method set_command_status_to_OK_when_handler_returns.
@Test
public void set_command_status_to_OK_when_handler_returns() {
commandBus.register(createProjectHandler);
final Command command = requestFactory.command().create(createProjectMessage());
commandBus.post(command, responseObserver);
final TenantId tenantId = command.getContext().getActorContext().getTenantId();
final CommandId commandId = command.getId();
final ProcessingStatus status = getStatus(commandId, tenantId);
assertEquals(CommandStatus.OK, status.getCode());
}
use of io.spine.base.CommandId in project core-java by SpineEventEngine.
the class CommandStoreShould method getProcessingStatus.
private ProcessingStatus getProcessingStatus(CommandEnvelope commandEnvelope) {
final TenantId tenantId = commandEnvelope.getCommandContext().getActorContext().getTenantId();
final TenantAwareFunction<CommandId, ProcessingStatus> func = new TenantAwareFunction<CommandId, ProcessingStatus>(tenantId) {
@Override
public ProcessingStatus apply(@Nullable CommandId input) {
return commandStore.getStatus(checkNotNull(input));
}
};
final ProcessingStatus result = func.execute(commandEnvelope.getCommandId());
return result;
}
Aggregations