use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldPerformStringContainmentSearch.
@Test
void shouldPerformStringContainmentSearch() throws Exception {
// given
boolean needsValues = indexParams.indexProvidesStringValues();
int prop = token.propertyKey(PROP_NAME);
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
IndexValueCapability stringCapability = index.reference().getCapability().valueCapability(ValueCategory.TEXT);
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
entityParams.entityIndexSeek(tx, index, cursor, unordered(needsValues), PropertyIndexQuery.stringContains(prop, stringValue("o")));
// then
assertThat(cursor.numberOfProperties()).isEqualTo(1);
assertFoundEntitiesAndValue(cursor, uniqueIds, stringCapability, needsValues, strOne, strTwo1, strTwo2);
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldNotFindDeletedEntityInIndexScan.
@Test
void shouldNotFindDeletedEntityInIndexScan() throws Exception {
// Given
boolean needsValues = indexParams.indexProvidesAllValues();
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
IndexValueCapability wildcardCapability = index.reference().getCapability().valueCapability(ValueCategory.UNKNOWN);
try (KernelTransaction tx = beginTransaction();
var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
entityParams.entityIndexScan(tx, index, cursor, unordered(needsValues));
assertThat(cursor.numberOfProperties()).isEqualTo(1);
assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT, uniqueIds, wildcardCapability, needsValues);
// then
entityParams.entityDelete(tx, strOne);
entityParams.entityIndexScan(tx, index, cursor, unordered(needsValues));
assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT - 1, uniqueIds, wildcardCapability, needsValues);
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldPerformIndexScan.
@Test
void shouldPerformIndexScan() throws Exception {
// given
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
IndexValueCapability wildcardCapability = index.reference().getCapability().valueCapability(ValueCategory.UNKNOWN);
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
entityParams.entityIndexScan(tx, index, cursor, unordered(indexParams.indexProvidesAllValues()));
// then
assertThat(cursor.numberOfProperties()).isEqualTo(1);
assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT, uniqueIds, wildcardCapability, indexParams.indexProvidesAllValues());
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class ConstraintIndexConcurrencyTest method shouldNotAllowConcurrentViolationOfConstraint.
@Test
void shouldNotAllowConcurrentViolationOfConstraint() throws Exception {
// Given
Label label = label("Foo");
String propertyKey = "bar";
String conflictingValue = "baz";
String constraintName = "MyConstraint";
// a constraint
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(constraintName).create();
tx.commit();
}
// When
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
int labelId = ktx.tokenRead().nodeLabel(label.name());
int propertyKeyId = ktx.tokenRead().propertyKey(propertyKey);
Read read = ktx.dataRead();
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
IndexDescriptor index = ktx.schemaRead().indexGetForName(constraintName);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
read.nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, "The value is irrelevant, we just want to perform some sort of lookup against this " + "index"));
}
// then let another thread come in and create a node
threads.execute(db -> {
try (Transaction transaction = db.beginTx()) {
transaction.createNode(label).setProperty(propertyKey, conflictingValue);
transaction.commit();
}
return null;
}, db).get();
// before we create a node with the same property ourselves - using the same statement that we have
// already used for lookup against that very same index
long node = ktx.dataWrite().nodeCreate();
ktx.dataWrite().nodeAddLabel(node, labelId);
var e = assertThrows(UniquePropertyValueValidationException.class, () -> ktx.dataWrite().nodeSetProperty(node, propertyKeyId, Values.of(conflictingValue)));
assertEquals(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId), e.constraint());
IndexEntryConflictException conflict = Iterators.single(e.conflicts().iterator());
assertEquals(Values.stringValue(conflictingValue), conflict.getSinglePropertyValue());
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class NonUniqueIndexTest method concurrentIndexPopulationAndInsertsShouldNotProduceDuplicates.
@Test
void concurrentIndexPopulationAndInsertsShouldNotProduceDuplicates() throws Exception {
// Given
GraphDatabaseService db = newEmbeddedGraphDatabaseWithSlowJobScheduler();
try {
// When
try (Transaction tx = db.beginTx()) {
tx.schema().indexFor(label(LABEL)).on(KEY).withName(INDEX_NAME).create();
tx.commit();
}
Node node;
try (Transaction tx = db.beginTx()) {
node = tx.createNode(label(LABEL));
node.setProperty(KEY, VALUE);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, MINUTES);
tx.commit();
}
// Then
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
IndexDescriptor index = ktx.schemaRead().indexGetForName(INDEX_NAME);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exact(1, VALUE));
assertTrue(cursor.next());
assertEquals(node.getId(), cursor.nodeReference());
assertFalse(cursor.next());
}
tx.commit();
}
} finally {
managementService.shutdown();
}
}
Aggregations