use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction.
@Test
void shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction() 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().relationshipSetProperty(relationshipId, propToken, stringValue("world")), stringValue("hello"));
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 only find one property");
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 hasPropertiesShouldSeeNewlyCreatedProperties.
@Test
void hasPropertiesShouldSeeNewlyCreatedProperties() 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 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 RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction.
@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction() throws Exception {
// Given
long relationshipId;
String propKey1 = "prop1";
String propKey2 = "prop2";
int propToken1;
int propToken2;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
assertEquals(write.relationshipSetProperty(relationshipId, propToken1, stringValue("hello")), NO_VALUE);
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken2, 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);
while (property.next()) {
if (// from disk
property.propertyKey() == propToken1) {
assertEquals(property.propertyValue(), stringValue("hello"));
} else if (// from tx state
property.propertyKey() == propToken2) {
assertEquals(property.propertyValue(), stringValue("world"));
} else {
fail(property.propertyKey() + " was not the property you were looking for");
}
}
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
Relationship relationship = transaction.getRelationshipById(relationshipId);
assertThat(relationship.getProperty(propKey1)).isEqualTo("hello");
assertThat(relationship.getProperty(propKey2)).isEqualTo("world");
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNotSeeRemovedPropertyInTransaction.
@Test
void shouldNotSeeRemovedPropertyInTransaction() 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"));
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);
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()) {
assertFalse(transaction.getRelationshipById(relationshipId).hasProperty(propKey));
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsInBatches.
@Test
void shouldScanAllRelationshipsInBatches() {
// given
LongArrayList ids = new LongArrayList();
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// when
Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
while (scan.reserveBatch(relationships, 3)) {
while (relationships.next()) {
ids.add(relationships.relationshipReference());
}
}
}
// then
assertEquals(RELATIONSHIPS, ids);
}
Aggregations