Search in sources :

Example 6 with CommandId

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

the class CommandStore method getStatus.

/**
 * Obtains the processing status for the passed command.
 */
public ProcessingStatus getStatus(Command command) {
    final TenantId tenantId = Commands.getTenantId(command);
    final TenantAwareFunction<CommandId, ProcessingStatus> func = new TenantAwareFunction<CommandId, ProcessingStatus>(tenantId) {

        @Nullable
        @Override
        public ProcessingStatus apply(@Nullable CommandId commandId) {
            checkNotNull(commandId);
            return getStatus(commandId);
        }
    };
    return func.execute(command.getId());
}
Also used : TenantId(io.spine.core.TenantId) TenantAwareFunction(io.spine.server.tenant.TenantAwareFunction) CommandId(io.spine.core.CommandId) ProcessingStatus(io.spine.server.commandbus.ProcessingStatus) Nullable(javax.annotation.Nullable)

Example 7 with CommandId

use of io.spine.core.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 CmdCreateProject 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().getRejection()));
            break;
        case ERROR:
            assertTrue(isNotDefault(record.getStatus().getError()));
            break;
        case REJECTED:
            assertTrue(isNotDefault(record.getStatus().getRejection()));
            break;
        case UNDEFINED:
        case UNRECOGNIZED:
            break;
    }
}
Also used : CmdCreateProject(io.spine.test.command.CmdCreateProject) CommandContext(io.spine.core.CommandContext) CommandId(io.spine.core.CommandId)

Example 8 with CommandId

use of io.spine.core.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.ACommand.createProject();
    final CommandId commandId = command.getId();
    final Error error = newError();
    repository.store(command, error);
    final CommandRecord record = read(commandId).get();
    checkRecord(record, command, ERROR);
    assertEquals(error, record.getStatus().getError());
}
Also used : Command(io.spine.core.Command) Error(io.spine.base.Error) CommandId(io.spine.core.CommandId) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 9 with CommandId

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

the class AbstractCommandBusTestSuite method checkResult.

protected void checkResult(Command cmd) {
    assertNull(observer.getError());
    assertTrue(observer.isCompleted());
    final CommandId commandId = unpack(observer.firstResponse().getMessageId());
    assertEquals(cmd.getId(), commandId);
}
Also used : CommandId(io.spine.core.CommandId)

Example 10 with CommandId

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

the class CommandStoreShould method set_command_status_to_rejection_when_handler_throws_rejection.

@Test
public void set_command_status_to_rejection_when_handler_throws_rejection() {
    ModelTests.clearModel();
    final TestRejection rejection = new TestRejection();
    final Command command = givenThrowingHandler(rejection);
    final CommandId commandId = command.getId();
    final Message commandMessage = getMessage(command);
    commandBus.post(command, observer);
    // Check that the logging was called.
    verify(log).rejectedWith(eq(rejection), eq(commandMessage), eq(commandId));
    // Check that the status has the correct code,
    // and the rejection matches the thrown rejection.
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.REJECTED, status.getCode());
    assertEquals(toRejection(rejection, command).getMessage(), status.getRejection().getMessage());
}
Also used : TenantId(io.spine.core.TenantId) 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) CommandId(io.spine.core.CommandId) 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