use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeRelationshipInTransactionBeforeCursorInitialization.
@Test
void shouldSeeRelationshipInTransactionBeforeCursorInitialization() throws Exception {
long n1, n2;
try (KernelTransaction tx = beginTransaction()) {
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
long r = tx.dataWrite().relationshipCreate(n1, label, n2);
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);
assertTrue(relationship.next(), "should find relationship");
assertEquals(r, relationship.relationshipReference());
// should not be seen
tx.dataWrite().relationshipCreate(n1, label, n2);
assertFalse(relationship.next(), "should not find relationship added after cursor init");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeNewRelationshipPropertyInTransaction.
@Test
void shouldSeeNewRelationshipPropertyInTransaction() throws Exception {
try (KernelTransaction tx = beginTransaction()) {
String propKey1 = "prop1";
String propKey2 = "prop2";
long n1 = tx.dataWrite().nodeCreate();
long n2 = tx.dataWrite().nodeCreate();
int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
long r = tx.dataWrite().relationshipCreate(n1, label, n2);
int prop1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
int prop2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
assertEquals(tx.dataWrite().relationshipSetProperty(r, prop1, stringValue("hello")), NO_VALUE);
assertEquals(tx.dataWrite().relationshipSetProperty(r, prop2, stringValue("world")), NO_VALUE);
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL);
PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
tx.dataRead().singleNode(n1, node);
assertTrue(node.next(), "should access node");
node.relationships(relationship, ALL_RELATIONSHIPS);
assertTrue(relationship.next(), "should access relationship");
relationship.properties(property);
while (property.next()) {
if (property.propertyKey() == prop1) {
assertEquals(property.propertyValue(), stringValue("hello"));
} else if (property.propertyKey() == prop2) {
assertEquals(property.propertyValue(), stringValue("world"));
} else {
fail(property.propertyKey() + " was not the property key you were looking for");
}
}
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldScanAllNodesFromRandomlySizedWorkers.
@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, ExecutionException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<NodeCursor> scan = read.allNodesScan();
CursorFactory cursors = testSupport.kernelToTest().cursors();
try {
// 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)));
}
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
// then
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
TestUtils.assertDistinct(lists);
LongList concat = TestUtils.concat(lists).toSortedList();
assertEquals(NODE_IDS, concat);
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldScanASubsetOfNodes.
@Test
void shouldScanASubsetOfNodes() {
try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
// when
Scan<NodeCursor> scan = read.allNodesScan();
assertTrue(scan.reserveBatch(nodes, 3));
assertTrue(nodes.next());
assertEquals(NODE_IDS.get(0), nodes.nodeReference());
assertTrue(nodes.next());
assertEquals(NODE_IDS.get(1), nodes.nodeReference());
assertTrue(nodes.next());
assertEquals(NODE_IDS.get(2), nodes.nodeReference());
assertFalse(nodes.next());
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldScanAllNodesInBatches.
@Test
void shouldScanAllNodesInBatches() {
// given
LongArrayList ids = new LongArrayList();
try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
// when
Scan<NodeCursor> scan = read.allNodesScan();
while (scan.reserveBatch(nodes, 3)) {
while (nodes.next()) {
ids.add(nodes.nodeReference());
}
}
}
// then
assertEquals(NODE_IDS, ids);
}
Aggregations