use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class EventStorage method iterator.
Iterator<Event> iterator(EventStreamQuery query) {
final EventRecordStorage storage = recordStorage();
final Map<EventId, EntityRecord> records = storage.readAll(query);
final Collection<EventEntity> entities = transform(records.entrySet(), storageRecordToEntity());
// TODO:2017-05-19:dmytro.dashenkov: Remove after the Entity Column approach is implemented.
final Collection<EventEntity> filtered = filter(entities, createEntityFilter(query));
final List<EventEntity> entityList = newArrayList(filtered);
Collections.sort(entityList, EventEntity.comparator());
final Iterator<Event> result = Iterators.transform(entityList.iterator(), getEventFunc());
return result;
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class ProjectionStorageShould method retrieve_empty_map_if_storage_is_empty.
// because the behaviour to test is different
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
@Test
public void retrieve_empty_map_if_storage_is_empty() {
final Map<I, EntityRecord> noMaskEntiries = storage.readAll();
final FieldMask nonEmptyMask = FieldMask.newBuilder().addPaths("invalid_path").build();
final Map<I, EntityRecord> maskedEntries = storage.readAll(nonEmptyMask);
assertEmpty(noMaskEntiries);
assertEmpty(maskedEntries);
// Same type
assertEquals(noMaskEntiries, maskedEntries);
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class EntityQueryMatcherShould method match_columns.
// Mocks <-> reflection issues
@SuppressWarnings("unchecked")
@Test
public void match_columns() {
final String targetName = "feature";
final Column<?> target = mock(Column.class);
when(target.isNullable()).thenReturn(true);
when(target.getName()).thenReturn(targetName);
when(target.getType()).thenReturn((Class) Boolean.class);
final Object acceptedValue = true;
final Collection<Object> ids = Collections.emptyList();
final Map<Column<?>, Object> params = ImmutableMap.<Column<?>, Object>of(target, acceptedValue);
final EntityQuery<?> query = EntityQuery.of(ids, params);
final Any matchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final Any nonMatchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
final EntityRecord matching = EntityRecord.newBuilder().setEntityId(matchingId).build();
final EntityRecord nonMatching = EntityRecord.newBuilder().setEntityId(nonMatchingId).build();
final Column.MemoizedValue storedValue = mock(Column.MemoizedValue.class);
when(storedValue.getSourceColumn()).thenReturn(target);
when(storedValue.getValue()).thenReturn(acceptedValue);
final Map<String, Column.MemoizedValue<?>> matchingColumns = ImmutableMap.<String, Column.MemoizedValue<?>>of(targetName, storedValue);
final EntityRecordWithColumns nonMatchingRecord = of(nonMatching);
final EntityRecordWithColumns matchingRecord = io.spine.server.entity.storage.EntityRecordWithColumns.of(matching, matchingColumns);
assertTrue(matcher.apply(matchingRecord));
assertFalse(matcher.apply(nonMatchingRecord));
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class StandStorageShould method checkIds.
protected void checkIds(List<AggregateStateId> ids, Collection<EntityRecord> records) {
assertSize(ids.size(), records);
final Collection<ProjectId> projectIds = Collections2.transform(ids, new Function<AggregateStateId, ProjectId>() {
@Nullable
@Override
public ProjectId apply(@Nullable AggregateStateId input) {
if (input == null) {
return null;
}
return (ProjectId) input.getAggregateId();
}
});
for (EntityRecord record : records) {
final Any packedState = record.getState();
final Project state = AnyPacker.unpack(packedState);
final ProjectId id = state.getId();
assertContains(id, projectIds);
}
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class StandStorageShould method retrieve_records_by_ids.
@Test
public void retrieve_records_by_ids() {
final StandStorage storage = getStorage();
// Use a subset of IDs
final List<AggregateStateId> ids = fill(storage, 10, DEFAULT_ID_SUPPLIER).subList(0, 5);
final Collection<EntityRecord> records = (Collection<EntityRecord>) storage.readMultiple(ids);
checkIds(ids, records);
}
Aggregations