Search in sources :

Example 11 with TenantId

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));
}
Also used : IdempotencyGuardTestEnv.newTenantId(io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) IgTestAggregate(io.spine.server.aggregate.given.aggregate.IgTestAggregate) IdempotencyGuardTestEnv.newProjectId(io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId) ProjectId(io.spine.test.aggregate.ProjectId) Ack(io.spine.core.Ack) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 12 with TenantId

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();
}
Also used : TenantId(io.spine.core.TenantId) Subscription(io.spine.client.Subscription) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 13 with TenantId

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

Example 14 with TenantId

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;
}
Also used : TenantId(io.spine.core.TenantId) Nullable(javax.annotation.Nullable)

Example 15 with TenantId

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());
}
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) Test(org.junit.Test)

Aggregations

TenantId (io.spine.core.TenantId)41 Test (org.junit.Test)27 Command (io.spine.core.Command)17 Ack (io.spine.core.Ack)11 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 CommandBus (io.spine.server.commandbus.CommandBus)6 Error (io.spine.base.Error)4 CommandId (io.spine.core.CommandId)4 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)4 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)4 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)4 Nullable (javax.annotation.Nullable)4 ActorContext (io.spine.core.ActorContext)3 CommandContext (io.spine.core.CommandContext)3 Rejection (io.spine.core.Rejection)3 BoundedContext (io.spine.server.BoundedContext)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3