use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class IndexCRUDIT method addingANodeWithPropertyShouldGetIndexed.
@Test
void addingANodeWithPropertyShouldGetIndexed() throws Exception {
// Given
String indexProperty = "indexProperty";
GatheringIndexWriter writer = newWriter();
createIndex(db, myLabel, indexProperty);
// When
int value1 = 12;
String otherProperty = "otherProperty";
int otherValue = 17;
Node node = createNode(map(indexProperty, value1, otherProperty, otherValue), myLabel);
// Then, for now, this should trigger two NodePropertyUpdates
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenRead tokenRead = ktx.tokenRead();
int propertyKey1 = tokenRead.propertyKey(indexProperty);
int label = tokenRead.nodeLabel(myLabel.name());
LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, propertyKey1);
assertThat(writer.updatesCommitted).isEqualTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, Values.of(value1))));
tx.commit();
}
// We get two updates because we both add a label and a property to be indexed
// in the same transaction, in the future, we should optimize this down to
// one NodePropertyUpdate.
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup.
@Test
void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception {
// given
ConstraintDescriptor constraint = createConstraint("Person", "id");
long ourNode;
{
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
ourNode = createLabeledNode(transaction, "Person", "id", 1);
commit();
}
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
TokenRead tokenRead = transaction.tokenRead();
int propId = tokenRead.propertyKey("id");
IndexDescriptor idx = transaction.schemaRead().indexGetForName(constraint.getName());
// when
createLabeledNode(transaction, "Person", "id", 2);
// then I should find the original node
try (NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker())) {
assertThat(transaction.dataRead().lockingNodeUniqueIndexSeek(idx, cursor, exact(propId, Values.of(1)))).isEqualTo(ourNode);
}
commit();
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck.
@Test
void unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck() throws Exception {
// given
ConstraintDescriptor constraint = createConstraint("Person", "id");
long ourNode;
{
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
ourNode = createLabeledNode(transaction, "Person", "id", 1);
createLabeledNode(transaction, "Item", "id", 2);
commit();
}
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
TokenRead tokenRead = transaction.tokenRead();
int propId = tokenRead.propertyKey("id");
IndexDescriptor idx = transaction.schemaRead().indexGetForName(constraint.getName());
// when
createLabeledNode(transaction, "Item", "id", 2);
// then I should find the original node
try (NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker())) {
assertThat(transaction.dataRead().lockingNodeUniqueIndexSeek(idx, cursor, exact(propId, Values.of(1)))).isEqualTo(ourNode);
}
commit();
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustIncludeOnlineIndexes.
@Test
void schemaStatementsMustIncludeOnlineIndexes() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someIndex();
InternalIndexState indexState = InternalIndexState.ONLINE;
SchemaReadCore schemaReadCore = getSchemaReadCore(index, indexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(1, result.size());
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsShouldHandleConstraintWithBackticks.
@Test
void schemaStatementsShouldHandleConstraintWithBackticks() throws IndexNotFoundKernelException, ProcedureException, LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForSchema(forLabel(1, 1)).withName(NAME_WITH_BACKTICKS);
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint);
TokenRead tokenRead = mock(TokenRead.class);
when(tokenRead.nodeLabelName(1)).thenReturn(LABEL_WITH_BACKTICKS);
when(tokenRead.propertyKeyName(1)).thenReturn(PROPERTY_KEY_WITH_BACKTICKS);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
assertTrue(iter.hasNext());
BuiltInProcedures.SchemaStatementResult next = iter.next();
assertEquals(NAME_WITH_BACKTICKS, next.name);
assertEquals(format("CREATE CONSTRAINT %s ON (a:%s) ASSERT (a.%s) IS NOT NULL", ESCAPED_NAME_WITH_BACKTICKS, ESCAPED_LABEL_WITH_BACKTICKS, ESCAPED_PROPERTY_KEY_WITH_BACKTICKS), next.createStatement);
assertEquals(format("DROP CONSTRAINT %s", ESCAPED_NAME_WITH_BACKTICKS), next.dropStatement);
assertEquals(NAME_WITH_BACKTICKS, next.name);
assertFalse(iter.hasNext());
}
Aggregations