use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.
the class RecordStorageReaderRelTypesAndDegreeTest method testRelationshipTypesForDenseNode.
protected void testRelationshipTypesForDenseNode(LongConsumer nodeChanger, Set<TestRelType> expectedTypes) throws Exception {
int inRelCount = randomRelCount();
int outRelCount = randomRelCount();
int loopRelCount = randomRelCount();
long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
nodeChanger.accept(nodeId);
StorageNodeCursor cursor = newCursor(nodeId);
assertEquals(expectedTypes, relTypes(cursor));
}
use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.
the class RecordStorageReaderRelTypesAndDegreeTest method testDegreeByDirectionForDenseNodeWithPartiallyDeletedRelGroupChain.
protected void testDegreeByDirectionForDenseNodeWithPartiallyDeletedRelGroupChain(TestRelType... typesToDelete) throws Exception {
int inRelCount = randomRelCount();
int outRelCount = randomRelCount();
int loopRelCount = randomRelCount();
long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
StorageNodeCursor cursor = newCursor(nodeId);
for (TestRelType type : typesToDelete) {
markRelGroupNotInUse(nodeId, type);
switch(type) {
case IN:
inRelCount = 0;
break;
case OUT:
outRelCount = 0;
break;
case LOOP:
loopRelCount = 0;
break;
default:
throw new IllegalArgumentException("Unknown type: " + type);
}
}
assertEquals(outRelCount + loopRelCount, degreeForDirection(cursor, OUTGOING));
assertEquals(inRelCount + loopRelCount, degreeForDirection(cursor, INCOMING));
assertEquals(inRelCount + outRelCount + loopRelCount, degreeForDirection(cursor, BOTH));
}
use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.
the class RecordStorageReaderRelTypesAndDegreeTest method testDegreesForDenseNodeWithPartiallyDeletedRelChains.
protected void testDegreesForDenseNodeWithPartiallyDeletedRelChains(boolean modifyInChain, boolean modifyOutChain, boolean modifyLoopChain) throws Exception {
int inRelCount = randomRelCount();
int outRelCount = randomRelCount();
int loopRelCount = randomRelCount();
long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
StorageNodeCursor cursor = newCursor(nodeId);
if (modifyInChain) {
markRandomRelsInGroupNotInUse(nodeId, IN);
}
if (modifyOutChain) {
markRandomRelsInGroupNotInUse(nodeId, OUT);
}
if (modifyLoopChain) {
markRandomRelsInGroupNotInUse(nodeId, LOOP);
}
Set<TestDegreeItem> expectedDegrees = new HashSet<>(asList(new TestDegreeItem(relTypeId(OUT), outRelCount, 0), new TestDegreeItem(relTypeId(IN), 0, inRelCount), new TestDegreeItem(relTypeId(LOOP), loopRelCount, loopRelCount)));
Set<TestDegreeItem> actualDegrees = degrees(cursor);
assertEquals(expectedDegrees, actualDegrees);
}
use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.
the class GraphStoreFixture method nodeAsUpdates.
public EntityUpdates nodeAsUpdates(long nodeId) {
try (StorageReader storeReader = storageEngine.newReader();
StorageNodeCursor nodeCursor = storeReader.allocateNodeCursor(NULL);
StoragePropertyCursor propertyCursor = storeReader.allocatePropertyCursor(NULL, INSTANCE)) {
nodeCursor.single(nodeId);
long[] labels;
if (!nodeCursor.next() || !nodeCursor.hasProperties() || (labels = nodeCursor.labels()).length == 0) {
return null;
}
nodeCursor.properties(propertyCursor);
EntityUpdates.Builder update = EntityUpdates.forEntity(nodeId, true).withTokens(labels);
while (propertyCursor.next()) {
update.added(propertyCursor.propertyKey(), propertyCursor.propertyValue());
}
return update.build();
}
}
use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens.
@Test
void shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens() throws Exception {
// given
StubStorageCursors data = new StubStorageCursors();
int numNodes = 10;
MutableLongSet relevantNodeIds = LongSets.mutable.empty();
for (int i = 0; i < numNodes; i++) {
int labelId = i % 2 == 0 ? LABEL : OTHER_LABEL;
data.withNode(i).labels(labelId).properties(KEY, stringValue("name_" + i));
if (labelId == LABEL) {
relevantNodeIds.add(i);
}
}
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), false, PageCacheTracer.NULL, INSTANCE);
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
GeneratedIndexUpdates updates = sender.batches.get(0);
updates.completeBatch();
for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
}
assertThat(relevantNodeIds.isEmpty()).isTrue();
}
Aggregations