use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipScanCursorTestBase method shouldNotAccessNegativeReferences.
// This is functionality which is only required for the hacky db.schema not to leak real data
@Test
void shouldNotAccessNegativeReferences() {
// given
try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL)) {
// when
read.singleRelationship(-2L, relationship);
// then
assertFalse(relationship.next(), "should not access negative reference relationship");
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipScanCursorTestBase method shouldAccessNodes.
@Test
void shouldAccessNodes() {
// given
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// when
read.singleRelationship(one, relationships);
// then
assertTrue(relationships.next());
assertEquals(c, relationships.sourceNodeReference());
assertEquals(d, relationships.targetNodeReference());
assertFalse(relationships.next());
// when
read.singleRelationship(loop, relationships);
// then
assertTrue(relationships.next());
assertEquals(relationships.sourceNodeReference(), relationships.targetNodeReference());
assertFalse(relationships.next());
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction.
@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction() throws Exception {
// Given
long relationshipId;
String propKey = "prop1";
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
int propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("hello")), 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("hello"));
assertFalse(property.next(), "should only find one 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("hello");
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method propertyTypeShouldBeTxStateAware.
@Test
void propertyTypeShouldBeTxStateAware() throws Exception {
// Given
long relationship;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
tx.commit();
}
// Then
try (KernelTransaction tx = beginTransaction()) {
try (RelationshipScanCursor relationships = tx.cursors().allocateRelationshipScanCursor(NULL);
PropertyCursor properties = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
tx.dataRead().singleRelationship(relationship, relationships);
assertTrue(relationships.next());
assertFalse(hasProperties(relationships, tx));
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
tx.dataWrite().relationshipSetProperty(relationship, prop, stringValue("foo"));
relationships.properties(properties);
assertTrue(properties.next());
assertThat(properties.propertyType()).isEqualTo(ValueGroup.TEXT);
}
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNotScanRelationshipWhichWasDeletedInTransaction.
@Test
void shouldNotScanRelationshipWhichWasDeletedInTransaction() throws Exception {
final int nRelationshipsInStore = 5 + 1 + 5;
int type;
long n1, n2, r;
try (KernelTransaction tx = beginTransaction()) {
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
relateNTimes(5, type, n1, n2, tx);
r = tx.dataWrite().relationshipCreate(n1, type, n2);
relateNTimes(5, type, n1, n2, tx);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
assertTrue(tx.dataWrite().relationshipDelete(r), "should delete relationship");
try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
tx.dataRead().allRelationshipsScan(relationship);
assertCountRelationships(relationship, nRelationshipsInStore - 1, n1, type, n2);
}
tx.commit();
}
}
Aggregations