Search in sources :

Example 11 with CommandId

use of io.spine.core.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.getId());
    return result;
}
Also used : TenantId(io.spine.core.TenantId) TenantAwareFunction(io.spine.server.tenant.TenantAwareFunction) CommandId(io.spine.core.CommandId) Nullable(javax.annotation.Nullable)

Example 12 with CommandId

use of io.spine.core.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, observer);
    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.core.TenantId) Command(io.spine.core.Command) CommandId(io.spine.core.CommandId) Test(org.junit.Test)

Example 13 with CommandId

use of io.spine.core.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.getId();
        // 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.commandExpired(cmd);
        assertEquals(expected, status.getError());
    }
}
Also used : Commands.getMessage(io.spine.core.Commands.getMessage) ThrowableMessage(io.spine.base.ThrowableMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) Duration(com.google.protobuf.Duration) CommandId(io.spine.core.CommandId) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 14 with CommandId

use of io.spine.core.CommandId in project core-java by SpineEventEngine.

the class StorageShould method store_and_read_command.

// We get right after we store.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void store_and_read_command() {
    final Command command = Given.ACommand.createProject();
    final CommandId commandId = command.getId();
    repository.store(command);
    final CommandRecord record = read(commandId).get();
    checkRecord(record, command, RECEIVED);
}
Also used : Command(io.spine.core.Command) CommandId(io.spine.core.CommandId) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 15 with CommandId

use of io.spine.core.CommandId in project core-java by SpineEventEngine.

the class StorageShould method store_command_with_status.

// We get right after we store.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void store_command_with_status() {
    final Command command = Given.ACommand.createProject();
    final CommandId commandId = command.getId();
    final CommandStatus status = SCHEDULED;
    repository.store(command, status);
    final CommandRecord record = read(commandId).get();
    checkRecord(record, command, status);
}
Also used : Command(io.spine.core.Command) CommandStatus(io.spine.core.CommandStatus) CommandId(io.spine.core.CommandId) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Aggregations

CommandId (io.spine.core.CommandId)22 Command (io.spine.core.Command)6 Test (org.junit.Test)6 Error (io.spine.base.Error)5 Message (com.google.protobuf.Message)4 TenantId (io.spine.core.TenantId)4 CommandRecord (io.spine.server.commandbus.CommandRecord)4 ThrowableMessage (io.spine.base.ThrowableMessage)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)3 Nullable (javax.annotation.Nullable)3 CommandEnvelope (io.spine.core.CommandEnvelope)2 Commands.getMessage (io.spine.core.Commands.getMessage)2 Status (io.spine.core.Status)2 CommandMessage.createProjectMessage (io.spine.server.commandbus.Given.CommandMessage.createProjectMessage)2 ProcessingStatus (io.spine.server.commandbus.ProcessingStatus)2 TenantAwareFunction (io.spine.server.tenant.TenantAwareFunction)2 Duration (com.google.protobuf.Duration)1 Timestamp (com.google.protobuf.Timestamp)1 Ack (io.spine.core.Ack)1 CommandContext (io.spine.core.CommandContext)1