Search in sources :

Example 1 with Subscription

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

the class StandShould method throw_invalid_subscription_ex_if_cancelling_subscription_with_unsupported_target.

@Test
public void throw_invalid_subscription_ex_if_cancelling_subscription_with_unsupported_target() {
    final Stand stand = Stand.newBuilder().build();
    final Subscription subscription = subscriptionWithUnknownTopic();
    try {
        stand.cancel(subscription, StreamObservers.<Response>noOpObserver());
        fail("Expected IllegalArgumentException upon cancelling 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 2 with Subscription

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

the class StandShould method subscribeAndActivate.

@CanIgnoreReturnValue
protected static Subscription subscribeAndActivate(Stand stand, Topic topic, Stand.EntityUpdateCallback callback) {
    final MemoizingObserver<Subscription> observer = memoizingObserver();
    stand.subscribe(topic, observer);
    final Subscription subscription = observer.firstResponse();
    stand.activate(subscription, callback, StreamObservers.<Response>noOpObserver());
    assertNotNull(subscription);
    return subscription;
}
Also used : Subscription(io.spine.client.Subscription) CanIgnoreReturnValue(com.google.errorprone.annotations.CanIgnoreReturnValue)

Example 3 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_activate.

@Test
public void throw_invalid_subscription_ex_if_invalid_subscription_msg_passed_to_activate() {
    final Stand stand = Stand.newBuilder().build();
    final Subscription invalidSubscription = Subscription.getDefaultInstance();
    try {
        stand.activate(invalidSubscription, emptyUpdateCallback(), StreamObservers.<Response>noOpObserver());
        fail("Expected IllegalArgumentException due to an invalid subscription message " + "passed to `activate`, 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 4 with Subscription

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

the class SubscriptionRecordShould method be_equal_if_has_same_subscription.

@Test
public void be_equal_if_has_same_subscription() {
    final Subscription oneSubscription = Given.subscription();
    final SubscriptionId breakingId = Subscriptions.newId("breaking-id");
    final Subscription otherSubscription = Subscription.newBuilder().setId(breakingId).build();
    @SuppressWarnings("QuestionableName") final SubscriptionRecord one = new SubscriptionRecord(oneSubscription, Given.target(), Given.TYPE);
    final SubscriptionRecord similar = new SubscriptionRecord(otherSubscription, Given.target(), Given.TYPE);
    final SubscriptionRecord same = new SubscriptionRecord(oneSubscription, Given.target(), Given.TYPE);
    assertFalse(one.equals(similar));
    assertTrue(one.equals(same));
}
Also used : SubscriptionId(io.spine.client.SubscriptionId) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 5 with Subscription

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

the class SubscriptionServiceShould method handle_cancellation_process_exceptions_and_call_observer_error_callback.

@Test
public void handle_cancellation_process_exceptions_and_call_observer_error_callback() {
    final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
    final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
    final Target target = getProjectQueryTarget();
    final Topic topic = requestFactory.topic().forTarget(target);
    final MemoizeStreamObserver<Subscription> subscriptionObserver = new MemoizeStreamObserver<>();
    subscriptionService.subscribe(topic, subscriptionObserver);
    final String rejectionMessage = "Execution breaking exception";
    final MemoizeStreamObserver<Response> observer = new MemoizeStreamObserver<Response>() {

        @Override
        public void onNext(Response value) {
            super.onNext(value);
            throw new RuntimeException(rejectionMessage);
        }
    };
    subscriptionService.cancel(subscriptionObserver.streamFlowValue, observer);
    assertNotNull(observer.streamFlowValue);
    assertFalse(observer.isCompleted);
    assertNotNull(observer.throwable);
    assertInstanceOf(RuntimeException.class, observer.throwable);
    assertEquals(observer.throwable.getMessage(), rejectionMessage);
}
Also used : 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