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));
}
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, "");
}
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));
}
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, "");
}
Aggregations