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));
}
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);
}
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;
}
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);
}
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();
}
Aggregations