Search in sources :

Example 56 with LabelSchemaDescriptor

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

the class TransactionTestBase method shouldThrowOnThawOfNotFrozenLocks.

@Test
void shouldThrowOnThawOfNotFrozenLocks() 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()) {
        // WHEN
        assertThrows(LocksNotFrozenException.class, tx::thawLocks);
        // THEN
        assertAllowedLocks(tx, schema);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 57 with LabelSchemaDescriptor

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

the class TransactionTestBase method shouldThawLockInteractions.

@Test
void shouldThawLockInteractions() 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()) {
        // WHEN
        tx.freezeLocks();
        tx.thawLocks();
        // THEN
        assertAllowedLocks(tx, schema);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 58 with LabelSchemaDescriptor

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

the class GenericNativeIndexProviderTest method completeConfigurationMustNotOverrideExistingSettings.

@Test
void completeConfigurationMustNotOverrideExistingSettings() {
    // Given
    DatabaseIndexContext context = DatabaseIndexContext.builder(null, null, DEFAULT_DATABASE_NAME).build();
    GenericNativeIndexProvider provider = new GenericNativeIndexProvider(context, IndexDirectoryStructure.NONE, null, Config.defaults());
    Map<String, Value> existingSettings = new HashMap<>();
    CoordinateReferenceSystem existingCrs = CoordinateReferenceSystem.Cartesian;
    DoubleArray min = Values.doubleArray(new double[] { 0, 0 });
    DoubleArray max = Values.doubleArray(new double[] { 1, 1 });
    existingSettings.put(spatialMinSettingForCrs(existingCrs).getSettingName(), min);
    existingSettings.put(spatialMaxSettingForCrs(existingCrs).getSettingName(), max);
    IndexConfig existingIndexConfig = IndexConfig.with(existingSettings);
    LabelSchemaDescriptor incompleteSchema = SchemaDescriptor.forLabel(1, 1);
    IndexDescriptor incompleteDescriptor = IndexPrototype.forSchema(incompleteSchema, IndexProviderDescriptor.UNDECIDED).withName("index").materialise(1).withIndexConfig(existingIndexConfig);
    // When
    IndexDescriptor completedDescriptor = provider.completeConfiguration(incompleteDescriptor);
    // Then
    IndexConfig completedIndexConfig = completedDescriptor.getIndexConfig();
    for (CoordinateReferenceSystem crs : CoordinateReferenceSystem.all()) {
        if (crs.equals(existingCrs)) {
            // Assert value
            assertEquals(min, completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
            assertEquals(max, completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
        } else {
            // Simply assert not null
            assertNotNull(completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
            assertNotNull(completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
        }
    }
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) HashMap(java.util.HashMap) Value(org.neo4j.values.storable.Value) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DoubleArray(org.neo4j.values.storable.DoubleArray) Test(org.junit.jupiter.api.Test)

Example 59 with LabelSchemaDescriptor

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

the class GenericNativeIndexProviderTest method mustCompleteIndexDescriptorConfigurationsWithSpatialConfig.

@Test
void mustCompleteIndexDescriptorConfigurationsWithSpatialConfig() {
    // Given
    DatabaseIndexContext context = DatabaseIndexContext.builder(null, null, DEFAULT_DATABASE_NAME).build();
    GenericNativeIndexProvider provider = new GenericNativeIndexProvider(context, IndexDirectoryStructure.NONE, null, Config.defaults());
    LabelSchemaDescriptor incompleteSchema = SchemaDescriptor.forLabel(1, 1);
    IndexDescriptor incompleteDescriptor = IndexPrototype.forSchema(incompleteSchema, IndexProviderDescriptor.UNDECIDED).withName("index").materialise(1);
    // When
    IndexDescriptor completedDescriptor = provider.completeConfiguration(incompleteDescriptor);
    // Then
    IndexConfig sinfulIndexConfig = incompleteDescriptor.getIndexConfig();
    IndexConfig completedIndexConfig = completedDescriptor.getIndexConfig();
    assertEquals(0, sinfulIndexConfig.entries().count(p -> true), "expected sinful index config to have no entries");
    for (CoordinateReferenceSystem crs : CoordinateReferenceSystem.all()) {
        assertNotNull(completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
        assertNotNull(completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
    }
}
Also used : DoubleArray(org.neo4j.values.storable.DoubleArray) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) HashMap(java.util.HashMap) Config(org.neo4j.configuration.Config) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) Value(org.neo4j.values.storable.Value) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexSettingUtil.spatialMinSettingForCrs(org.neo4j.graphdb.schema.IndexSettingUtil.spatialMinSettingForCrs) Values(org.neo4j.values.storable.Values) Test(org.junit.jupiter.api.Test) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) IndexSettingUtil.spatialMaxSettingForCrs(org.neo4j.graphdb.schema.IndexSettingUtil.spatialMaxSettingForCrs) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Map(java.util.Map) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexConfig(org.neo4j.internal.schema.IndexConfig) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 60 with LabelSchemaDescriptor

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

the class TxStateTest method shouldDifferentiateBetweenUniquenessConstraintsForDifferentLabels.

@Test
void shouldDifferentiateBetweenUniquenessConstraintsForDifferentLabels() {
    // when
    LabelSchemaDescriptor schema1 = forLabel(1, 17);
    UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForSchema(schema1);
    state.constraintDoAdd(constraint1, IndexPrototype.uniqueForSchema(schema1).withName("constraint_7").materialise(7));
    LabelSchemaDescriptor schema2 = forLabel(2, 17);
    UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForSchema(schema2);
    state.constraintDoAdd(constraint2, IndexPrototype.uniqueForSchema(schema2).withName("constraint_19").materialise(19));
    // then
    assertEquals(singleton(constraint1), state.constraintsChangesForLabel(1).getAdded());
    assertEquals(singleton(constraint2), state.constraintsChangesForLabel(2).getAdded());
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) RepeatedTest(org.junit.jupiter.api.RepeatedTest) 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