Search in sources :

Example 1 with Topic

use of io.spine.client.Topic 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(entity, requestFactory.createCommandContext());
    // isCompleted set to false since we don't expect activationObserver::onCompleted to be called.
    activationObserver.verifyState(false);
}
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) Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 2 with Topic

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

the class SubscriptionServiceShould method subscribe_to_topic.

/*
    * Subscription tests
    * ------------------
    */
@Test
public void subscribe_to_topic() {
    final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
    final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
    final String type = boundedContext.getStand().getExposedTypes().iterator().next().getTypeName();
    final Target target = getProjectQueryTarget();
    assertEquals(type, target.getType());
    final Topic topic = requestFactory.topic().forTarget(target);
    final MemoizeStreamObserver<Subscription> observer = new MemoizeStreamObserver<>();
    subscriptionService.subscribe(topic, observer);
    assertNotNull(observer.streamFlowValue);
    assertTrue(observer.streamFlowValue.isInitialized());
    assertEquals(observer.streamFlowValue.getTopic().getTarget().getType(), type);
    assertNull(observer.throwable);
    assertTrue(observer.isCompleted);
}
Also used : Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 3 with Topic

use of io.spine.client.Topic 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 failureMessage = "Execution breaking exception";
    final MemoizeStreamObserver<Response> observer = new MemoizeStreamObserver<Response>() {

        @Override
        public void onNext(Response value) {
            super.onNext(value);
            throw new RuntimeException(failureMessage);
        }
    };
    subscriptionService.cancel(subscriptionObserver.streamFlowValue, observer);
    assertNotNull(observer.streamFlowValue);
    assertFalse(observer.isCompleted);
    assertNotNull(observer.throwable);
    assertInstanceOf(RuntimeException.class, observer.throwable);
    assertEquals(observer.throwable.getMessage(), failureMessage);
}
Also used : Response(io.spine.base.Response) Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 4 with Topic

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

the class MultiTenantStandShould method subscribeToAllOf.

protected MemoizeEntityUpdateCallback subscribeToAllOf(Stand stand, ActorRequestFactory requestFactory, Class<? extends Message> entityClass) {
    final Topic allCustomers = requestFactory.topic().allOf(entityClass);
    final MemoizeEntityUpdateCallback callback = new MemoizeEntityUpdateCallback();
    subscribeAndActivate(stand, allCustomers, callback);
    assertNull(callback.getNewEntityState());
    return callback;
}
Also used : Topic(io.spine.client.Topic)

Example 5 with Topic

use of io.spine.client.Topic 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(boundedContext);
    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 = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(someId, Project.getDefaultInstance(), stateVersion));
    verify(executor, times(1)).execute(any(Runnable.class));
}
Also used : QueryResponse(io.spine.client.QueryResponse) Response(io.spine.base.Response) Executor(java.util.concurrent.Executor) Version(io.spine.base.Version) ProjectId(io.spine.test.projection.ProjectId) BoundedContext(io.spine.server.BoundedContext) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Topic (io.spine.client.Topic)13 Test (org.junit.Test)11 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Subscription (io.spine.client.Subscription)6 Version (io.spine.base.Version)5 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)4 Target (io.spine.client.Target)4 StandStorage (io.spine.server.stand.StandStorage)4 Map (java.util.Map)4 Any (com.google.protobuf.Any)3 Response (io.spine.base.Response)3 Customer (io.spine.test.commandservice.customer.Customer)3 CustomerId (io.spine.test.commandservice.customer.CustomerId)3 Message (com.google.protobuf.Message)2 SubscriptionUpdate (io.spine.client.SubscriptionUpdate)2 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)2 VersionableEntity (io.spine.server.entity.VersionableEntity)2 ProjectId (io.spine.test.aggregate.ProjectId)2 ProjectId (io.spine.test.projection.ProjectId)2 QueryResponse (io.spine.client.QueryResponse)1