use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction.
@Test
void shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception {
// Given
long nodeId;
String propKey1 = "prop1";
String propKey2 = "prop2";
int propToken1;
int propToken2;
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken1, stringValue("hello")));
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken2, stringValue("world")));
try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext());
PropertyCursor property = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().singleNode(nodeId, node);
assertTrue(node.next(), "should access node");
node.properties(property);
// property 2, start with tx state
assertTrue(property.next());
assertEquals(propToken2, property.propertyKey());
assertEquals(property.propertyValue(), stringValue("world"));
// property 1, from disk
assertTrue(property.next());
assertEquals(propToken1, property.propertyKey());
assertEquals(property.propertyValue(), stringValue("hello"));
assertFalse(property.next(), "should only find two properties");
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertThat(tx.getNodeById(nodeId).getProperty(propKey1)).isEqualTo("hello");
assertThat(tx.getNodeById(nodeId).getProperty(propKey2)).isEqualTo("world");
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method propertyTypeShouldBeTxStateAware.
@Test
void propertyTypeShouldBeTxStateAware() throws Exception {
// Given
long node;
try (KernelTransaction tx = beginTransaction()) {
node = tx.dataWrite().nodeCreate();
tx.commit();
}
// Then
try (KernelTransaction tx = beginTransaction()) {
try (NodeCursor nodes = tx.cursors().allocateNodeCursor(tx.cursorContext());
PropertyCursor properties = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().singleNode(node, nodes);
assertTrue(nodes.next());
assertFalse(hasProperties(nodes, properties));
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
tx.dataWrite().nodeSetProperty(node, prop, stringValue("foo"));
nodes.properties(properties);
assertTrue(properties.next());
assertThat(properties.propertyType()).isEqualTo(ValueGroup.TEXT);
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeLabelChangesInTransaction.
@Test
void shouldSeeLabelChangesInTransaction() throws Exception {
long nodeId;
int toRetain, toDelete, toAdd, toRegret;
final String toRetainName = "ToRetain";
final String toDeleteName = "ToDelete";
final String toAddName = "ToAdd";
final String toRegretName = "ToRegret";
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
toRetain = tx.token().labelGetOrCreateForName(toRetainName);
toDelete = tx.token().labelGetOrCreateForName(toDeleteName);
tx.dataWrite().nodeAddLabel(nodeId, toRetain);
tx.dataWrite().nodeAddLabel(nodeId, toDelete);
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertThat(tx.getNodeById(nodeId).getLabels()).contains(label(toRetainName), label(toDeleteName));
}
try (KernelTransaction tx = beginTransaction()) {
toAdd = tx.token().labelGetOrCreateForName(toAddName);
tx.dataWrite().nodeAddLabel(nodeId, toAdd);
tx.dataWrite().nodeRemoveLabel(nodeId, toDelete);
toRegret = tx.token().labelGetOrCreateForName(toRegretName);
tx.dataWrite().nodeAddLabel(nodeId, toRegret);
tx.dataWrite().nodeRemoveLabel(nodeId, toRegret);
try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
tx.dataRead().singleNode(nodeId, node);
assertTrue(node.next(), "should access node");
assertLabels(node.labels(), toRetain, toAdd);
assertTrue(node.hasLabel(toAdd));
assertTrue(node.hasLabel(toRetain));
assertFalse(node.hasLabel(toDelete));
assertFalse(node.hasLabel(toRegret));
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertThat(tx.getNodeById(nodeId).getLabels()).contains(label(toRetainName), label(toAddName));
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldFailForSizeHintZero.
@Test
void shouldFailForSizeHintZero() {
try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
// given
Scan<NodeCursor> scan = read.allNodesScan();
// when
assertThrows(IllegalArgumentException.class, () -> scan.reserveBatch(nodes, 0));
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldHandleSizeHintOverflow.
@Test
void shouldHandleSizeHintOverflow() {
try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
// when
Scan<NodeCursor> scan = read.allNodesScan();
assertTrue(scan.reserveBatch(nodes, NUMBER_OF_NODES * 2));
LongArrayList ids = new LongArrayList();
while (nodes.next()) {
ids.add(nodes.nodeReference());
}
assertEquals(NODE_IDS, ids);
}
}
Aggregations