Search in sources :

Example 31 with Version

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

the class MultiTenantStandShould method not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions.

@Test
public void not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions() {
    final StandStorage standStorage = InMemoryStorageFactory.newInstance(newName(getClass().getSimpleName()), isMultitenant()).createStandStorage();
    final Stand stand = prepareStandWithAggregateRepo(standStorage);
    // --- Default Tenant
    final ActorRequestFactory requestFactory = getRequestFactory();
    final MemoizeEntityUpdateCallback defaultTenantCallback = subscribeToAllOf(stand, requestFactory, Customer.class);
    // --- Another Tenant
    final TenantId anotherTenant = newUuid();
    final ActorRequestFactory anotherFactory = createRequestFactory(anotherTenant);
    final MemoizeEntityUpdateCallback anotherCallback = subscribeToAllOf(stand, anotherFactory, Customer.class);
    // Trigger updates in Default Tenant.
    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));
    final Any packedState = AnyPacker.pack(customer);
    // Verify that Default Tenant callback has got the update.
    assertEquals(packedState, defaultTenantCallback.getNewEntityState());
    // And Another Tenant callback has not been called.
    assertEquals(null, anotherCallback.getNewEntityState());
}
Also used : TenantId(io.spine.core.TenantId) Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) ActorRequestFactory(io.spine.client.ActorRequestFactory) CustomerId(io.spine.test.commandservice.customer.CustomerId) Map(java.util.Map) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 32 with Version

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

the class StandPostShould method deliver_updates.

// **** Positive scenarios (unit) ****
@SuppressWarnings({ "OverlyComplexAnonymousInnerClass", "ConstantConditions" })
@Test
public void deliver_updates() {
    final AggregateRepository<ProjectId, Given.StandTestAggregate> repository = Given.aggregateRepo();
    final ProjectId entityId = ProjectId.newBuilder().setId("PRJ-001").build();
    final Given.StandTestAggregate entity = repository.create(entityId);
    final StringValue state = entity.getState();
    final Version version = entity.getVersion();
    final Stand innerStand = Stand.newBuilder().build();
    final Stand stand = spy(innerStand);
    stand.post(requestFactory.createCommandContext().getActorContext().getTenantId(), entity);
    final ArgumentMatcher<EntityStateEnvelope<?, ?>> argumentMatcher = new ArgumentMatcher<EntityStateEnvelope<?, ?>>() {

        @Override
        public boolean matches(EntityStateEnvelope<?, ?> argument) {
            final boolean entityIdMatches = argument.getEntityId().equals(entityId);
            final boolean versionMatches = version.equals(argument.getEntityVersion().orNull());
            final boolean stateMatches = argument.getMessage().equals(state);
            return entityIdMatches && versionMatches && stateMatches;
        }
    };
    verify(stand).update(ArgumentMatchers.argThat(argumentMatcher));
}
Also used : EntityStateEnvelope(io.spine.server.entity.EntityStateEnvelope) Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) ArgumentMatcher(org.mockito.ArgumentMatcher) ProjectId(io.spine.test.projection.ProjectId) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 33 with Version

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

the class StandShould method doCheckReadingCustomersByIdAndFieldMask.

@SuppressWarnings("MethodWithMultipleLoops")
private void doCheckReadingCustomersByIdAndFieldMask(String... paths) {
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());
    final int querySize = 2;
    final Set<CustomerId> ids = new HashSet<>();
    for (int i = 0; i < querySize; i++) {
        final Customer customer = getSampleCustomer().toBuilder().setId(CustomerId.newBuilder().setNumber(i)).build();
        final Version stateVersion = GivenVersion.withNumber(1);
        stand.update(asEnvelope(customer.getId(), customer, stateVersion));
        ids.add(customer.getId());
    }
    final Query customerQuery = requestFactory.query().byIdsWithMask(Customer.class, ids, paths);
    final FieldMask fieldMask = FieldMask.newBuilder().addAllPaths(Arrays.asList(paths)).build();
    final MemoizeQueryResponseObserver observer = new MemoizeQueryResponseObserver() {

        @Override
        public void onNext(QueryResponse value) {
            super.onNext(value);
            final List<Any> messages = value.getMessagesList();
            Verify.assertSize(ids.size(), messages);
            for (Any message : messages) {
                final Customer customer = unpack(message);
                assertNotEquals(customer, null);
                assertMatches(customer, fieldMask);
            }
        }
    };
    stand.execute(customerQuery, observer);
    verifyObserver(observer);
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) QueryResponse(io.spine.client.QueryResponse) FieldMask(com.google.protobuf.FieldMask) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet)

Example 34 with Version

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

the class StandShould method requestSampleCustomer.

private void requestSampleCustomer(int[] fieldIndexes, final MemoizeQueryResponseObserver observer) {
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());
    final Customer sampleCustomer = getSampleCustomer();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(sampleCustomer.getId(), sampleCustomer, stateVersion));
    final String[] paths = new String[fieldIndexes.length];
    for (int i = 0; i < fieldIndexes.length; i++) {
        paths[i] = Customer.getDescriptor().getFields().get(fieldIndexes[i]).getFullName();
    }
    final Query customerQuery = requestFactory.query().allWithMask(Customer.class, paths);
    stand.execute(customerQuery, observer);
    verifyObserver(observer);
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version)

Example 35 with Version

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

the class StandShould method trigger_subscription_callback_upon_update_of_projection.

@Test
public void trigger_subscription_callback_upon_update_of_projection() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allProjects = requestFactory.topic().allOf(Project.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    subscribeAndActivate(stand, allProjects, memoizeCallback);
    assertNull(memoizeCallback.newEntityState);
    final Map.Entry<ProjectId, Project> sampleData = fillSampleProjects(1).entrySet().iterator().next();
    final ProjectId projectId = sampleData.getKey();
    final Project project = sampleData.getValue();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(projectId, project, stateVersion));
    final Any packedState = AnyPacker.pack(project);
    assertEquals(packedState, memoizeCallback.newEntityState);
}
Also used : Project(io.spine.test.projection.Project) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) ProjectId(io.spine.test.projection.ProjectId) Topic(io.spine.client.Topic) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Any(com.google.protobuf.Any) 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