Search in sources :

Example 21 with LabelSchemaDescriptor

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

the class IndexIT method committedAndTransactionalIndexRulesShouldBeMerged.

@Test
void committedAndTransactionalIndexRulesShouldBeMerged() throws Exception {
    // GIVEN
    SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction();
    IndexDescriptor existingRule = schemaWriteOperations.indexCreate(schema, "my index");
    commit();
    // WHEN
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyKeyId2);
    IndexDescriptor addedRule = transaction.schemaWrite().indexCreate(schema, "my other index");
    Set<IndexDescriptor> indexRulesInTx = asSet(transaction.schemaRead().indexesGetForLabel(labelId));
    commit();
    // THEN
    assertEquals(asSet(existingRule, addedRule), indexRulesInTx);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 22 with LabelSchemaDescriptor

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

the class IndexPopulationJobTest method shouldPopulateIndexWithASmallDataset.

@Test
void shouldPopulateIndexWithASmallDataset() throws Exception {
    // GIVEN
    String value = "Mattias";
    long node1 = createNode(map(name, value), FIRST);
    createNode(map(name, value), SECOND);
    createNode(map(age, 31), FIRST);
    long node4 = createNode(map(age, 35, name, value), FIRST);
    IndexPopulator actualPopulator = indexPopulator(false);
    TrackingIndexPopulator populator = new TrackingIndexPopulator(actualPopulator);
    int label = tokenHolders.labelTokens().getIdByName(FIRST.name());
    int prop = tokenHolders.propertyKeyTokens().getIdByName(name);
    LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, prop);
    IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.NODE, IndexPrototype.forSchema(descriptor));
    // WHEN
    job.run();
    // THEN
    IndexEntryUpdate<?> update1 = add(node1, descriptor, Values.of(value));
    IndexEntryUpdate<?> update2 = add(node4, descriptor, Values.of(value));
    assertTrue(populator.created);
    assertEquals(Arrays.asList(update1, update2), populator.includedSamples);
    assertEquals(1, populator.adds.size());
    assertTrue(populator.resultSampled);
    assertTrue(populator.closeCall);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 23 with LabelSchemaDescriptor

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

the class SystemBuiltInProceduresIT method awaitIndex.

@Test
void awaitIndex() 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.awaitIndex('person foo index',10)").hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 24 with LabelSchemaDescriptor

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

the class SchemaComplianceCheckerTest method shouldCheckIndexesWithLookupFiltering.

@Test
void shouldCheckIndexesWithLookupFiltering() throws Exception {
    // given
    LabelSchemaDescriptor descriptor = forLabel(label1, propertyKey1);
    long indexId = uniqueIndex(descriptor);
    long nodeId;
    try (AutoCloseable ignored = tx()) {
        PointValue value = pointValue(CoordinateReferenceSystem.WGS84, 2, 4);
        // (N1) w/ property
        {
            long propId = propertyStore.nextId(CursorContext.NULL);
            nodeId = node(nodeStore.nextId(CursorContext.NULL), propId, NULL, label1);
            property(propId, NULL, NULL, propertyValue(propertyKey1, value));
            indexValue(descriptor, indexId, nodeId, value);
        }
        // (N2) w/ property
        {
            long propId = propertyStore.nextId(CursorContext.NULL);
            long nodeId2 = node(nodeStore.nextId(CursorContext.NULL), propId, NULL, label1);
            property(propId, NULL, NULL, propertyValue(propertyKey1, value));
            indexValue(descriptor, indexId, nodeId2, value);
        }
    }
    // when
    checkIndexed(nodeId);
    // then it should be successful
    expect(ConsistencyReport.NodeConsistencyReport.class, report -> report.uniqueIndexNotUnique(any(), any(), anyLong()));
}
Also used : PointValue(org.neo4j.values.storable.PointValue) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.jupiter.api.Test)

Example 25 with LabelSchemaDescriptor

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

the class TransactionTestBase method shouldFreezeLockInteractions.

@Test
void shouldFreezeLockInteractions() throws Exception {
    // GIVEN
    int label;
    int propertyKey;
    LabelSchemaDescriptor schema;
    try (KernelTransaction tx = beginTransaction()) {
        label = tx.tokenWrite().labelGetOrCreateForName("Label");
        propertyKey = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
        schema = SchemaDescriptor.forLabel(label, propertyKey);
        tx.schemaWrite().indexCreate(schema, "my index");
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        assertAllowedLocks(tx, schema);
        // WHEN
        tx.freezeLocks();
        // THEN
        assertFrozenLocks(tx, schema);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

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