use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeNodeInTransaction.
@Test
void shouldSeeNodeInTransaction() throws Exception {
long nodeId;
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
tx.dataRead().singleNode(nodeId, node);
assertTrue(node.next(), "should access node");
assertEquals(nodeId, node.nodeReference());
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertEquals(nodeId, tx.getNodeById(nodeId).getId());
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeNewLabeledNodeInTransaction.
@Test
void shouldSeeNewLabeledNodeInTransaction() throws Exception {
long nodeId;
int labelId;
final String labelName = "Town";
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
labelId = tx.token().labelGetOrCreateForName(labelName);
tx.dataWrite().nodeAddLabel(nodeId, labelId);
try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
tx.dataRead().singleNode(nodeId, node);
assertTrue(node.next(), "should access node");
TokenSet labels = node.labels();
assertEquals(1, labels.numberOfTokens());
assertEquals(labelId, labels.token(0));
assertTrue(node.hasLabel(labelId));
assertFalse(node.hasLabel(labelId + 1));
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertThat(tx.getNodeById(nodeId).getLabels()).isEqualTo(Iterables.iterable(label(labelName)));
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method hasPropertiesShouldSeeNewlyRemovedProperties.
@Test
void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception {
// Given
long node;
int prop1, prop2, prop3;
try (KernelTransaction tx = beginTransaction()) {
node = tx.dataWrite().nodeCreate();
prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop1");
prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop2");
prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop3");
tx.dataWrite().nodeSetProperty(node, prop1, longValue(1));
tx.dataWrite().nodeSetProperty(node, prop2, longValue(2));
tx.dataWrite().nodeSetProperty(node, prop3, longValue(3));
tx.commit();
}
// Then
try (KernelTransaction tx = beginTransaction()) {
try (NodeCursor cursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
PropertyCursor props = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().singleNode(node, cursor);
assertTrue(cursor.next());
assertTrue(hasProperties(cursor, props));
tx.dataWrite().nodeRemoveProperty(node, prop1);
assertTrue(hasProperties(cursor, props));
tx.dataWrite().nodeRemoveProperty(node, prop2);
assertTrue(hasProperties(cursor, props));
tx.dataWrite().nodeRemoveProperty(node, prop3);
assertFalse(hasProperties(cursor, props));
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldDiscoverDeletedNodeInTransaction.
@Test
void shouldDiscoverDeletedNodeInTransaction() throws Exception {
long nodeId;
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
assertTrue(tx.dataWrite().nodeDelete(nodeId));
try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
tx.dataRead().singleNode(nodeId, node);
assertFalse(node.next());
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class KernelReadTracerTest method shouldTraceLazySelectionRelationshipTraversal.
@Test
void shouldTraceLazySelectionRelationshipTraversal() {
// given
TestKernelReadTracer tracer = new TestKernelReadTracer();
try (NodeCursor nodeCursor = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor cursor = cursors.allocateRelationshipTraversalCursor(NULL)) {
// when
cursor.setTracer(tracer);
read.singleNode(foo, nodeCursor);
assertTrue(nodeCursor.next());
int type = token.relationshipType("HAS");
nodeCursor.relationships(cursor, selection(type, Direction.OUTGOING));
assertTrue(cursor.next());
tracer.assertEvents(OnRelationship(cursor.relationshipReference()));
cursor.removeTracer();
assertTrue(cursor.next());
tracer.assertEvents();
cursor.setTracer(tracer);
assertTrue(cursor.next());
tracer.assertEvents(OnRelationship(cursor.relationshipReference()));
// skip last one
assertTrue(cursor.next());
tracer.clear();
assertFalse(cursor.next());
tracer.assertEvents();
}
}
Aggregations