use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class PropertyCursorTestBase method shouldNotAccessNonExistentNodeProperties.
@Test
void shouldNotAccessNonExistentNodeProperties() {
// given
try (NodeCursor node = cursors.allocateNodeCursor(NULL);
PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
// when
read.singleNode(bareNodeId, node);
assertTrue(node.next(), "node by reference");
assertFalse(hasProperties(node, props), "no properties");
node.properties(props);
assertFalse(props.next(), "no properties by direct method");
read.nodeProperties(node.nodeReference(), node.propertiesReference(), props);
assertFalse(props.next(), "no properties via property ref");
assertFalse(node.next(), "only one node");
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method shouldScanAllNodesFromMultipleThreads.
@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException, TransactionFailureException, InvalidTransactionTypeKernelException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
CursorFactory cursors = testSupport.kernelToTest().cursors();
int size = 128;
LongArrayList ids = new LongArrayList();
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
for (int i = 0; i < size; i++) {
ids.add(write.nodeCreate());
}
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
Scan<NodeCursor> scan = read.allNodesScan();
// when
Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
// then
LongList ids1 = future1.get();
LongList ids2 = future2.get();
LongList ids3 = future3.get();
LongList ids4 = future4.get();
TestUtils.assertDistinct(ids1, ids2, ids3, ids4);
LongList concat = TestUtils.concat(ids1, ids2, ids3, ids4);
assertEquals(ids.toSortedList(), concat.toSortedList());
tx.rollback();
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method shouldScanAllNodesFromRandomlySizedWorkers.
@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, TransactionFailureException, InvalidTransactionTypeKernelException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
int size = 128;
LongArrayList ids = new LongArrayList();
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
for (int i = 0; i < size; i++) {
ids.add(write.nodeCreate());
}
Read read = tx.dataRead();
Scan<NodeCursor> scan = read.allNodesScan();
CursorFactory cursors = testSupport.kernelToTest().cursors();
// when
List<Future<LongList>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NODE_GET)));
}
// then
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
TestUtils.assertDistinct(lists);
LongList concat = TestUtils.concat(lists);
assertEquals(ids.toSortedList(), concat.toSortedList());
tx.rollback();
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNotSeeRelationshipDeletedInTransaction.
@Test
void shouldNotSeeRelationshipDeletedInTransaction() throws Exception {
long n1, n2, r;
try (KernelTransaction tx = beginTransaction()) {
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
r = tx.dataWrite().relationshipCreate(n1, label, n2);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
tx.dataWrite().relationshipDelete(r);
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
tx.dataRead().singleNode(n1, node);
assertTrue(node.next(), "should access node");
node.relationships(relationship, ALL_RELATIONSHIPS);
assertFalse(relationship.next(), "should not find relationship");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNewRelationshipBetweenAlreadyConnectedDenseNodes.
@Test
void shouldNewRelationshipBetweenAlreadyConnectedDenseNodes() throws Exception {
long start;
long end;
long existingRelationship;
int type, bulk;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
start = write.nodeCreate();
end = write.nodeCreate();
type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
existingRelationship = write.relationshipCreate(start, type, end);
bulk = tx.tokenWrite().relationshipTypeGetOrCreateForName("BULK");
for (int i = 0; i < 100; i++) {
write.relationshipCreate(start, bulk, write.nodeCreate());
}
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
long newRelationship = write.relationshipCreate(start, type, write.nodeCreate());
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
read.singleNode(start, node);
assertTrue(node.next());
assertTrue(node.supportsFastDegreeLookup());
Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
for (int t : degrees.types()) {
if (t == type) {
assertEquals(2, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
assertRelationships(OUTGOING, node, t, traversal, existingRelationship, newRelationship);
} else if (t == bulk) {
assertEquals(bulk, t);
assertEquals(100, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
} else {
fail(t + " is not the type you're looking for ");
}
}
}
}
}
Aggregations