use of org.neo4j.internal.counts.RelationshipGroupDegreesStore in project neo4j by neo4j.
the class RecordNodeCursorTest method shouldChooseFastTotalDegreeLookupWhenPossible.
@Test
void shouldChooseFastTotalDegreeLookupWhenPossible() {
// given
NodeStore nodeStore = mock(NodeStore.class);
long relationshipId = 99;
long nextRelationshipId = relationshipId + 1;
long nodeId = 5;
int degree = 123;
when(nodeStore.getHighestPossibleIdInUse(NULL)).thenReturn(nodeId + 1);
doAnswer(invocationOnMock -> {
long id = invocationOnMock.getArgument(0);
NodeRecord record = invocationOnMock.getArgument(1);
record.setId(id);
record.initialize(true, NULL_REFERENCE.longValue(), false, relationshipId, NO_LABELS_FIELD.longValue());
return null;
}).when(nodeStore).getRecordByCursor(eq(nodeId), any(), any(), any());
RelationshipStore relationshipStore = mock(RelationshipStore.class);
doAnswer(invocationOnMock -> {
long id = invocationOnMock.getArgument(0);
RelationshipRecord record = invocationOnMock.getArgument(1);
record.setId(id);
record.initialize(true, NULL_REFERENCE.longValue(), nodeId, nodeId + 10, 1, degree, nextRelationshipId, 33, 44, true, false);
return null;
}).when(relationshipStore).getRecordByCursor(eq(relationshipId), any(), any(), any());
RelationshipGroupStore groupStore = mock(RelationshipGroupStore.class);
RelationshipGroupDegreesStore groupDegreesStore = mock(RelationshipGroupDegreesStore.class);
RecordNodeCursor nodeCursor = new RecordNodeCursor(nodeStore, relationshipStore, groupStore, groupDegreesStore, NULL);
// when
nodeCursor.single(nodeId);
assertThat(nodeCursor.next()).isTrue();
SingleDegree mutator = new SingleDegree();
nodeCursor.degrees(RelationshipSelection.ALL_RELATIONSHIPS, mutator, true);
// then
assertThat(mutator.getTotal()).isEqualTo(degree);
verifyNoInteractions(groupStore);
verify(relationshipStore).getRecordByCursor(eq(relationshipId), any(), any(), any());
verify(relationshipStore, never()).getRecordByCursor(eq(nextRelationshipId), any(), any(), any());
}
Aggregations