Search in sources :

Example 36 with LabelSchemaDescriptor

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

the class IndexEntryConflictExceptionTest method shouldMakeEntryConflicts.

@Test
void shouldMakeEntryConflicts() {
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, 2);
    IndexEntryConflictException e = new IndexEntryConflictException(0L, 1L, value);
    assertThat(e.evidenceMessage(tokens, schema)).isEqualTo("Both Node(0) and Node(1) have the label `label1` and property `p2` = 'hi'");
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 37 with LabelSchemaDescriptor

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

the class SchemaDescriptorTest method shouldCreateLabelDescriptors.

@Test
void shouldCreateLabelDescriptors() {
    LabelSchemaDescriptor labelDesc;
    labelDesc = SchemaDescriptor.forLabel(LABEL_ID, 1);
    assertThat(labelDesc.getLabelId()).isEqualTo(LABEL_ID);
    assertThat(labelDesc.entityType()).isEqualTo(EntityType.NODE);
    assertThat(labelDesc.propertySchemaType()).isEqualTo(PropertySchemaType.COMPLETE_ALL_TOKENS);
    assertArray(labelDesc.getPropertyIds(), 1);
    labelDesc = SchemaDescriptor.forLabel(LABEL_ID, 1, 2, 3);
    assertThat(labelDesc.getLabelId()).isEqualTo(LABEL_ID);
    assertArray(labelDesc.getPropertyIds(), 1, 2, 3);
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with LabelSchemaDescriptor

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

the class SchemaComplianceCheckerTest method shouldReportNotUniquelyIndexed.

@Test
void shouldReportNotUniquelyIndexed() throws Exception {
    // given
    LabelSchemaDescriptor descriptor = forLabel(label1, propertyKey1);
    long indexId = uniqueIndex(descriptor);
    long nodeId;
    try (AutoCloseable ignored = tx()) {
        TextValue value = stringValue("a");
        // (N1) indexed w/ property A
        {
            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) indexed w/ property A
        {
            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
    expect(ConsistencyReport.NodeConsistencyReport.class, report -> report.uniqueIndexNotUnique(any(), any(), anyLong()));
}
Also used : TextValue(org.neo4j.values.storable.TextValue) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.jupiter.api.Test)

Example 39 with LabelSchemaDescriptor

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

the class SchemaComplianceCheckerTest method shouldReportNotIndexed.

@Test
void shouldReportNotIndexed() throws Exception {
    // given
    LabelSchemaDescriptor descriptor = forLabel(label1, propertyKey1);
    index(descriptor);
    long nodeId;
    try (AutoCloseable ignored = tx()) {
        // (N1) w/ property A (NOT indexed)
        long propId = propertyStore.nextId(CursorContext.NULL);
        nodeId = node(nodeStore.nextId(CursorContext.NULL), propId, NULL, label1);
        property(propId, NULL, NULL, propertyValue(propertyKey1, stringValue("a")));
    }
    // when
    checkIndexed(nodeId);
    // then
    expect(ConsistencyReport.NodeConsistencyReport.class, report -> report.notIndexed(any(), any()));
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.jupiter.api.Test)

Example 40 with LabelSchemaDescriptor

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

the class IndexPopulationJobTest method shouldPopulateIndexWithOneNode.

@Test
void shouldPopulateIndexWithOneNode() throws Exception {
    // GIVEN
    String value = "Taylor";
    long nodeId = createNode(map(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<?> update = IndexEntryUpdate.add(nodeId, descriptor, Values.of(value));
    assertTrue(populator.created);
    assertEquals(Collections.singletonList(update), 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)

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