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);
}
}
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);
}
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);
}
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());
}
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());
}
Aggregations