use of io.spine.core.TenantId in project core-java by SpineEventEngine.
the class IdempotencyGuardShould method not_throw_when_the_command_was_handled_but_the_snapshot_was_made.
@Test
public void not_throw_when_the_command_was_handled_but_the_snapshot_was_made() {
repository.setSnapshotTrigger(1);
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.TenantId in project core-java by SpineEventEngine.
the class Stand method subscribe.
/**
* Subscribes for all further changes of an entity state, which satisfies the {@link Topic}.
*
* <p>Once this instance of {@code Stand} receives an update of an entity
* with the given {@code TypeUrl}, all such callbacks are executed.
*
* @param topic an instance {@link Topic}, defining the entity and criteria,
* which changes should be propagated to the {@code callback}
*/
public void subscribe(final Topic topic, final StreamObserver<Subscription> responseObserver) {
topicValidator.validate(topic, responseObserver);
final TenantId tenantId = topic.getContext().getTenantId();
final TenantAwareOperation op = new TenantAwareOperation(tenantId) {
@Override
public void run() {
final Subscription subscription = subscriptionRegistry.add(topic);
responseObserver.onNext(subscription);
responseObserver.onCompleted();
}
};
op.execute();
}
use of io.spine.core.TenantId in project core-java by SpineEventEngine.
the class SubscriptionValidator method checkInRegistry.
private boolean checkInRegistry(Subscription request) {
final TenantId tenantId = request.getTopic().getContext().getTenantId();
final Boolean result = new TenantAwareFunction<Subscription, Boolean>(tenantId) {
@Override
public Boolean apply(@Nullable Subscription input) {
checkNotNull(input);
final boolean result = registry.containsId(input.getId());
return result;
}
}.execute(request);
checkNotNull(result);
return result;
}
use of io.spine.core.TenantId in project core-java by SpineEventEngine.
the class TenantFunction method execute.
/**
* Applies the function and returns the result.
*
* @return the result of the function
*/
@Nullable
public T execute() {
final TenantId currentTenant = tenantId();
final T result = apply(currentTenant);
return result;
}
use of io.spine.core.TenantId in project core-java by SpineEventEngine.
the class DuplicateCommandShould method not_be_acknowledged_on_client_when_not_sent.
@Test
public void not_be_acknowledged_on_client_when_not_sent() {
final TenantId tenantId = newTenantId();
final Command command = command(createProject(), tenantId);
final Ack ack = client.post(command);
final Status status = ack.getStatus();
assertTrue(status.hasOk());
}
Aggregations