use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class RecordNodeCursorIT method shouldProperlyReturnHasLabel.
@RepeatedTest(10)
void shouldProperlyReturnHasLabel() {
// given/when
MutableLongSet labels = LongSets.mutable.empty();
long nodeId = createNodeWithRandomLabels(labels);
// then
try (RecordNodeCursor nodeCursor = new RecordNodeCursor(nodeStore, neoStores.getRelationshipStore(), neoStores.getRelationshipGroupStore(), null, NULL)) {
nodeCursor.single(nodeId);
assertThat(nodeCursor.next()).isTrue();
for (int labelId = 0; labelId < HIGH_LABEL_ID; labelId++) {
boolean fromCursor = nodeCursor.hasLabel(labelId);
boolean fromSet = labels.contains(labelId);
assertThat(fromCursor).as("Label " + labelId).isEqualTo(fromSet);
}
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class SchemaChecker method checkTokens.
private static <R extends TokenRecord> void checkTokens(TokenStore<R> store, Function<R, ConsistencyReport.NameConsistencyReport> report, Function<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> dynamicRecordReport, PageCacheTracer pageCacheTracer) {
DynamicStringStore nameStore = store.getNameStore();
DynamicRecord nameRecord = nameStore.newRecord();
long highId = store.getHighId();
MutableLongSet seenNameRecordIds = LongSets.mutable.empty();
int blockSize = store.getNameStore().getRecordDataSize();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(CONSISTENCY_TOKEN_CHECKER_TAG));
RecordReader<R> tokenReader = new RecordReader<>(store, true, cursorContext);
RecordReader<DynamicRecord> nameReader = new RecordReader<>(store.getNameStore(), false, cursorContext)) {
for (long id = 0; id < highId; id++) {
R record = tokenReader.read(id);
if (record.inUse() && !NULL_REFERENCE.is(record.getNameId())) {
safeLoadDynamicRecordChain(r -> {
}, nameReader, seenNameRecordIds, record.getNameId(), blockSize, (i, r) -> dynamicRecordReport.apply(nameRecord).circularReferenceNext(r), (i, r) -> report.apply(record).nameBlockNotInUse(nameRecord), (i, r) -> dynamicRecordReport.apply(nameRecord).nextNotInUse(r), (i, r) -> dynamicRecordReport.apply(r).emptyBlock(), r -> dynamicRecordReport.apply(r).recordNotFullReferencesNext(), r -> dynamicRecordReport.apply(r).invalidLength());
}
}
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class NodeRelationshipCacheTest method shouldVisitChangedNodes.
@Test
public void shouldVisitChangedNodes() {
// GIVEN
int nodes = 100;
int typeId = 10;
int chunkSize = 10;
List<Long> changedNodes = new ArrayList<>();
cache = new NodeRelationshipCache(NumberArrayFactories.HEAP, 2, chunkSize, base, INSTANCE);
cache.setNodeCount(nodes);
for (long nodeId = 0; nodeId < nodes; nodeId++) {
if (nodeId >= chunkSize && nodeId < 2 * chunkSize) {
// One chunk without any changes
continue;
}
cache.incrementCount(nodeId);
if (random.nextBoolean()) {
cache.incrementCount(nodeId);
}
changedNodes.add(nodeId);
}
MutableLongSet keySparseChanged = new LongHashSet();
MutableLongSet keyDenseChanged = new LongHashSet();
for (int i = 0; i < nodes / 2; i++) {
long nodeId = random.among(changedNodes);
cache.getAndPutRelationship(nodeId, typeId, Direction.OUTGOING, random.nextLong(1_000_000), false);
boolean dense = cache.isDense(nodeId);
(dense ? keyDenseChanged : keySparseChanged).add(nodeId);
}
{
// WHEN (sparse)
NodeRelationshipCache.NodeChangeVisitor visitor = (nodeId, array) -> {
// THEN (sparse)
assertTrue("Unexpected sparse change reported for " + nodeId, keySparseChanged.remove(nodeId));
};
cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_SPARSE);
assertTrue("There was " + keySparseChanged.size() + " expected sparse changes that weren't reported", keySparseChanged.isEmpty());
}
{
// WHEN (dense)
NodeRelationshipCache.NodeChangeVisitor visitor = (nodeId, array) -> {
// THEN (dense)
assertTrue("Unexpected dense change reported for " + nodeId, keyDenseChanged.remove(nodeId));
};
cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_DENSE);
assertTrue("There was " + keyDenseChanged.size() + " expected dense changes that weren reported", keyDenseChanged.isEmpty());
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class MutableLongDiffSetsImplTest method useCollectionsFactory.
@Test
void useCollectionsFactory() {
final MutableLongSet set1 = new LongHashSet();
final MutableLongSet set2 = new LongHashSet();
final CollectionsFactory collectionsFactory = mock(CollectionsFactory.class);
doReturn(set1, set2).when(collectionsFactory).newLongSet(EmptyMemoryTracker.INSTANCE);
final MutableLongDiffSetsImpl diffSets = new MutableLongDiffSetsImpl(collectionsFactory, EmptyMemoryTracker.INSTANCE);
diffSets.add(1L);
diffSets.remove(2L);
assertSame(set1, diffSets.getAdded());
assertSame(set2, diffSets.getRemoved());
verify(collectionsFactory, times(2)).newLongSet(EmptyMemoryTracker.INSTANCE);
verifyNoMoreInteractions(collectionsFactory);
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class RelationshipTypeIndexCursorTestBase method shouldFindRelationshipsByTypeInTx.
@ParameterizedTest
@EnumSource(value = IndexOrder.class)
void shouldFindRelationshipsByTypeInTx(IndexOrder order) throws KernelException {
long inStore;
long inStore2;
long deletedInTx;
long createdInTx;
long createdInTx2;
try (KernelTransaction tx = beginTransaction()) {
inStore = createRelationship(tx.dataWrite(), typeOne);
createRelationship(tx.dataWrite(), typeTwo);
deletedInTx = createRelationship(tx.dataWrite(), typeOne);
inStore2 = createRelationship(tx.dataWrite(), typeOne);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
tx.dataWrite().relationshipDelete(deletedInTx);
createdInTx = createRelationship(tx.dataWrite(), typeOne);
createRelationship(tx.dataWrite(), typeTwo);
createdInTx2 = createRelationship(tx.dataWrite(), typeOne);
try (RelationshipTypeIndexCursor cursor = tx.cursors().allocateRelationshipTypeIndexCursor(NULL)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
relationshipTypeScan(tx, typeOne, cursor, order);
// then
assertRelationships(cursor, uniqueIds, order, inStore, inStore2, createdInTx, createdInTx2);
}
}
}
Aggregations