Search in sources :

Example 96 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaCacheTest method shouldResolveIndexDescriptor.

@Test
public void shouldResolveIndexDescriptor() throws Exception {
    // Given
    SchemaCache cache = newSchemaCache();
    cache.addSchemaRule(newIndexRule(1L, 1, 2));
    cache.addSchemaRule(newIndexRule(2L, 1, 3));
    cache.addSchemaRule(newIndexRule(3L, 2, 2));
    // When
    LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel(1, 3);
    NewIndexDescriptor descriptor = cache.indexDescriptor(schema);
    // Then
    assertThat(descriptor.schema(), equalTo(schema));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 97 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaRuleSerializationTest method assertParseIndexRule.

private void assertParseIndexRule(String serialized, String name) throws Exception {
    // GIVEN
    long ruleId = 24;
    NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(512, 4);
    SchemaIndexProvider.Descriptor indexProvider = new SchemaIndexProvider.Descriptor("index-provider", "25.0");
    byte[] bytes = decodeBase64(serialized);
    //        System.out.println( encodeBase64( IndexRule.indexRule( ruleId, index, indexProvider, "custom_name" ).serialize() ) );
    // WHEN
    IndexRule deserialized = assertIndexRule(SchemaRuleSerialization.deserialize(ruleId, ByteBuffer.wrap(bytes)));
    // THEN
    assertThat(deserialized.getId(), equalTo(ruleId));
    assertThat(deserialized.getIndexDescriptor(), equalTo(index));
    assertThat(deserialized.schema(), equalTo(index.schema()));
    assertThat(deserialized.getProviderDescriptor(), equalTo(indexProvider));
    assertThat(deserialized.getName(), is(name));
    assertException(deserialized::getOwningConstraint, IllegalStateException.class, "");
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 98 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class IndexRuleTest method shouldCreateUniqueIndex.

@Test
public void shouldCreateUniqueIndex() throws Exception {
    // GIVEN
    NewIndexDescriptor descriptor = uniqueForLabel(LABEL_ID, PROPERTY_ID_1);
    IndexRule indexRule = IndexRule.indexRule(RULE_ID, descriptor, PROVIDER_DESCRIPTOR);
    // THEN
    assertThat(indexRule.getId(), equalTo(RULE_ID));
    assertTrue(indexRule.canSupportUniqueConstraint());
    assertThat(indexRule.schema(), equalTo(descriptor.schema()));
    assertThat(indexRule.getIndexDescriptor(), equalTo(descriptor));
    assertThat(indexRule.getProviderDescriptor(), equalTo(PROVIDER_DESCRIPTOR));
    assertThat(indexRule.getOwningConstraint(), equalTo(null));
    IndexRule withConstraint = indexRule.withOwningConstraint(RULE_ID_2);
    assertThat(withConstraint.getOwningConstraint(), equalTo(RULE_ID_2));
    // this is unchanged
    assertThat(indexRule.getOwningConstraint(), equalTo(null));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 99 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class IndexRuleTest method shouldCreateGeneralIndex.

@Test
public void shouldCreateGeneralIndex() throws Exception {
    // GIVEN
    NewIndexDescriptor descriptor = forLabel(LABEL_ID, PROPERTY_ID_1);
    IndexRule indexRule = IndexRule.indexRule(RULE_ID, descriptor, PROVIDER_DESCRIPTOR);
    // THEN
    assertThat(indexRule.getId(), equalTo(RULE_ID));
    assertFalse(indexRule.canSupportUniqueConstraint());
    assertThat(indexRule.schema(), equalTo(descriptor.schema()));
    assertThat(indexRule.getIndexDescriptor(), equalTo(descriptor));
    assertThat(indexRule.getProviderDescriptor(), equalTo(PROVIDER_DESCRIPTOR));
    assertException(indexRule::getOwningConstraint, IllegalStateException.class, "");
    assertException(() -> indexRule.withOwningConstraint(RULE_ID_2), IllegalStateException.class, "");
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Aggregations

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)99 Test (org.junit.Test)55 Statement (org.neo4j.kernel.api.Statement)24 ReadOperations (org.neo4j.kernel.api.ReadOperations)17 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)9 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)7 Transaction (org.neo4j.graphdb.Transaction)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)5 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 KernelException (org.neo4j.kernel.api.exceptions.KernelException)4 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)4