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);
}
}
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;
}
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);
}
}
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));
}
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);
}
Aggregations