Search in sources :

Example 46 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class SystemBuiltInProceduresIT method resampleIndex.

@Test
void resampleIndex() throws Throwable {
    // Given
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    int labelId1 = transaction.tokenWrite().labelGetOrCreateForName("Person");
    int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("foo");
    LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
    transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
    commit();
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        // When & Then
        // this will always be true because that procedure returns void BUT it proves that it runs on system
        assertFalse(tx.execute("CALL db.resampleIndex('person foo index')").hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 47 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class SystemBuiltInProceduresIT method awaitEventuallyConsistentIndexRefresh.

@Test
void awaitEventuallyConsistentIndexRefresh() throws Throwable {
    // Given
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    int labelId1 = transaction.tokenWrite().labelGetOrCreateForName("Person");
    int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("foo");
    LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
    transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
    commit();
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        // When & Then
        // this will always be true because that procedure returns void BUT it proves that it runs on system
        assertFalse(tx.execute("CALL db.index.fulltext.awaitEventuallyConsistentIndexRefresh").hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 48 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class SystemBuiltInProceduresIT method resampleOutdatedIndexes.

@Test
void resampleOutdatedIndexes() throws Throwable {
    // Given
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    int labelId1 = transaction.tokenWrite().labelGetOrCreateForName("Person");
    int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("foo");
    LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
    transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
    commit();
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        // When & Then
        // this will always be true because that procedure returns void BUT it proves that it runs on system
        assertFalse(tx.execute("CALL db.resampleOutdatedIndexes").hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 49 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method createUniquenessConstraint.

private IndexDescriptor createUniquenessConstraint(int labelId, int... propertyIds) throws Exception {
    KernelTransaction transaction = newTransaction(LoginContext.AUTH_DISABLED);
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyIds);
    ConstraintDescriptor constraint = transaction.schemaWrite().uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(schema));
    IndexDescriptor index = transaction.schemaRead().indexGetForName(constraint.getName());
    commit();
    return index;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 50 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexIT method shouldListConstraintIndexesInTheCoreAPI.

@Test
void shouldListConstraintIndexesInTheCoreAPI() throws Exception {
    // given
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    long initialIndexCount = Iterators.count(transaction.schemaRead().indexesGetAll());
    int labelId = transaction.tokenWrite().labelGetOrCreateForName("Label1");
    int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName("property1");
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyKeyId);
    transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(schema).withName("constraint name"));
    commit();
    // when
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        // then
        Set<IndexDefinition> indexes = Iterables.asSet(tx.schema().getIndexes());
        assertThat(indexes.size()).isEqualTo(initialIndexCount + 1);
        IndexDefinition index = tx.schema().getIndexByName("constraint name");
        assertThat(index.getLabels()).map(Label::name).containsOnly("Label1");
        assertThat(index.getPropertyKeys()).containsOnly("property1");
        assertTrue(index.isConstraintIndex(), "index should be a constraint index");
        // when
        var e = assertThrows(IllegalStateException.class, index::drop);
        assertEquals("Constraint indexes cannot be dropped directly, instead drop the owning uniqueness constraint.", e.getMessage());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)63 Test (org.junit.jupiter.api.Test)41 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)24 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)16 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)5 Value (org.neo4j.values.storable.Value)5 Transaction (org.neo4j.graphdb.Transaction)4 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)3 Node (org.neo4j.graphdb.Node)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)3 IndexConfig (org.neo4j.internal.schema.IndexConfig)3