use of io.spine.core.Version in project core-java by SpineEventEngine.
the class StandShould method trigger_each_subscription_callback_once_for_multiple_subscriptions.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void trigger_each_subscription_callback_once_for_multiple_subscriptions() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Target allCustomers = Targets.allOf(Customer.class);
final Set<MemoizeEntityUpdateCallback> callbacks = newHashSet();
final int totalCallbacks = 100;
for (int callbackIndex = 0; callbackIndex < totalCallbacks; callbackIndex++) {
final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allCustomers);
callbacks.add(callback);
}
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);
for (MemoizeEntityUpdateCallback callback : callbacks) {
assertEquals(packedState, callback.newEntityState);
verify(callback, times(1)).onStateChanged(any(EntityStateUpdate.class));
}
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class StandShould method do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch.
@Test
public void do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Target allProjects = Targets.allOf(Project.class);
final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allProjects);
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));
verify(callback, never()).onStateChanged(any(EntityStateUpdate.class));
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class RecordStorageShould method filter_records_by_columns.
// Complex test case (still tests a single operation)
@SuppressWarnings("OverlyLongMethod")
@Test
public void filter_records_by_columns() {
final Project.Status requiredValue = DONE;
final Int32Value wrappedValue = Int32Value.newBuilder().setValue(requiredValue.getNumber()).build();
final Version versionValue = Version.newBuilder().setNumber(// Value of the counter after one columns
2).build();
final ColumnFilter status = eq("projectStatusValue", wrappedValue);
final ColumnFilter version = eq("counterVersion", versionValue);
final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().setOperator(ALL).addFilter(status).addFilter(version).build();
final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
final RecordStorage<I> storage = getStorage();
final EntityQuery<I> query = EntityQueries.from(filters, storage);
final I idMatching = newId();
final I idWrong1 = newId();
final I idWrong2 = newId();
final TestCounterEntity<I> matchingEntity = new TestCounterEntity<>(idMatching);
final TestCounterEntity<I> wrongEntity1 = new TestCounterEntity<>(idWrong1);
final TestCounterEntity<I> wrongEntity2 = new TestCounterEntity<>(idWrong2);
// 2 of 3 have required values
matchingEntity.setStatus(requiredValue);
wrongEntity1.setStatus(requiredValue);
wrongEntity2.setStatus(CANCELLED);
// Change internal Entity state
wrongEntity1.getCounter();
// After the mutation above the single matching record is the one under the `idMatching` ID
final EntityRecord fineRecord = newStorageRecord(idMatching, newState(idMatching));
final EntityRecord notFineRecord1 = newStorageRecord(idWrong1, newState(idWrong1));
final EntityRecord notFineRecord2 = newStorageRecord(idWrong2, newState(idWrong2));
final EntityRecordWithColumns recordRight = create(fineRecord, matchingEntity, storage);
final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1, storage);
final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2, storage);
storage.write(idMatching, recordRight);
storage.write(idWrong1, recordWrong1);
storage.write(idWrong2, recordWrong2);
final Iterator<EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
assertSingleRecord(fineRecord, readRecords);
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class GivenVersionShould method generate_version_by_number.
@Test
public void generate_version_by_number() {
final int number = random(100);
final Version version = GivenVersion.withNumber(number);
assertEquals(number, version.getNumber());
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class EntityShould method have_state.
@Test
public void have_state() {
final Version ver = Versions.newVersion(3, getCurrentTime());
entityNew.updateState(state, ver);
assertEquals(state, entityNew.getState());
assertEquals(ver, entityNew.getVersion());
}
Aggregations