use of org.neo4j.internal.kernel.api.PropertyCursor 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.PropertyCursor in project neo4j by neo4j.
the class PropertyCursorTestBase method shouldAccessAllRelationshipProperties.
@Test
void shouldAccessAllRelationshipProperties() {
// given
try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
// when
read.singleRelationship(allPropsRelId, relationship);
assertTrue(relationship.next(), "relationship by reference");
assertTrue(hasProperties(relationship, props), "has properties");
relationship.properties(props);
Set<Object> values = new HashSet<>();
while (props.next()) {
values.add(props.propertyValue().asObject());
}
assertTrue(values.contains((byte) 13), BYTE_PROP);
assertTrue(values.contains((short) 13), SHORT_PROP);
assertTrue(values.contains(13), INT_PROP);
assertTrue(values.contains(13L), INLINE_LONG_PROP);
assertTrue(values.contains(Long.MAX_VALUE), LONG_PROP);
assertTrue(values.contains(13.0f), FLOAT_PROP);
assertTrue(values.contains(13.0), DOUBLE_PROP);
assertTrue(values.contains(true), TRUE_PROP);
assertTrue(values.contains(false), FALSE_PROP);
assertTrue(values.contains('x'), CHAR_PROP);
assertTrue(values.contains(""), EMPTY_STRING_PROP);
assertTrue(values.contains("hello"), SHORT_STRING_PROP);
assertTrue(values.contains(chinese), UTF_8_PROP);
if (supportsBigProperties()) {
assertTrue(values.contains(LONG_STRING), LONG_STRING_PROP);
assertThat(values).as(SMALL_ARRAY_PROP).contains(new int[] { 1, 2, 3, 4 });
assertThat(values).as(BIG_ARRAY_PROP).contains(LONG_STRING);
}
assertTrue(values.contains(pointValue), POINT_PROP);
assertTrue(values.contains(dateValue.asObject()), DATE_PROP);
int expected = supportsBigProperties() ? 18 : 15;
assertEquals(expected, values.size(), "number of values");
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class PropertyCursorTestBase method shouldNotAccessNonExistentRelationshipProperties.
@Test
void shouldNotAccessNonExistentRelationshipProperties() {
try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
// when
read.singleRelationship(bareRelId, relationship);
assertTrue(relationship.next(), "relationship by reference");
assertFalse(hasProperties(relationship, props), "no properties");
relationship.properties(props);
assertFalse(props.next(), "no properties by direct method");
read.relationshipProperties(relationship.relationshipReference(), relationship.propertiesReference(), props);
assertFalse(props.next(), "no properties via property ref");
assertFalse(relationship.next(), "only one node");
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeRemovedThenAddedPropertyInTransaction.
@Test
void shouldSeeRemovedThenAddedPropertyInTransaction() throws Exception {
// Given
long relationshipId;
String propKey = "prop1";
int propToken;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
assertEquals(write.relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
assertEquals(tx.dataWrite().relationshipRemoveProperty(relationshipId, propToken), stringValue("hello"));
assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("world")), NO_VALUE);
try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL);
PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
tx.dataRead().singleRelationship(relationshipId, relationship);
assertTrue(relationship.next(), "should access relationship");
relationship.properties(property);
assertTrue(property.next());
assertEquals(propToken, property.propertyKey());
assertEquals(property.propertyValue(), stringValue("world"));
assertFalse(property.next(), "should not find any properties");
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
assertThat(transaction.getRelationshipById(relationshipId).getProperty(propKey)).isEqualTo("world");
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.
@Test
void shouldAllowManyLabelsAndPropertyCursor() {
int propertyCount = 10;
int labelCount = 15;
Node node;
try (Transaction tx = db.beginTx()) {
node = tx.createNode();
for (int i = 0; i < propertyCount; i++) {
node.setProperty("foo" + i, "bar");
}
for (int i = 0; i < labelCount; i++) {
node.addLabel(label("label" + i));
}
tx.commit();
}
Set<Integer> seenProperties = new HashSet<>();
Set<Integer> seenLabels = new HashSet<>();
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeCursor nodes = ktx.cursors().allocateNodeCursor(CursorContext.NULL);
PropertyCursor propertyCursor = ktx.cursors().allocatePropertyCursor(CursorContext.NULL, INSTANCE)) {
ktx.dataRead().singleNode(node.getId(), nodes);
while (nodes.next()) {
nodes.properties(propertyCursor);
while (propertyCursor.next()) {
seenProperties.add(propertyCursor.propertyKey());
}
TokenSet labels = nodes.labels();
for (int i = 0; i < labels.numberOfTokens(); i++) {
seenLabels.add(labels.token(i));
}
}
}
tx.commit();
}
assertEquals(propertyCount, seenProperties.size());
assertEquals(labelCount, seenLabels.size());
}
Aggregations