use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class AggregateShould method create_single_event_for_a_pair_of_events_with_empty_for_a_rejection_react.
/**
* Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second optional
* value returned from a reaction on a rejection stores a single event.
*
* <p>The rejection is fired by the {@link TaskAggregate#handle(AggReassignTask)
* TaskAggregate.handle(AggReassignTask)}
* and handled by the {@link TaskAggregate#on(Rejections.AggCannotReassignUnassignedTask)
* TaskAggregate.on(AggCannotReassignUnassignedTask)}.
*/
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_a_rejection_react() {
final BoundedContext boundedContext = newTaskBoundedContext();
final TenantId tenantId = newTenantId();
final Command command = command(reassignTask(), tenantId);
final MemoizingObserver<Ack> observer = memoizingObserver();
boundedContext.getCommandBus().post(command, observer);
assertNull(observer.getError());
final List<Ack> responses = observer.responses();
assertSize(1, responses);
final Ack response = responses.get(0);
final io.spine.core.Status status = response.getStatus();
final Error emptyError = Error.getDefaultInstance();
assertEquals(emptyError, status.getError());
final Rejection emptyRejection = Rejection.getDefaultInstance();
assertEquals(emptyRejection, status.getRejection());
final List<Event> events = readAllEvents(boundedContext, tenantId);
assertSize(1, events);
final Event reactionEvent = events.get(0);
final TypeUrl userNotifiedType = TypeUrl.from(AggUserNotified.getDescriptor());
assertEquals(typeUrlOf(reactionEvent), userNotifiedType);
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class IdempotencyGuardShould method throw_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot.
@Test(expected = DuplicateCommandException.class)
public void throw_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot() {
final TenantId tenantId = newTenantId();
final ProjectId projectId = newProjectId();
final Command createCommand = command(createProject(projectId), tenantId);
final CommandBus commandBus = boundedContext.getCommandBus();
final StreamObserver<Ack> noOpObserver = noOpObserver();
commandBus.post(createCommand, noOpObserver);
final IgTestAggregate aggregate = repository.loadAggregate(tenantId, projectId);
final IdempotencyGuard guard = new IdempotencyGuard(aggregate);
guard.check(of(createCommand));
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class IntegrationBusShould method emit_unsupported_external_message_exception_if_message_type_is_unknown.
@Test
public void emit_unsupported_external_message_exception_if_message_type_is_unknown() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext boundedContext = contextWithTransport(transportFactory);
final Event event = projectCreated();
final BoundedContextName boundedContextName = BoundedContext.newName("External context ID");
final ExternalMessage externalMessage = ExternalMessages.of(event, boundedContextName);
final MemoizingObserver<Ack> observer = StreamObservers.memoizingObserver();
boundedContext.getIntegrationBus().post(externalMessage, observer);
final Error error = observer.firstResponse().getStatus().getError();
assertFalse(Validate.isDefault(error));
assertEquals(ExternalMessageValidationError.getDescriptor().getFullName(), error.getType());
assertTrue(UNSUPPORTED_EXTERNAL_MESSAGE.getNumber() == error.getCode());
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class CommandOutputBus method doPost.
@Override
protected Ack doPost(E envelope) {
final E enrichedEnvelope = enrich(envelope);
final int dispatchersCalled = callDispatchers(enrichedEnvelope);
final Any packedId = Identifier.pack(envelope.getId());
checkState(dispatchersCalled != 0, format("Message %s has no dispatchers.", envelope.getMessage()));
final Ack result = acknowledge(packedId);
return result;
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class AbstractCommandRouter method route.
/**
* Creates a new command from the passed message and posts it
* to the {@code CommandBus}.
*
* <p>This method waits till the posting of the command is finished.
*
* @param message the command message for the new command
* @return the created and posted {@code Command}
*/
protected Command route(Message message) {
final Command command = produceCommand(message);
final SettableFuture<Ack> finishFuture = SettableFuture.create();
final StreamObserver<Ack> observer = newAckingObserver(finishFuture);
commandBus.post(command, observer);
final Ack ack;
// Wait till the call is completed.
try {
ack = finishFuture.get();
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e);
}
checkSent(command, ack);
return command;
}
Aggregations