Search in sources :

Example 31 with Command

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

the class CommandSchedulingShould method reschedule_commands_from_storage.

@Test
public void reschedule_commands_from_storage() {
    final Timestamp schedulingTime = minutesAgo(3);
    final Duration delayPrimary = Durations2.fromMinutes(5);
    // = 5 - 3
    final Duration newDelayExpected = Durations2.fromMinutes(2);
    final List<Command> commandsPrimary = newArrayList(createProject(), addTask(), startProject());
    storeAsScheduled(commandsPrimary, delayPrimary, schedulingTime);
    commandBus.rescheduleCommands();
    final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    verify(scheduler, times(commandsPrimary.size())).schedule(commandCaptor.capture());
    final List<Command> commandsRescheduled = commandCaptor.getAllValues();
    for (Command cmd : commandsRescheduled) {
        final long actualDelay = getDelaySeconds(cmd);
        Tests.assertSecondsEqual(newDelayExpected.getSeconds(), actualDelay, /*maxDiffSec=*/
        1);
    }
}
Also used : Command(io.spine.core.Command) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 32 with Command

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

the class CommandSchedulingShould method store_scheduled_command_and_return_OK.

@Test
public void store_scheduled_command_and_return_OK() {
    commandBus.register(createProjectHandler);
    final Command cmd = createProject(/*delay=*/
    minutes(1));
    commandBus.post(cmd, observer);
    verify(commandStore).store(cmd, SCHEDULED);
    checkResult(cmd);
}
Also used : Command(io.spine.core.Command) Test(org.junit.Test)

Example 33 with Command

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

the class CommandStoreShould method set_command_status_to_error_when_handler_throws_exception.

@Test
public void set_command_status_to_error_when_handler_throws_exception() {
    ModelTests.clearModel();
    final RuntimeException exception = new IllegalStateException("handler throws");
    final Command command = givenThrowingHandler(exception);
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    commandBus.post(command, observer);
    // Check that the logging was called.
    verify(log).errorHandling(eq(exception), eq(envelope.getMessage()), eq(envelope.getId()));
    final String errorMessage = exception.getMessage();
    assertHasErrorStatusWithMessage(envelope, errorMessage);
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 34 with Command

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

the class CommandStoreShould method set_command_status_to_error_when_dispatcher_throws.

@Test
public void set_command_status_to_error_when_dispatcher_throws() {
    final ThrowingDispatcher dispatcher = new ThrowingDispatcher();
    commandBus.register(dispatcher);
    final Command command = requestFactory.command().create(createProjectMessage());
    commandBus.post(command, observer);
    // Check that the logging was called.
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    verify(log).errorHandling(dispatcher.exception, envelope.getMessage(), envelope.getId());
    // Check that the command status has the correct code,
    // and the error matches the thrown exception.
    assertHasErrorStatusWithMessage(envelope, dispatcher.exception.getMessage());
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 35 with Command

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

the class CommandValidatorViolationCheckShould method not_allow_commands_without_IDs.

@Test
public void not_allow_commands_without_IDs() {
    final Command cmd = Given.ACommand.createProject();
    final Command unidentifiableCommand = cmd.toBuilder().setId(CommandId.getDefaultInstance()).build();
    final List<ConstraintViolation> violations = inspect(CommandEnvelope.of(unidentifiableCommand));
    assertEquals(1, violations.size());
}
Also used : Command(io.spine.core.Command) ConstraintViolation(io.spine.validate.ConstraintViolation) Test(org.junit.Test)

Aggregations

Command (io.spine.core.Command)137 Test (org.junit.Test)87 Event (io.spine.core.Event)19 TenantId (io.spine.core.TenantId)17 Ack (io.spine.core.Ack)15 Message (com.google.protobuf.Message)14 Rejection (io.spine.core.Rejection)13 CommandEnvelope (io.spine.core.CommandEnvelope)11 Timestamp (com.google.protobuf.Timestamp)9 Error (io.spine.base.Error)9 CommandContext (io.spine.core.CommandContext)9 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)8 CommandRecord (io.spine.server.commandbus.CommandRecord)8 ProjectId (io.spine.test.aggregate.ProjectId)8 CommandBus (io.spine.server.commandbus.CommandBus)7 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)7 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Any (com.google.protobuf.Any)6 CommandId (io.spine.core.CommandId)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6