use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.
the class MockedNeoStores method basicMockedNeoStores.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static NeoStores basicMockedNeoStores() {
NeoStores neoStores = mock(NeoStores.class);
// Cursor, absolutely mocked and cannot be used at all as it is
RecordCursor cursor = mockedRecordCursor();
// NodeStore - DynamicLabelStore
NodeStore nodeStore = mock(NodeStore.class);
when(nodeStore.newRecordCursor(any())).thenReturn(cursor);
when(neoStores.getNodeStore()).thenReturn(nodeStore);
// NodeStore - DynamicLabelStore
DynamicArrayStore dynamicLabelStore = mock(DynamicArrayStore.class);
when(dynamicLabelStore.newRecordCursor(any())).thenReturn(cursor);
when(nodeStore.getDynamicLabelStore()).thenReturn(dynamicLabelStore);
// RelationshipStore
RelationshipStore relationshipStore = mock(RelationshipStore.class);
when(relationshipStore.newRecordCursor(any())).thenReturn(cursor);
when(neoStores.getRelationshipStore()).thenReturn(relationshipStore);
// RelationshipGroupStore
RelationshipGroupStore relationshipGroupStore = mock(RelationshipGroupStore.class);
when(relationshipGroupStore.newRecordCursor(any())).thenReturn(cursor);
when(neoStores.getRelationshipGroupStore()).thenReturn(relationshipGroupStore);
// PropertyStore
PropertyStore propertyStore = mock(PropertyStore.class);
when(propertyStore.newRecordCursor(any())).thenReturn(cursor);
when(neoStores.getPropertyStore()).thenReturn(propertyStore);
// PropertyStore -- DynamicStringStore
DynamicStringStore propertyStringStore = mock(DynamicStringStore.class);
when(propertyStringStore.newRecordCursor(any())).thenReturn(cursor);
when(propertyStore.getStringStore()).thenReturn(propertyStringStore);
// PropertyStore -- DynamicArrayStore
DynamicArrayStore propertyArrayStore = mock(DynamicArrayStore.class);
when(propertyArrayStore.newRecordCursor(any())).thenReturn(cursor);
when(propertyStore.getArrayStore()).thenReturn(propertyArrayStore);
return neoStores;
}
use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.
the class StoreIteratorRelationshipCursorTest method newRecordCursorsWithMockedNeoStores.
private static RecordCursors newRecordCursorsWithMockedNeoStores(RelationshipStore relationshipStore) {
NeoStores neoStores = mock(NeoStores.class);
NodeStore nodeStore = newStoreMockWithRecordCursor(NodeStore.class);
RelationshipGroupStore relGroupStore = newStoreMockWithRecordCursor(RelationshipGroupStore.class);
PropertyStore propertyStore = newStoreMockWithRecordCursor(PropertyStore.class);
DynamicStringStore dynamicStringStore = newStoreMockWithRecordCursor(DynamicStringStore.class);
DynamicArrayStore dynamicArrayStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
DynamicArrayStore dynamicLabelStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
when(neoStores.getNodeStore()).thenReturn(nodeStore);
when(neoStores.getRelationshipStore()).thenReturn(relationshipStore);
when(neoStores.getRelationshipGroupStore()).thenReturn(relGroupStore);
when(neoStores.getPropertyStore()).thenReturn(propertyStore);
when(propertyStore.getStringStore()).thenReturn(dynamicStringStore);
when(propertyStore.getArrayStore()).thenReturn(dynamicArrayStore);
when(nodeStore.getDynamicLabelStore()).thenReturn(dynamicLabelStore);
return new RecordCursors(neoStores);
}
use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.
the class RelationshipGroupDefragmenterTest method verifyGroupsAreSequentiallyOrderedByNode.
private void verifyGroupsAreSequentiallyOrderedByNode() {
RelationshipGroupStore store = stores.getRelationshipGroupStore();
long firstId = store.getNumberOfReservedLowIds();
long groupCount = store.getHighId() - firstId;
RelationshipGroupRecord groupRecord = store.newRecord();
PageCursor groupCursor = store.openPageCursorForReading(firstId, NULL);
long highGroupId = store.getHighId();
long currentNodeId = -1;
int currentTypeId = -1;
int newGroupCount = 0;
int currentGroupLength = 0;
for (long id = firstId; id < highGroupId; id++, newGroupCount++) {
store.getRecordByCursor(id, groupRecord, CHECK, groupCursor);
if (!groupRecord.inUse()) {
// This will be the case if we have double record units, just assert that fact
assertTrue(units > 1);
assertTrue(currentGroupLength > 0);
currentGroupLength--;
continue;
}
long nodeId = groupRecord.getOwningNode();
assertTrue(nodeId >= currentNodeId, "Expected a group for node >= " + currentNodeId + ", but was " + nodeId + " in " + groupRecord);
if (nodeId != currentNodeId) {
currentNodeId = nodeId;
currentTypeId = -1;
if (units > 1) {
assertEquals(0, currentGroupLength);
}
currentGroupLength = 0;
}
currentGroupLength++;
assertTrue(groupRecord.getNext() == groupRecord.getId() + 1 || groupRecord.getNext() == Record.NO_NEXT_RELATIONSHIP.intValue(), "Expected this group to have a next of current + " + units + " OR NULL, " + "but was " + groupRecord);
assertTrue(groupRecord.getType() > currentTypeId, "Expected " + groupRecord + " to have type > " + currentTypeId);
currentTypeId = groupRecord.getType();
}
assertEquals(groupCount, newGroupCount);
}
use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldDeleteEmptyGroupsWhenDeletingNode.
@Test
void shouldDeleteEmptyGroupsWhenDeletingNode() throws Exception {
// given
// node --> group A (empty) --> group B (empty) --> group C (empty)
neoStores = createStores();
NodeStore nodeStore = neoStores.getNodeStore();
RelationshipGroupStore groupStore = neoStores.getRelationshipGroupStore();
long nodeId = nodeStore.nextId(NULL);
long groupA = groupStore.nextId(NULL);
long groupB = groupStore.nextId(NULL);
long groupC = groupStore.nextId(NULL);
groupStore.updateRecord(new RelationshipGroupRecord(groupA).initialize(true, 0, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, groupB), NULL);
groupStore.updateRecord(new RelationshipGroupRecord(groupB).initialize(true, 1, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, groupC), NULL);
groupStore.updateRecord(new RelationshipGroupRecord(groupC).initialize(true, 2, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, NULL_REFERENCE.longValue()), NULL);
nodeStore.updateRecord(new NodeRecord(nodeId).initialize(true, NO_NEXT_PROPERTY.longValue(), true, groupA, Record.NO_LABELS_FIELD.longValue()), NULL);
// when
TransactionRecordState state = newTransactionRecordState();
state.nodeDelete(nodeId);
apply(state);
// then
assertThat(nodeStore.isInUse(nodeId, NULL)).isFalse();
assertThat(groupStore.isInUse(groupA, NULL)).isFalse();
assertThat(groupStore.isInUse(groupB, NULL)).isFalse();
assertThat(groupStore.isInUse(groupC, NULL)).isFalse();
}
use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.
the class RecordRelationshipTraversalCursorTest method createRelationshipStructure.
protected long createRelationshipStructure(boolean dense, RelationshipSpec... relationshipSpecs) {
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
if (!dense) {
// a single chain
for (int i = 0; i < relationshipSpecs.length; i++) {
long nextRelationshipId = i == relationshipSpecs.length - 1 ? NULL : i + 1;
relationshipStore.updateRecord(createRelationship(i, nextRelationshipId, relationshipSpecs[i]), CursorContext.NULL);
}
return 0;
} else {
// split chains on type/direction
Arrays.sort(relationshipSpecs);
RelationshipGroupStore relationshipGroupStore = neoStores.getRelationshipGroupStore();
int currentType = -1;
long[] currentGroup = null;
long nextGroupId = relationshipGroupStore.getNumberOfReservedLowIds();
for (int i = 0; i < relationshipSpecs.length; i++) {
RelationshipSpec spec = relationshipSpecs[i];
if (spec.type != currentType || currentGroup == null) {
if (currentGroup != null) {
relationshipGroupStore.updateRecord(createRelationshipGroup(nextGroupId++, currentType, currentGroup, nextGroupId), CursorContext.NULL);
}
currentType = spec.type;
currentGroup = new long[] { NULL, NULL, NULL };
}
int relationshipOrdinal = relationshipSpecs[i].direction.ordinal();
long relationshipId = i;
long nextRelationshipId = i < relationshipSpecs.length - 1 && relationshipSpecs[i + 1].equals(spec) ? i + 1 : NULL;
relationshipStore.updateRecord(createRelationship(relationshipId, nextRelationshipId, relationshipSpecs[i]), CursorContext.NULL);
if (currentGroup[relationshipOrdinal] == NULL) {
currentGroup[relationshipOrdinal] = relationshipId;
}
}
relationshipGroupStore.updateRecord(createRelationshipGroup(nextGroupId, currentType, currentGroup, NULL), CursorContext.NULL);
return relationshipsReferenceWithDenseMarker(relationshipGroupStore.getNumberOfReservedLowIds(), true);
}
}
Aggregations