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());
}
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));
}
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);
}
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);
}
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);
}
Aggregations