use of org.neo4j.storageengine.api.StoragePropertyCursor in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdates.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityPropertyUpdates(boolean alsoWrite) throws Exception {
// given
StubStorageCursors data = someUniformData(10);
TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
Set<TestPropertyScanConsumer.Record> expectedUpdates = new HashSet<>();
try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL);
StoragePropertyCursor propertyCursor = data.allocatePropertyCursor(NULL, INSTANCE)) {
cursor.scan();
while (cursor.next()) {
cursor.properties(propertyCursor);
Map<Integer, Value> properties = new HashMap<>();
while (propertyCursor.next()) {
properties.put(propertyCursor.propertyKey(), propertyCursor.propertyValue());
}
expectedUpdates.add(new TestPropertyScanConsumer.Record(cursor.entityReference(), cursor.labels(), properties));
}
}
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
if (alsoWrite) {
for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
assertThat(expectedUpdates.remove(update)).isTrue();
}
} else {
GeneratedIndexUpdates updates = sender.batches.get(0);
updates.completeBatch();
for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
assertThat(expectedUpdates.remove(update)).isTrue();
}
}
assertThat(expectedUpdates).isEmpty();
}
Aggregations