use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsFromMultipleThreads.
@Test
void shouldScanAllRelationshipsFromMultipleThreads() throws InterruptedException, ExecutionException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
CursorFactory cursors = testSupport.kernelToTest().cursors();
try {
// when
Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
// then
LongList ids1 = future1.get();
LongList ids2 = future2.get();
LongList ids3 = future3.get();
LongList ids4 = future4.get();
assertDistinct(ids1, ids2, ids3, ids4);
LongList concat = concat(ids1, ids2, ids3, ids4).toSortedList();
assertEquals(RELATIONSHIPS, concat);
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class ParallelRelationshipCursorTransactionStateTestBase method scanShouldSeeAddedRelationships.
@Test
void scanShouldSeeAddedRelationships() throws Exception {
int size = 100;
MutableLongSet existing = createRelationships(size);
MutableLongSet added = LongSets.mutable.empty();
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
for (int i = 0; i < size; i++) {
added.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
}
try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
Scan<RelationshipScanCursor> scan = tx.dataRead().allRelationshipsScan();
MutableLongSet seen = LongSets.mutable.empty();
while (scan.reserveBatch(cursor, 17)) {
while (cursor.next()) {
long relationshipId = cursor.relationshipReference();
assertTrue(seen.add(relationshipId));
assertTrue(existing.remove(relationshipId) || added.remove(relationshipId));
}
}
// make sure we have seen all relationships
assertTrue(existing.isEmpty());
assertTrue(added.isEmpty());
}
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class PropertyCursorTestBase method assertAccessSingleRelationshipProperty.
private void assertAccessSingleRelationshipProperty(long relationshipId, Object expectedValue, ValueGroup expectedValueType) {
// given
try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
// when
read.singleRelationship(relationshipId, relationship);
assertTrue(relationship.next(), "relationship by reference");
assertTrue(hasProperties(relationship, props), "has properties");
relationship.properties(props);
assertTrue(props.next(), "has properties by direct method");
assertEquals(expectedValue, props.propertyValue(), "correct value");
assertEquals(expectedValueType, props.propertyType(), "correct value type ");
assertFalse(props.next(), "single property");
read.relationshipProperties(relationship.relationshipReference(), relationship.propertiesReference(), props);
assertTrue(props.next(), "has properties via property ref");
assertEquals(expectedValue, props.propertyValue(), "correct value");
assertFalse(props.next(), "single property");
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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.RelationshipScanCursor 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");
}
}
Aggregations