Search in sources :

Example 11 with Version

use of io.spine.core.Version 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));
}
Also used : QueryResponse(io.spine.client.QueryResponse) Response(io.spine.core.Response) Executor(java.util.concurrent.Executor) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.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)

Example 12 with Version

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

the class StandShould method triggerMultipleUpdates.

private void triggerMultipleUpdates(Map<CustomerId, Customer> sampleCustomers, Stand stand) {
    // Trigger the aggregate state updates.
    for (CustomerId id : sampleCustomers.keySet()) {
        final Customer sampleCustomer = sampleCustomers.get(id);
        final Version stateVersion = GivenVersion.withNumber(1);
        stand.update(asEnvelope(id, sampleCustomer, stateVersion));
    }
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) CustomerId(io.spine.test.commandservice.customer.CustomerId)

Example 13 with Version

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

the class StandShould method operate_with_storage_provided_through_builder.

@SuppressWarnings("OverlyCoupledMethod")
@Test
public void operate_with_storage_provided_through_builder() {
    final StandStorage standStorageMock = mock(StandStorage.class);
    final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setStorage(standStorageMock)).build();
    final Stand stand = boundedContext.getStand();
    assertNotNull(stand);
    final CustomerAggregateRepository customerAggregateRepo = new CustomerAggregateRepository();
    stand.registerTypeSupplier(customerAggregateRepo);
    final int numericIdValue = 17;
    final CustomerId customerId = customerIdFor(numericIdValue);
    final CustomerAggregate customerAggregate = customerAggregateRepo.create(customerId);
    final Customer customerState = customerAggregate.getState();
    final TypeUrl customerType = TypeUrl.of(Customer.class);
    final Version stateVersion = GivenVersion.withNumber(1);
    verify(standStorageMock, never()).write(any(AggregateStateId.class), any(EntityRecordWithColumns.class));
    stand.update(asEnvelope(customerId, customerState, stateVersion));
    final AggregateStateId expectedAggregateStateId = AggregateStateId.of(customerId, customerType);
    final Any packedState = AnyPacker.pack(customerState);
    final EntityRecord expectedRecord = EntityRecord.newBuilder().setState(packedState).build();
    verify(standStorageMock, times(1)).write(eq(expectedAggregateStateId), recordStateMatcher(expectedRecord));
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) TypeUrl(io.spine.type.TypeUrl) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) CustomerAggregate(io.spine.server.Given.CustomerAggregate) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) BoundedContext(io.spine.server.BoundedContext) CustomerAggregateRepository(io.spine.server.Given.CustomerAggregateRepository) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 14 with Version

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

the class StandShould method allow_cancelling_subscriptions.

@Test
public void allow_cancelling_subscriptions() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allCustomers = requestFactory.topic().allOf(Customer.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    final Subscription subscription = subscribeAndActivate(stand, allCustomers, memoizeCallback);
    stand.cancel(subscription, StreamObservers.<Response>noOpObserver());
    final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
    final CustomerId customerId = sampleData.getKey();
    final Customer customer = sampleData.getValue();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(customerId, customer, stateVersion));
    assertNull(memoizeCallback.newEntityState);
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) CustomerId(io.spine.test.commandservice.customer.CustomerId) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 15 with Version

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

the class StandShould method trigger_subscription_callbacks_matching_by_id.

@Test
public void trigger_subscription_callbacks_matching_by_id() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Map<CustomerId, Customer> sampleCustomers = fillSampleCustomers(10);
    final Topic someCustomers = requestFactory.topic().someOf(Customer.class, sampleCustomers.keySet());
    final Map<CustomerId, Customer> callbackStates = newHashMap();
    final MemoizeEntityUpdateCallback callback = new MemoizeEntityUpdateCallback() {

        @Override
        public void onStateChanged(EntityStateUpdate update) {
            super.onStateChanged(update);
            final Customer customerInCallback = unpack(update.getState());
            final CustomerId customerIdInCallback = unpack(update.getId());
            callbackStates.put(customerIdInCallback, customerInCallback);
        }
    };
    subscribeAndActivate(stand, someCustomers, callback);
    for (Map.Entry<CustomerId, Customer> sampleEntry : sampleCustomers.entrySet()) {
        final CustomerId customerId = sampleEntry.getKey();
        final Customer customer = sampleEntry.getValue();
        final Version stateVersion = GivenVersion.withNumber(1);
        stand.update(asEnvelope(customerId, customer, stateVersion));
    }
    assertEquals(newHashMap(sampleCustomers), callbackStates);
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) EntityStateUpdate(io.spine.client.EntityStateUpdate) CustomerId(io.spine.test.commandservice.customer.CustomerId) Topic(io.spine.client.Topic) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Version (io.spine.core.Version)41 Test (org.junit.Test)33 GivenVersion (io.spine.core.given.GivenVersion)16 Customer (io.spine.test.commandservice.customer.Customer)13 Any (com.google.protobuf.Any)11 Versions.newVersion (io.spine.core.Versions.newVersion)11 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)11 Event (io.spine.core.Event)10 CustomerId (io.spine.test.commandservice.customer.CustomerId)10 Map (java.util.Map)7 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)6 Query (io.spine.client.Query)5 Topic (io.spine.client.Topic)5 QueryResponse (io.spine.client.QueryResponse)4 ProjectId (io.spine.test.projection.ProjectId)4 Message (com.google.protobuf.Message)3 Timestamp (com.google.protobuf.Timestamp)3 EntityStateUpdate (io.spine.client.EntityStateUpdate)3 EntityRecord (io.spine.server.entity.EntityRecord)3 Project (io.spine.test.aggregate.Project)3