use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord 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());
}
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupGetterTest method group.
private RelationshipGroupRecord group(long id, int type) {
RelationshipGroupRecord group = new RelationshipGroupRecord(id, type);
group.setInUse(true);
return group;
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class ReadGroupsFromCacheStepTest method shouldProduceCompleteBatchesPerOwner.
@Test
public void shouldProduceCompleteBatchesPerOwner() throws Exception {
// GIVEN
Configuration config = Configuration.withBatchSize(DEFAULT, 10);
Iterator<RelationshipGroupRecord> groups = groups(new Group(1, 3), new Group(2, 3), // ^^^ perfect batch size
new Group(3, 4), new Group(4, 2), // ^^^ slightly bigger than batch size
new Group(5, 10), // ^^^ much bigger than batch size
new Group(6, 35), new Group(7, 2)).iterator();
final AtomicInteger processCounter = new AtomicInteger();
Stage stage = new Stage(getClass().getSimpleName(), config) {
{
add(new ReadGroupsFromCacheStep(control(), config, groups, 1));
add(new VerifierStep(control(), config, processCounter));
}
};
// WHEN processing the data
superviseDynamicExecution(stage);
// THEN
assertEquals(4, processCounter.get());
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupCacheTest method shouldPutGroupsOnlyWithinPreparedRange.
@Test
public void shouldPutGroupsOnlyWithinPreparedRange() throws Exception {
// GIVEN
int nodeCount = 1000;
RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(4), nodeCount);
int[] counts = new int[nodeCount];
for (int nodeId = 0; nodeId < counts.length; nodeId++) {
counts[nodeId] = random.nextInt(10);
setCount(cache, nodeId, counts[nodeId]);
}
long toNodeId = cache.prepare(0);
assertTrue(toNodeId < nodeCount);
// WHEN
boolean thereAreMoreGroups = true;
int cachedCount = 0;
while (thereAreMoreGroups) {
thereAreMoreGroups = false;
for (int nodeId = 0; nodeId < nodeCount; nodeId++) {
if (counts[nodeId] > 0) {
thereAreMoreGroups = true;
int typeId = counts[nodeId]--;
if (cache.put(new RelationshipGroupRecord(nodeId).initialize(true, typeId, -1, -1, -1, nodeId, -1))) {
cachedCount++;
}
}
}
}
assertTrue(cachedCount >= toNodeId);
// THEN the relationship groups we get back are only for those we prepared for
int readCount = 0;
for (RelationshipGroupRecord cachedGroup : cache) {
assertTrue(cachedGroup.getOwningNode() >= 0 && cachedGroup.getOwningNode() < toNodeId);
readCount++;
}
assertEquals(cachedCount, readCount);
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupCacheTest method shouldHandleGroupCountBeyondSignedShortRange.
@Test
public void shouldHandleGroupCountBeyondSignedShortRange() throws Exception {
// GIVEN
long nodeId = 0;
int limit = Short.MAX_VALUE + 10;
RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(100), nodeId + 1);
// WHEN first counting all groups per node
for (int type = 0; type < limit; type++) {
cache.incrementGroupCount(nodeId);
}
// and WHEN later putting group records into the cache
RelationshipGroupRecord group = new RelationshipGroupRecord(-1);
group.setOwningNode(nodeId);
for (int type = 0; type < limit; type++) {
group.setId(type);
// just some relationship
group.setFirstOut(type);
group.setType(type);
cache.put(group);
}
long prepared = cache.prepare(nodeId);
// THEN that should work, because it used to fail inside prepare, but we can also ask
// the groupCount method to be sure
assertEquals(nodeId, prepared);
assertEquals(limit, cache.groupCount(nodeId));
}
Aggregations