use of io.spine.client.SubscriptionUpdate in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method activate_subscription.
@Test
public void activate_subscription() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final Target target = getProjectQueryTarget();
final Topic topic = requestFactory.topic().forTarget(target);
// Subscribe to the topic
final MemoizeStreamObserver<Subscription> subscriptionObserver = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, subscriptionObserver);
subscriptionObserver.verifyState();
// Activate subscription
final MemoizeStreamObserver<SubscriptionUpdate> activationObserver = new MemoizeStreamObserver<>();
subscriptionService.activate(subscriptionObserver.streamFlowValue, activationObserver);
// Post update to Stand directly
final ProjectId projectId = ProjectId.newBuilder().setId("some-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);
// isCompleted set to false since we don't expect activationObserver::onCompleted to be called.
activationObserver.verifyState(false);
}
use of io.spine.client.SubscriptionUpdate 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();
}
use of io.spine.client.SubscriptionUpdate in project core-java by SpineEventEngine.
the class SubscriptionService method activate.
@Override
public void activate(final Subscription subscription, final StreamObserver<SubscriptionUpdate> responseObserver) {
log().debug("Activating the subscription: {}", subscription);
try {
final BoundedContext boundedContext = selectBoundedContext(subscription);
final Stand.EntityUpdateCallback updateCallback = new Stand.EntityUpdateCallback() {
@Override
public void onStateChanged(EntityStateUpdate stateUpdate) {
checkNotNull(subscription);
final SubscriptionUpdate update = SubscriptionUpdate.newBuilder().setSubscription(subscription).setResponse(Responses.ok()).addEntityStateUpdates(stateUpdate).build();
responseObserver.onNext(update);
}
};
final Stand targetStand = boundedContext.getStand();
targetStand.activate(subscription, updateCallback, StreamObservers.<Response>forwardErrorsOnly(responseObserver));
} catch (@SuppressWarnings("OverlyBroadCatchBlock") Exception e) {
log().error("Error activating the subscription", e);
responseObserver.onError(e);
}
}
Aggregations