Search in sources :

Example 26 with Command

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);
}
Also used : Command(io.spine.core.Command) Test(org.junit.Test)

Example 27 with 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);
}
Also used : Command(io.spine.core.Command) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 28 with Command

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;
}
Also used : Command(io.spine.core.Command)

Example 29 with Command

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());
}
Also used : CommandContext(io.spine.core.CommandContext) Command(io.spine.core.Command) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 30 with Command

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)));
}
Also used : Command(io.spine.core.Command) 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