use of org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter.RelationshipGroupPosition in project neo4j by neo4j.
the class RelationshipGroupGetterTest method shouldAbortLoadingGroupChainIfComeTooFar.
@Test
public void shouldAbortLoadingGroupChainIfComeTooFar() throws Exception {
// GIVEN a node with relationship group chain 2-->4-->10-->23
File dir = new File("dir");
fs.get().mkdirs(dir);
LogProvider logProvider = NullLogProvider.getInstance();
StoreFactory storeFactory = new StoreFactory(dir, pageCache.getPageCache(fs.get()), fs.get(), logProvider);
try (NeoStores stores = storeFactory.openNeoStores(true, StoreType.RELATIONSHIP_GROUP)) {
RecordStore<RelationshipGroupRecord> store = spy(stores.getRelationshipGroupStore());
RelationshipGroupRecord group_2 = group(0, 2);
RelationshipGroupRecord group_4 = group(1, 4);
RelationshipGroupRecord group_10 = group(2, 10);
RelationshipGroupRecord group_23 = group(3, 23);
link(group_2, group_4, group_10, group_23);
store.updateRecord(group_2);
store.updateRecord(group_4);
store.updateRecord(group_10);
store.updateRecord(group_23);
RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(store);
NodeRecord node = new NodeRecord(0, true, group_2.getId(), -1);
// WHEN trying to find relationship group 7
RecordAccess<Long, RelationshipGroupRecord, Integer> access = new DirectRecordAccess<>(store, Loaders.relationshipGroupLoader(store));
RelationshipGroupPosition result = groupGetter.getRelationshipGroup(node, 7, access);
// THEN only groups 2, 4 and 10 should have been loaded
InOrder verification = inOrder(store);
verification.verify(store).getRecord(eq(group_2.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
verification.verify(store).getRecord(eq(group_4.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
verification.verify(store).getRecord(eq(group_10.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
verification.verify(store, times(0)).getRecord(eq(group_23.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
// it should also be reported as not found
assertNull(result.group());
// with group 4 as closes previous one
assertEquals(group_4, result.closestPrevious().forReadingData());
}
}
Aggregations