use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludePopulatingIndexes.
@Test
void schemaStatementsMustNotIncludePopulatingIndexes() throws ProcedureException, IndexNotFoundKernelException {
IndexDescriptor index = someIndex();
InternalIndexState indexState = InternalIndexState.POPULATING;
SchemaReadCore schemaReadCore = getSchemaReadCore(index, indexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(0, result.size());
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex.
@Test
void schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
ConstraintDescriptor constraint = indexBackedConstraint(index);
index = indexBoundToConstraint(index, constraint);
InternalIndexState internalIndexState = InternalIndexState.ONLINE;
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
assertTrue(iter.hasNext());
BuiltInProcedures.SchemaStatementResult next = iter.next();
assertEquals(SchemaStatementProcedure.SchemaRuleType.CONSTRAINT.name(), next.type);
assertEquals(CONSTRAINT_NAME, next.name);
assertFalse(iter.hasNext());
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class AwaitIndexProcedureTest method setup.
@BeforeEach
void setup() throws LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
final int labelId = 0;
final int propId = 0;
LabelSchemaDescriptor anyDescriptor = SchemaDescriptor.forLabel(labelId, propId);
anyIndex = forSchema(anyDescriptor).withName("index").materialise(13);
KernelTransaction transaction = mock(KernelTransaction.class);
schemaRead = mock(SchemaRead.class);
when(transaction.schemaRead()).thenReturn(schemaRead);
TokenRead tokenRead = mock(TokenRead.class);
when(tokenRead.nodeLabelName(labelId)).thenReturn("label_0");
when(tokenRead.propertyKeyName(propId)).thenReturn("prop_0");
when(tokenRead.labelGetName(labelId)).thenReturn("label_0");
when(tokenRead.propertyKeyGetName(propId)).thenReturn("prop_0");
when(transaction.tokenRead()).thenReturn(tokenRead);
procedure = new IndexProcedures(transaction, null);
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldAnswerExactIfCypherCompatible.
@Test
void shouldAnswerExactIfCypherCompatible() throws KernelException {
IndexDescriptor indexReference;
Label containsLabel = label("containsLabel");
String containsProp = "containsProp";
long nodea;
long nodeapa1;
long nodeapa2;
long nodeapaapa;
try (Transaction tx = db.beginTx()) {
nodea = createNode(tx, containsLabel, containsProp, "a");
createNode(tx, containsLabel, containsProp, "A");
nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
createNode(tx, containsLabel, containsProp, "longapa");
nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
createNode(tx, containsLabel, containsProp, "apalong");
tx.commit();
}
int containsLabelId;
int containsPropertyId;
try (Transaction tx = db.beginTx()) {
TokenRead tokenRead = tokenRead(tx);
containsLabelId = tokenRead.nodeLabel(containsLabel.name());
containsPropertyId = tokenRead.propertyKey(containsProp);
}
indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
await(indexReference);
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, exactQuery(containsPropertyId, "a"), nodea);
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2);
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa a"));
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa apa"), nodeapaapa);
assertQueryResult(ktx, exactQuery(containsPropertyId, "*apa"));
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
IndexNotApplicableKernelException e = assertThrows(IndexNotApplicableKernelException.class, () -> assertQueryResult(ktx, exactQuery(containsPropertyId, 1)));
assertThat(e.getMessage()).contains("A fulltext schema index cannot answer " + PropertyIndexQuery.IndexQueryType.exact + " queries on " + ValueCategory.NUMBER + " values.");
}
controller.restartDbms();
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, exactQuery(containsPropertyId, "a"), nodea);
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2);
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa a"));
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa apa"), nodeapaapa);
assertQueryResult(ktx, exactQuery(containsPropertyId, "*apa"));
assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
IndexNotApplicableKernelException e = assertThrows(IndexNotApplicableKernelException.class, () -> assertQueryResult(ktx, exactQuery(containsPropertyId, 1)));
assertThat(e.getMessage()).contains("A fulltext schema index cannot answer " + PropertyIndexQuery.IndexQueryType.exact + " queries on " + ValueCategory.NUMBER + " values.");
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldAnswerEndsWithIfCypherCompatible.
@Test
void shouldAnswerEndsWithIfCypherCompatible() throws KernelException {
IndexDescriptor indexReference;
Label containsLabel = label("containsLabel");
String containsProp = "containsProp";
long nodea;
long nodeapa1;
long nodeapa2;
long nodelongapa;
long nodeapaapa;
try (Transaction tx = db.beginTx()) {
nodea = createNode(tx, containsLabel, containsProp, "a");
createNode(tx, containsLabel, containsProp, "A");
nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
nodelongapa = createNode(tx, containsLabel, containsProp, "longapa");
nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
createNode(tx, containsLabel, containsProp, "apalong");
tx.commit();
}
int containsLabelId;
int containsPropertyId;
try (Transaction tx = db.beginTx()) {
TokenRead tokenRead = tokenRead(tx);
containsLabelId = tokenRead.nodeLabel(containsLabel.name());
containsPropertyId = tokenRead.propertyKey(containsProp);
}
indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
await(indexReference);
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "a apa"), nodeapaapa);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "*apa"));
}
controller.restartDbms();
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "a apa"), nodeapaapa);
assertQueryResult(ktx, endsWithQuery(containsPropertyId, "*apa"));
}
}
Aggregations