use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipScanCursorTestBase method shouldNotAccessDeletedRelationship.
@Test
void shouldNotAccessDeletedRelationship() {
// given
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// when
read.singleRelationship(none, relationships);
// then
assertFalse(relationships.next(), "should not access deleted relationship");
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction.
@Test
void shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction() throws Exception {
int label;
long n1, n2, r;
try (KernelTransaction tx = beginTransaction()) {
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
long decoyNode = tx.dataWrite().nodeCreate();
// to have >1 relationship in the db
tx.dataWrite().relationshipCreate(n2, label, decoyNode);
r = tx.dataWrite().relationshipCreate(n1, label, n2);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
assertTrue(tx.dataWrite().relationshipDelete(r), "should delete relationship");
try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
tx.dataRead().singleRelationship(r, relationship);
assertFalse(relationship.next(), "should not find relationship");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationship.
@Test
void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationship() throws Exception {
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
long relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
tx.dataRead().singleRelationship(relationship, cursor);
assertTrue(cursor.next());
assertFalse(hasProperties(cursor, tx));
tx.dataWrite().relationshipSetProperty(relationship, tx.tokenWrite().propertyKeyGetOrCreateForName("prop"), stringValue("foo"));
assertTrue(hasProperties(cursor, tx));
}
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseRelationshipScanCursor.
@Test
void shouldReuseRelationshipScanCursor() {
RelationshipScanCursor c1 = cursors.allocateRelationshipScanCursor(NULL);
read.singleRelationship(relationship, c1);
c1.close();
RelationshipScanCursor c2 = cursors.allocateRelationshipScanCursor(NULL);
assertThat(c1).isSameAs(c2);
c2.close();
}
Aggregations