Search in sources :

Example 26 with Ack

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

the class BoundedContextShould method not_notify_integration_event_subscriber_if_event_is_invalid.

@Test
public void not_notify_integration_event_subscriber_if_event_is_invalid() {
    final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(true).build();
    // Unsupported message.
    final Any invalidMsg = AnyPacker.pack(BcProjectCreated.getDefaultInstance());
    final IntegrationEvent event = Given.AnIntegrationEvent.projectCreated().toBuilder().setMessage(invalidMsg).build();
    final MemoizingObserver<Ack> observer = memoizingObserver();
    boundedContext.notify(event, observer);
    assertEquals(ERROR, observer.firstResponse().getStatus().getStatusCase());
}
Also used : Ack(io.spine.core.Ack) IntegrationEvent(io.spine.server.integration.IntegrationEvent) BoundedContext(io.spine.server.BoundedContext) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 27 with Ack

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

the class DuplicateCommandShould method be_acknowledged_on_client_when_posted_to_an_aggregate.

@Test
public void be_acknowledged_on_client_when_posted_to_an_aggregate() {
    final TenantId tenantId = newTenantId();
    final Command command = command(createProject(), tenantId);
    client.post(command);
    final Ack ack = client.post(command);
    final Status status = ack.getStatus();
    final Error error = status.getError();
    final String errorType = error.getType();
    final String expectedErrorType = DuplicateCommandException.class.getCanonicalName();
    assertEquals(expectedErrorType, errorType);
}
Also used : Status(io.spine.core.Status) TenantId(io.spine.core.TenantId) DuplicateCommandTestEnv.newTenantId(io.spine.server.command.given.DuplicateCommandTestEnv.newTenantId) Command(io.spine.core.Command) Ack(io.spine.core.Ack) Error(io.spine.base.Error) Test(org.junit.Test)

Example 28 with Ack

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

the class Buses method setStatus.

private static Ack setStatus(Message id, Status status) {
    checkNotNull(id);
    final Any packedId = pack(id);
    final Ack result = Ack.newBuilder().setMessageId(packedId).setStatus(status).build();
    return result;
}
Also used : Ack(io.spine.core.Ack) Any(com.google.protobuf.Any)

Example 29 with Ack

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

the class TestClient method post.

/**
 * Creates a command for the passed message and sends it to the server.
 */
@CanIgnoreReturnValue
public Optional<Ack> post(CommandMessage domainCommand) {
    var command = requestFactory.command().create(domainCommand);
    var commandType = TypeName.of(domainCommand);
    Ack result = null;
    try {
        _debug().log("Sending command: `%s` ...", commandType);
        result = commandClient.post(command);
        _debug().log("Ack: `%s`.", result);
    } catch (RuntimeException e) {
        _warn().withCause(e).log(RPC_FAILED);
    }
    return Optional.ofNullable(result);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) Ack(io.spine.core.Ack) CanIgnoreReturnValue(com.google.errorprone.annotations.CanIgnoreReturnValue)

Aggregations

Ack (io.spine.core.Ack)29 Test (org.junit.Test)18 Command (io.spine.core.Command)15 Error (io.spine.base.Error)11 TenantId (io.spine.core.TenantId)11 CommandBus (io.spine.server.commandbus.CommandBus)7 Any (com.google.protobuf.Any)6 Event (io.spine.core.Event)6 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6 Rejection (io.spine.core.Rejection)5 BoundedContext (io.spine.server.BoundedContext)5 ProjectId (io.spine.test.aggregate.ProjectId)4 Status (io.spine.core.Status)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)3 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)3 Rejections.toRejection (io.spine.core.Rejections.toRejection)2