Search in sources :

Example 16 with CommandId

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;
}
Also used : CommandId(io.spine.base.CommandId) Identifiers.idToString(io.spine.base.Identifiers.idToString) CommandRecord(io.spine.server.commandbus.CommandRecord)

Example 17 with CommandId

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());
}
Also used : CommandId(io.spine.base.CommandId) Test(org.junit.Test)

Example 18 with CommandId

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());
    }
}
Also used : Commands.getMessage(io.spine.base.Commands.getMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.base.Command) CommandEnvelope(io.spine.envelope.CommandEnvelope) Error(io.spine.base.Error) Duration(com.google.protobuf.Duration) CommandId(io.spine.base.CommandId) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 19 with CommandId

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());
}
Also used : TenantId(io.spine.users.TenantId) Command(io.spine.base.Command) CommandId(io.spine.base.CommandId) Test(org.junit.Test)

Example 20 with CommandId

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;
}
Also used : TenantId(io.spine.users.TenantId) TenantAwareFunction(io.spine.server.tenant.TenantAwareFunction) CommandId(io.spine.base.CommandId) Nullable(javax.annotation.Nullable)

Aggregations

CommandId (io.spine.base.CommandId)20 Test (org.junit.Test)7 Command (io.spine.base.Command)6 Message (com.google.protobuf.Message)5 Error (io.spine.base.Error)4 CommandRecord (io.spine.server.commandbus.CommandRecord)4 CommandContext (io.spine.base.CommandContext)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)3 TenantId (io.spine.users.TenantId)3 Commands.getMessage (io.spine.base.Commands.getMessage)2 CommandEnvelope (io.spine.envelope.CommandEnvelope)2 CommandMessage.createProjectMessage (io.spine.server.commandbus.Given.CommandMessage.createProjectMessage)2 AbstractEntity (io.spine.server.entity.AbstractEntity)2 Nullable (javax.annotation.Nullable)2 ImmutableList (com.google.common.collect.ImmutableList)1 Duration (com.google.protobuf.Duration)1 Timestamp (com.google.protobuf.Timestamp)1 CommandStatus (io.spine.base.CommandStatus)1 FailureThrowable (io.spine.base.FailureThrowable)1 Identifiers.idToString (io.spine.base.Identifiers.idToString)1