Search in sources :

Example 26 with TenantId

use of io.spine.core.TenantId 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));
}
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 27 with TenantId

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

the class EventStoreShould method fail_to_store_events_of_different_tenants_in_a_single_operation.

@Test(expected = IllegalArgumentException.class)
public void fail_to_store_events_of_different_tenants_in_a_single_operation() {
    final TenantId firstTenantId = TenantId.newBuilder().setValue("abc").build();
    final TenantId secondTenantId = TenantId.newBuilder().setValue("xyz").build();
    final ActorContext firstTenantActor = ActorContext.newBuilder().setTenantId(firstTenantId).build();
    final ActorContext secondTenantActor = ActorContext.newBuilder().setTenantId(secondTenantId).build();
    final CommandContext firstTenantCommand = CommandContext.newBuilder().setActorContext(firstTenantActor).build();
    final CommandContext secondTenantCommand = CommandContext.newBuilder().setActorContext(secondTenantActor).build();
    final EventContext firstTenantContext = EventContext.newBuilder().setCommandContext(firstTenantCommand).build();
    final EventContext secondTenantContext = EventContext.newBuilder().setCommandContext(secondTenantCommand).build();
    final Event firstTenantEvent = Event.newBuilder().setContext(firstTenantContext).build();
    final Event secondTenantEvent = Event.newBuilder().setContext(secondTenantContext).build();
    final Collection<Event> event = ImmutableSet.of(firstTenantEvent, secondTenantEvent);
    eventStore.appendAll(event);
}
Also used : EventContext(io.spine.core.EventContext) TenantId(io.spine.core.TenantId) CommandContext(io.spine.core.CommandContext) Event(io.spine.core.Event) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Example 28 with TenantId

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

the class EventBusTestEnv method tenantId.

private static TenantId tenantId() {
    final String value = EventBusTestEnv.class.getName();
    final TenantId id = TenantId.newBuilder().setValue(value).build();
    return id;
}
Also used : TenantId(io.spine.core.TenantId)

Example 29 with TenantId

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

the class Given method invalidProjectNameRejection.

public static Rejection invalidProjectNameRejection() {
    final ProjectId projectId = newProjectId();
    final ProjectRejections.InvalidProjectName invalidProjectName = ProjectRejections.InvalidProjectName.newBuilder().setProjectId(projectId).build();
    final StringChange nameChange = StringChange.newBuilder().setNewValue("Too short").build();
    final RjUpdateProjectName updateProjectName = RjUpdateProjectNameVBuilder.newBuilder().setId(projectId).setNameUpdate(nameChange).build();
    final TenantId generatedTenantId = TenantId.newBuilder().setValue(newUuid()).build();
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(RejectionBusShould.class, generatedTenantId);
    final Command command = factory.createCommand(updateProjectName);
    return Rejections.createRejection(invalidProjectName, command);
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) ProjectRejections(io.spine.test.rejection.ProjectRejections) ProjectId(io.spine.test.rejection.ProjectId) RjUpdateProjectName(io.spine.test.rejection.command.RjUpdateProjectName) StringChange(io.spine.change.StringChange)

Example 30 with TenantId

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

the class InMemoryProjectionStorage method readLastHandledEventTime.

@Override
public Timestamp readLastHandledEventTime() {
    final TenantFunction<Timestamp> func = new TenantFunction<Timestamp>(isMultitenant()) {

        @Nullable
        @Override
        public Timestamp apply(@Nullable TenantId tenantId) {
            checkNotNull(tenantId);
            final Timestamp result = timestampOfLastEvent.get(tenantId);
            return result;
        }
    };
    return func.execute();
}
Also used : TenantId(io.spine.core.TenantId) Timestamp(com.google.protobuf.Timestamp) TenantFunction(io.spine.server.tenant.TenantFunction) Nullable(javax.annotation.Nullable)

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