use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandSchedulingShould method reject_previously_scheduled_command_if_no_endpoint_found.
@Test(expected = IllegalStateException.class)
public void reject_previously_scheduled_command_if_no_endpoint_found() {
Command command = storeSingleCommandForRescheduling();
commandBus.postPreviouslyScheduled(command);
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandSchedulingShould method reschedule_commands_from_storage_in_parallel_on_build_if_thread_spawning_allowed.
@Test
public void reschedule_commands_from_storage_in_parallel_on_build_if_thread_spawning_allowed() {
final String mainThreadName = Thread.currentThread().getName();
final StringBuilder threadNameUponScheduling = new StringBuilder(0);
final CountDownLatch latch = new CountDownLatch(1);
final CommandScheduler scheduler = threadAwareScheduler(threadNameUponScheduling, latch);
storeSingleCommandForRescheduling();
// Create CommandBus specific for this test.
final CommandBus commandBus = CommandBus.newBuilder().setCommandStore(commandStore).setCommandScheduler(scheduler).setThreadSpawnAllowed(true).setAutoReschedule(true).build();
assertNotNull(commandBus);
// Await to ensure the commands have been rescheduled in parallel.
try {
latch.await();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
// Ensure the scheduler has been called for a single command,
final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
verify(scheduler, times(1)).schedule(commandCaptor.capture());
// and the call has been made for a thread, different than the main thread.
final String actualThreadName = threadNameUponScheduling.toString();
assertNotNull(actualThreadName);
assertNotEquals(mainThreadName, actualThreadName);
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandSchedulingShould method storeSingleCommandForRescheduling.
/**
* Creates and stores one scheduled command.
*/
private Command storeSingleCommandForRescheduling() {
final Command cmdWithSchedule = createScheduledCommand();
commandStore.store(cmdWithSchedule, SCHEDULED);
return cmdWithSchedule;
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandSchedulingShould method update_schedule_options.
@Test
public void update_schedule_options() {
final Command cmd = requestFactory.command().create(toMessage(newUuid()));
final Timestamp schedulingTime = getCurrentTime();
final Duration delay = Durations2.minutes(5);
final Command cmdUpdated = setSchedule(cmd, delay, schedulingTime);
final CommandContext.Schedule schedule = cmdUpdated.getContext().getSchedule();
assertEquals(delay, schedule.getDelay());
assertEquals(schedulingTime, cmdUpdated.getSystemProperties().getSchedulingTime());
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandSchedulingShould method post_previously_scheduled_command.
@Test
public void post_previously_scheduled_command() {
CommandBus spy = spy(commandBus);
spy.register(createProjectHandler);
Command command = storeSingleCommandForRescheduling();
spy.postPreviouslyScheduled(command);
verify(spy).doPost(eq(CommandEnvelope.of(command)));
}
Aggregations