Search in sources :

Example 11 with Topic

use of io.spine.client.Topic 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 12 with Topic

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

the class StandShould method trigger_subscription_callback_upon_update_of_projection.

@Test
public void trigger_subscription_callback_upon_update_of_projection() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allProjects = requestFactory.topic().allOf(Project.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    subscribeAndActivate(stand, allProjects, memoizeCallback);
    assertNull(memoizeCallback.newEntityState);
    final Map.Entry<ProjectId, Project> sampleData = fillSampleProjects(1).entrySet().iterator().next();
    final ProjectId projectId = sampleData.getKey();
    final Project project = sampleData.getValue();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(projectId, project, stateVersion));
    final Any packedState = AnyPacker.pack(project);
    assertEquals(packedState, memoizeCallback.newEntityState);
}
Also used : Project(io.spine.test.projection.Project) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) ProjectId(io.spine.test.projection.ProjectId) Topic(io.spine.client.Topic) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 13 with Topic

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

the class StandShould method trigger_subscription_callback_upon_update_of_aggregate.

@Test
public void trigger_subscription_callback_upon_update_of_aggregate() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allCustomers = requestFactory.topic().allOf(Customer.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    subscribeAndActivate(stand, allCustomers, memoizeCallback);
    assertNull(memoizeCallback.newEntityState);
    final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
    final CustomerId customerId = sampleData.getKey();
    final Customer customer = sampleData.getValue();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(customerId, customer, stateVersion));
    final Any packedState = AnyPacker.pack(customer);
    assertEquals(packedState, memoizeCallback.newEntityState);
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) CustomerId(io.spine.test.commandservice.customer.CustomerId) Topic(io.spine.client.Topic) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Topic (io.spine.client.Topic)13 Test (org.junit.Test)11 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Subscription (io.spine.client.Subscription)6 Version (io.spine.core.Version)5 GivenVersion (io.spine.core.given.GivenVersion)5 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)4 Target (io.spine.client.Target)4 Map (java.util.Map)4 Response (io.spine.core.Response)3 Customer (io.spine.test.commandservice.customer.Customer)3 CustomerId (io.spine.test.commandservice.customer.CustomerId)3 Any (com.google.protobuf.Any)2 Message (com.google.protobuf.Message)2 SubscriptionUpdate (io.spine.client.SubscriptionUpdate)2 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)2 VersionableEntity (io.spine.server.entity.VersionableEntity)2 ProjectId (io.spine.test.aggregate.ProjectId)2 ProjectId (io.spine.test.projection.ProjectId)2 EntityStateUpdate (io.spine.client.EntityStateUpdate)1