use of io.spine.core.Response 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);
}
use of io.spine.core.Response in project core-java by SpineEventEngine.
the class StandShould method use_provided_executor_upon_update_of_watched_type.
@Test
public void use_provided_executor_upon_update_of_watched_type() {
final Executor executor = mock(Executor.class);
final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setCallbackExecutor(executor)).build();
final Stand stand = boundedContext.getStand();
final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository();
stand.registerTypeSupplier(standTestProjectionRepo);
final Topic projectProjections = requestFactory.topic().allOf(Project.class);
final MemoizingObserver<Subscription> observer = memoizingObserver();
stand.subscribe(projectProjections, observer);
final Subscription subscription = observer.firstResponse();
final StreamObserver<Response> noopObserver = noOpObserver();
stand.activate(subscription, emptyUpdateCallback(), noopObserver);
assertNotNull(subscription);
verify(executor, never()).execute(any(Runnable.class));
final ProjectId someId = ProjectId.getDefaultInstance();
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(someId, Project.getDefaultInstance(), stateVersion));
verify(executor, times(1)).execute(any(Runnable.class));
}
use of io.spine.core.Response 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();
}
Aggregations