use of io.spine.client.Target in project core-java by SpineEventEngine.
the class QueryBuilderShould method persist_only_last_ids_clause.
@Test
public void persist_only_last_ids_clause() {
final Iterable<?> genericIds = asList(newUuid(), -1, newMessageId());
final Long[] longIds = { 1L, 2L, 3L };
final Message[] messageIds = { newMessageId(), newMessageId(), newMessageId() };
final String[] stringIds = { newUuid(), newUuid(), newUuid() };
final Integer[] intIds = { 4, 5, 6 };
final Query query = factory().query().select(TestEntity.class).byId(genericIds).byId(longIds).byId(stringIds).byId(intIds).byId(messageIds).build();
assertNotNull(query);
final Target target = query.getTarget();
final EntityFilters filters = target.getFilters();
final Collection<EntityId> entityIds = filters.getIdFilter().getIdsList();
assertSize(messageIds.length, entityIds);
final Function<EntityId, ProjectId> transformer = new EntityIdUnpacker<>(ProjectId.class);
final Iterable<? extends Message> actualValues = transform(entityIds, transformer);
assertThat(actualValues, containsInAnyOrder(messageIds));
}
use of io.spine.client.Target in project core-java by SpineEventEngine.
the class TopicFactoryShould method create_topic_for_given_target.
@Test
public void create_topic_for_given_target() {
final Target givenTarget = Targets.allOf(TARGET_ENTITY_CLASS);
final Topic topic = factory().topic().forTarget(givenTarget);
verifyTargetAndContext(topic);
}
use of io.spine.client.Target in project core-java by SpineEventEngine.
the class SubscriptionService method subscribe.
@Override
public void subscribe(Topic topic, StreamObserver<Subscription> responseObserver) {
log().debug("Creating the subscription to a topic: {}", topic);
try {
final Target target = topic.getTarget();
final BoundedContext boundedContext = selectBoundedContext(target);
final Stand stand = boundedContext.getStand();
stand.subscribe(topic, responseObserver);
} catch (@SuppressWarnings("OverlyBroadCatchBlock") Exception e) {
log().error("Error processing subscription request", e);
responseObserver.onError(e);
}
}
use of io.spine.client.Target in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method cancel_subscription_on_topic.
@Test
public void cancel_subscription_on_topic() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final Target target = getProjectQueryTarget();
final Topic topic = requestFactory.topic().forTarget(target);
// Subscribe
final MemoizeStreamObserver<Subscription> subscribeObserver = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, subscribeObserver);
// Activate subscription
final MemoizeStreamObserver<SubscriptionUpdate> activateSubscription = spy(new MemoizeStreamObserver<SubscriptionUpdate>());
subscriptionService.activate(subscribeObserver.streamFlowValue, activateSubscription);
// Cancel subscription
subscriptionService.cancel(subscribeObserver.streamFlowValue, new MemoizeStreamObserver<Response>());
// Post update to Stand
final ProjectId projectId = ProjectId.newBuilder().setId("some-other-id").build();
final Message projectState = Project.newBuilder().setId(projectId).build();
final int version = 1;
final VersionableEntity entity = mockEntity(projectId, projectState, version);
boundedContext.getStand().post(requestFactory.createCommandContext().getActorContext().getTenantId(), entity);
// The update must not be handled by the observer
verify(activateSubscription, never()).onNext(any(SubscriptionUpdate.class));
verify(activateSubscription, never()).onCompleted();
}
use of io.spine.client.Target in project core-java by SpineEventEngine.
the class AggregateQueryProcessor method process.
@Override
public ImmutableCollection<Any> process(Query query) {
final ImmutableList.Builder<Any> resultBuilder = ImmutableList.builder();
Iterator<EntityRecord> stateRecords;
final Target target = query.getTarget();
final FieldMask fieldMask = query.getFieldMask();
final boolean shouldApplyFieldMask = !fieldMask.getPathsList().isEmpty();
if (target.getIncludeAll()) {
stateRecords = shouldApplyFieldMask ? standStorage.readAllByType(type, fieldMask) : standStorage.readAllByType(type);
} else {
stateRecords = doFetchWithFilters(target, fieldMask);
}
while (stateRecords.hasNext()) {
final EntityRecord record = stateRecords.next();
final Any state = record.getState();
resultBuilder.add(state);
}
final ImmutableList<Any> result = resultBuilder.build();
return result;
}
Aggregations