Search in sources :

Example 11 with Target

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));
}
Also used : Message(com.google.protobuf.Message) Query(io.spine.client.Query) EntityFilters(io.spine.client.EntityFilters) ProjectId(io.spine.test.validate.msg.ProjectId) Matchers.containsString(org.hamcrest.Matchers.containsString) EntityId(io.spine.client.EntityId) Target(io.spine.client.Target) Test(org.junit.Test)

Example 12 with Target

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);
}
Also used : Target(io.spine.client.Target) Test(org.junit.Test)

Example 13 with Target

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);
    }
}
Also used : Stand(io.spine.server.stand.Stand) Target(io.spine.client.Target)

Example 14 with Target

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();
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.aggregate.ProjectId) SubscriptionUpdate(io.spine.client.SubscriptionUpdate) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity) Response(io.spine.core.Response) Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 15 with Target

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;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Target(io.spine.client.Target) ImmutableList(com.google.common.collect.ImmutableList) Any(com.google.protobuf.Any) FieldMask(com.google.protobuf.FieldMask)

Aggregations

Target (io.spine.client.Target)16 Test (org.junit.Test)10 Message (com.google.protobuf.Message)4 Subscription (io.spine.client.Subscription)4 Topic (io.spine.client.Topic)4 Any (com.google.protobuf.Any)3 EntityFilters (io.spine.client.EntityFilters)3 Query (io.spine.client.Query)3 ImmutableList (com.google.common.collect.ImmutableList)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 FieldMask (com.google.protobuf.FieldMask)2 EntityId (io.spine.client.EntityId)2 EntityStateUpdate (io.spine.client.EntityStateUpdate)2 SubscriptionUpdate (io.spine.client.SubscriptionUpdate)2 Response (io.spine.core.Response)2 Version (io.spine.core.Version)2 GivenVersion (io.spine.core.given.GivenVersion)2 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)2 VersionableEntity (io.spine.server.entity.VersionableEntity)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2