Search in sources :

Example 16 with CommandId

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

the class CommandServiceShould method verifyPostsCommand.

private void verifyPostsCommand(Command cmd) {
    final MemoizingObserver<Ack> observer = memoizingObserver();
    service.post(cmd, observer);
    assertNull(observer.getError());
    assertTrue(observer.isCompleted());
    final Ack acked = observer.firstResponse();
    final CommandId id = AnyPacker.unpack(acked.getMessageId());
    assertEquals(cmd.getId(), id);
}
Also used : Ack(io.spine.core.Ack) CommandId(io.spine.core.CommandId)

Example 17 with CommandId

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

the class AbstractCommandRouter method checkSent.

private static void checkSent(Command command, Ack ack) {
    final Status status = ack.getStatus();
    final CommandId routedCommandId = unpack(ack.getMessageId());
    final CommandId commandId = command.getId();
    checkState(commandId.equals(routedCommandId), "Unexpected command posted. Intending (%s) but was (%s).", commandId, routedCommandId);
    checkState(status.getStatusCase() == Status.StatusCase.OK, "Command posting failed with status: %s.", status);
}
Also used : Status(io.spine.core.Status) CommandId(io.spine.core.CommandId)

Example 18 with CommandId

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

the class AbstractCommandBusTestSuite method checkCommandError.

static void checkCommandError(Ack sendingResult, CommandValidationError validationError, String errorType, Command cmd) {
    final Status status = sendingResult.getStatus();
    assertEquals(status.getStatusCase(), Status.StatusCase.ERROR);
    final CommandId commandId = cmd.getId();
    assertEquals(commandId, unpack(sendingResult.getMessageId()));
    final Error error = status.getError();
    assertEquals(errorType, error.getType());
    assertEquals(validationError.getNumber(), error.getCode());
    assertFalse(error.getMessage().isEmpty());
    if (validationError == INVALID_COMMAND) {
        assertFalse(error.getValidationError().getConstraintViolationList().isEmpty());
    }
}
Also used : Status(io.spine.core.Status) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError) CommandId(io.spine.core.CommandId)

Example 19 with CommandId

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

the class IdempotencyGuard method didHandleSinceLastSnapshot.

/**
 * Checks if the command was already handled by the aggregate since last snapshot.
 *
 * <p>The check is performed by searching for an event caused by this command that was
 * committed since last snapshot.
 *
 * <p>This functionality supports the ability to stop duplicate commands from being dispatched
 * to the aggregate.
 *
 * @param envelope the command to check
 * @return {@code true} if the command was handled since last snapshot, {@code false} otherwise
 */
private boolean didHandleSinceLastSnapshot(CommandEnvelope envelope) {
    final CommandId newCommandId = envelope.getId();
    final Iterator<Event> iterator = aggregate.historyBackward();
    while (iterator.hasNext()) {
        final Event event = iterator.next();
        final CommandId eventRootCommandId = getRootCommandId(event);
        if (newCommandId.equals(eventRootCommandId)) {
            return true;
        }
    }
    return false;
}
Also used : Event(io.spine.core.Event) Events.getRootCommandId(io.spine.core.Events.getRootCommandId) CommandId(io.spine.core.CommandId)

Example 20 with CommandId

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

the class CommandScheduler method rememberAsScheduled.

private static void rememberAsScheduled(Command command) {
    final CommandId id = command.getId();
    scheduledCommandIds.add(id);
}
Also used : CommandId(io.spine.core.CommandId)

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