Search in sources :

Example 11 with Subscription

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

the class StandShould method allow_cancelling_subscriptions.

@Test
public void allow_cancelling_subscriptions() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allCustomers = requestFactory.topic().allOf(Customer.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    final Subscription subscription = subscribeAndActivate(stand, allCustomers, memoizeCallback);
    stand.cancel(subscription, StreamObservers.<Response>noOpObserver());
    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));
    assertNull(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) Subscription(io.spine.client.Subscription) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 12 with Subscription

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

the class StandShould method throw_invalid_subscription_ex_if_invalid_subscription_msg_passed_to_cancel.

@Test
public void throw_invalid_subscription_ex_if_invalid_subscription_msg_passed_to_cancel() {
    final Stand stand = Stand.newBuilder().build();
    final Subscription invalidSubscription = Subscription.getDefaultInstance();
    try {
        stand.cancel(invalidSubscription, StreamObservers.<Response>noOpObserver());
        fail("Expected IllegalArgumentException due to an invalid subscription message " + "passed to `cancel`, but got nothing");
    } catch (IllegalArgumentException e) {
        verifyInvalidSubscriptionException(invalidSubscription, e);
    }
}
Also used : Subscription(io.spine.client.Subscription) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 13 with Subscription

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

the class StandShould method throw_invalid_subscription_ex_if_activating_subscription_with_unsupported_target.

@Test
public void throw_invalid_subscription_ex_if_activating_subscription_with_unsupported_target() {
    final Stand stand = Stand.newBuilder().build();
    final Subscription subscription = subscriptionWithUnknownTopic();
    try {
        stand.activate(subscription, emptyUpdateCallback(), StreamObservers.<Response>noOpObserver());
        fail("Expected IllegalArgumentException upon activating an unknown subscription, " + "but got nothing");
    } catch (IllegalArgumentException e) {
        verifyUnknownSubscriptionException(e, subscription);
    }
}
Also used : Subscription(io.spine.client.Subscription) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 14 with Subscription

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

the class StandShould method fail_if_cancelling_inexistent_subscription.

@Test(expected = IllegalArgumentException.class)
public void fail_if_cancelling_inexistent_subscription() {
    final Stand stand = Stand.newBuilder().build();
    final Subscription inexistentSubscription = Subscription.newBuilder().setId(Subscriptions.generateId()).build();
    stand.cancel(inexistentSubscription, StreamObservers.<Response>noOpObserver());
}
Also used : Subscription(io.spine.client.Subscription) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 15 with Subscription

use of io.spine.client.Subscription 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)

Aggregations

Subscription (io.spine.client.Subscription)15 Test (org.junit.Test)12 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Topic (io.spine.client.Topic)6 Target (io.spine.client.Target)4 Response (io.spine.core.Response)3 Message (com.google.protobuf.Message)2 SubscriptionUpdate (io.spine.client.SubscriptionUpdate)2 TenantId (io.spine.core.TenantId)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 ProjectId (io.spine.test.aggregate.ProjectId)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1 QueryResponse (io.spine.client.QueryResponse)1 SubscriptionId (io.spine.client.SubscriptionId)1 BoundedContext (io.spine.server.BoundedContext)1 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)1