use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method write_record_bulk.
@Test
public void write_record_bulk() {
final RecordStorage<I> storage = getStorage();
final int bulkSize = 5;
final Map<I, EntityRecordWithColumns> initial = new HashMap<>(bulkSize);
for (int i = 0; i < bulkSize; i++) {
final I id = newId();
final EntityRecord record = newStorageRecord(id);
initial.put(id, EntityRecordWithColumns.of(record));
}
storage.write(initial);
final Collection<EntityRecord> actual = newLinkedList(storage.readMultiple(initial.keySet()));
final Collection<EntityRecord> expected = Collections2.transform(initial.values(), RECORD_EXTRACTOR_FUNCTION);
assertEquals(expected.size(), actual.size());
assertTrue(actual.containsAll(expected));
close(storage);
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method newStorageRecord.
private static EntityRecord newStorageRecord(Message state) {
final Any wrappedState = AnyPacker.pack(state);
final EntityRecord record = EntityRecord.newBuilder().setState(wrappedState).setVersion(Tests.newVersionWithNumber(0)).build();
return record;
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method read_multiple_records_with_field_mask.
@SuppressWarnings({ "MethodWithMultipleLoops", "ConstantConditions" })
// Converter nullability issues
@Test
public void read_multiple_records_with_field_mask() {
final RecordStorage<I> storage = getStorage();
final int count = 10;
final List<I> ids = new LinkedList<>();
Descriptors.Descriptor typeDescriptor = null;
for (int i = 0; i < count; i++) {
final I id = newId();
final Message state = newState(id);
final EntityRecord record = newStorageRecord(state);
storage.write(id, record);
ids.add(id);
if (typeDescriptor == null) {
typeDescriptor = state.getDescriptorForType();
}
}
final int bulkCount = count / 2;
final FieldMask fieldMask = FieldMasks.maskOf(typeDescriptor, 2);
final Iterable<EntityRecord> readRecords = storage.readMultiple(ids.subList(0, bulkCount), fieldMask);
final List<EntityRecord> readList = newLinkedList(readRecords);
Verify.assertSize(bulkCount, readList);
for (EntityRecord record : readRecords) {
final Message state = unpack(record.getState());
assertMatchesMask(state, fieldMask);
}
}
use of io.spine.server.entity.EntityRecord 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 = Project.Status.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 EntityFilters filters = EntityFilters.newBuilder().putColumnFilter("projectStatusValue", AnyPacker.pack(wrappedValue)).putColumnFilter("counterVersion", AnyPacker.pack(versionValue)).build();
final EntityQuery<I> query = EntityQueries.from(filters, TestCounterEntity.class);
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(Project.Status.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);
final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1);
final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2);
final RecordStorage<I> storage = getStorage();
storage.write(idMatching, recordRight);
storage.write(idWrong1, recordWrong1);
storage.write(idWrong2, recordWrong2);
final Map<I, EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
Verify.assertSize(1, readRecords);
final I singleId = readRecords.keySet().iterator().next();
assertEquals(idMatching, singleId);
final EntityRecord singleRecord = readRecords.values().iterator().next();
assertEquals(fineRecord, singleRecord);
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method newStorageRecord.
private EntityRecord newStorageRecord(I id, Message state) {
final Any wrappedState = AnyPacker.pack(state);
final EntityRecord record = EntityRecord.newBuilder().setEntityId(idToAny(id)).setState(wrappedState).setVersion(Tests.newVersionWithNumber(0)).build();
return record;
}
Aggregations