use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method hasPropertiesShouldSeeNewlyRemovedProperties.
@Test
void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception {
// Given
long relationship;
int prop1, prop2, prop3;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop1");
prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop2");
prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop3");
tx.dataWrite().relationshipSetProperty(relationship, prop1, longValue(1));
tx.dataWrite().relationshipSetProperty(relationship, prop2, longValue(2));
tx.dataWrite().relationshipSetProperty(relationship, prop3, longValue(3));
tx.commit();
}
// Then
try (KernelTransaction tx = beginTransaction()) {
try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
tx.dataRead().singleRelationship(relationship, cursor);
assertTrue(cursor.next());
assertTrue(hasProperties(cursor, tx));
tx.dataWrite().relationshipRemoveProperty(relationship, prop1);
assertTrue(hasProperties(cursor, tx));
tx.dataWrite().relationshipRemoveProperty(relationship, prop2);
assertTrue(hasProperties(cursor, tx));
tx.dataWrite().relationshipRemoveProperty(relationship, prop3);
assertFalse(hasProperties(cursor, tx));
}
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeSingleRelationshipInTransaction.
@Test
void shouldSeeSingleRelationshipInTransaction() throws Exception {
int label;
long n1, n2;
try (KernelTransaction tx = beginTransaction()) {
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
// setup extra relationship to challenge the implementation
long decoyNode = tx.dataWrite().nodeCreate();
label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
tx.dataWrite().relationshipCreate(n2, label, decoyNode);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
long r = tx.dataWrite().relationshipCreate(n1, label, n2);
try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
tx.dataRead().singleRelationship(r, relationship);
assertTrue(relationship.next(), "should find relationship");
assertEquals(label, relationship.type());
assertEquals(n1, relationship.sourceNodeReference());
assertEquals(n2, relationship.targetNodeReference());
assertEquals(r, relationship.relationshipReference());
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipScanCursorTestBase method shouldAccessRelationshipLabels.
@Test
void shouldAccessRelationshipLabels() {
// given
Map<Integer, Integer> counts = new HashMap<>();
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// when
read.allRelationshipsScan(relationships);
while (relationships.next()) {
counts.compute(relationships.type(), (k, v) -> v == null ? 1 : v + 1);
}
}
// then
assertEquals(3, counts.size());
int[] values = new int[3];
int i = 0;
for (int value : counts.values()) {
values[i++] = value;
}
Arrays.sort(values);
assertArrayEquals(new int[] { 1, 6, 6 }, values);
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipScanCursorTestBase method shouldAccessRelationshipByReference.
@Test
void shouldAccessRelationshipByReference() {
// given
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
for (long id : RELATIONSHIP_IDS) {
// when
read.singleRelationship(id, relationships);
// then
assertTrue(relationships.next(), "should access defined relationship");
assertEquals(id, relationships.relationshipReference(), "should access the correct relationship");
assertFalse(relationships.next(), "should only access a single relationship");
}
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipScanCursorTestBase method shouldScanRelationships.
@Test
void shouldScanRelationships() {
// given
List<Long> ids = new ArrayList<>();
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// when
read.allRelationshipsScan(relationships);
while (relationships.next()) {
ids.add(relationships.relationshipReference());
}
}
assertEquals(RELATIONSHIP_IDS, ids);
}
Aggregations