use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery.
@Test
public void shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(true);
final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
record.setInUse(false);
final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
verify(schemaStore, times(1)).updateRecord(record);
verify(metaDataStore, never()).setLatestConstraintIntroducingTx(transactionId);
verify(cacheAccess, times(1)).removeSchemaRuleFromCache(command.getKey());
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class BatchInserterImpl method createUniquenessConstraintRule.
private void createUniquenessConstraintRule(UniquenessConstraint constraint) {
// TODO: Do not create duplicate index
long indexRuleId = schemaStore.nextId();
long constraintRuleId = schemaStore.nextId();
int propertyKeyId = constraint.indexDescriptor().schema().getPropertyId();
IndexRule indexRule = IndexRule.constraintIndexRule(indexRuleId, NewIndexDescriptorFactory.uniqueForLabel(constraint.label(), propertyKeyId), this.schemaIndexProviders.getDefaultProvider().getProviderDescriptor(), constraintRuleId);
ConstraintRule constraintRule = ConstraintRule.constraintRule(constraintRuleId, ConstraintDescriptorFactory.uniqueForLabel(constraint.label(), propertyKeyId), indexRuleId);
for (DynamicRecord record : schemaStore.allocateFrom(constraintRule)) {
schemaStore.updateRecord(record);
}
schemaCache.addSchemaRule(constraintRule);
for (DynamicRecord record : schemaStore.allocateFrom(indexRule)) {
schemaStore.updateRecord(record);
}
schemaCache.addSchemaRule(indexRule);
labelsTouched = true;
flushStrategy.forceFlush();
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraintsForRelationshipType.
@Test
public void shouldListConstraintsForRelationshipType() {
// Given
ConstraintRule rule1 = relPropertyExistenceConstraintRule(0, 1, 1);
ConstraintRule rule2 = relPropertyExistenceConstraintRule(0, 2, 1);
ConstraintRule rule3 = relPropertyExistenceConstraintRule(0, 1, 2);
SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
// When
Set<ConstraintDescriptor> listed = asSet(cache.constraintsForRelationshipType(1));
// Then
Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
assertEquals(expected, listed);
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraintsForSchema.
@Test
public void shouldListConstraintsForSchema() {
// Given
ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
// When
Set<ConstraintDescriptor> listed = asSet(cache.constraintsForSchema(rule3.schema()));
// Then
assertEquals(singleton(rule3.getConstraintDescriptor()), listed);
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraintsForLabel.
@Test
public void shouldListConstraintsForLabel() {
// Given
ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
// When
Set<ConstraintDescriptor> listed = asSet(cache.constraintsForLabel(1));
// Then
Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
assertEquals(expected, listed);
}
Aggregations