use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class FullCheckIntegrationTest method createNodePropertyExistenceConstraint.
private void createNodePropertyExistenceConstraint(int labelId, int propertyKeyId) {
SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore();
ConstraintRule rule = nodePropertyExistenceConstraintRule(schemaStore.nextId(), labelId, propertyKeyId);
Collection<DynamicRecord> records = schemaStore.allocateFrom(rule);
for (DynamicRecord record : records) {
schemaStore.updateRecord(record);
}
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportInvalidConstraintBackReferences.
@Test
public void shouldReportInvalidConstraintBackReferences() throws Exception {
// given
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
int ruleId1 = (int) next.schema();
int ruleId2 = (int) next.schema();
int labelId = next.label();
int propertyKeyId = next.propertyKey();
DynamicRecord record1 = new DynamicRecord(ruleId1);
DynamicRecord record2 = new DynamicRecord(ruleId2);
DynamicRecord record1Before = record1.clone();
DynamicRecord record2Before = record2.clone();
IndexRule rule1 = constraintIndexRule(ruleId1, labelId, propertyKeyId, DESCRIPTOR, (long) ruleId2);
ConstraintRule rule2 = uniquenessConstraintRule(ruleId2, labelId, propertyKeyId, ruleId2);
Collection<DynamicRecord> records1 = serializeRule(rule1, record1);
Collection<DynamicRecord> records2 = serializeRule(rule2, record2);
assertEquals(asList(record1), records1);
assertEquals(asList(record2), records2);
tx.nodeLabel(labelId, "label");
tx.propertyKey(propertyKeyId, "property");
tx.createSchema(asList(record1Before), records1, rule1);
tx.createSchema(asList(record2Before), records2, rule2);
}
});
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.SCHEMA, 2).andThatsAllFolks();
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery.
@Test
public void shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(true);
final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
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, times(1)).setLatestConstraintIntroducingTx(transactionId);
verify(cacheAccess, times(1)).addSchemaRule(rule);
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery.
@Test
public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(true);
final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
record.setCreated();
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, times(1)).setLatestConstraintIntroducingTx(transactionId);
verify(cacheAccess, times(1)).addSchemaRule(rule);
}
use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.
the class SchemaRuleCommandTest method shouldSetLatestConstraintRule.
@Test
public void shouldSetLatestConstraintRule() throws Exception {
// Given
SchemaRecord beforeRecords = serialize(rule, id, true, true);
SchemaRecord afterRecords = serialize(rule, id, true, false);
when(neoStores.getSchemaStore()).thenReturn(schemaStore);
when(neoStores.getMetaDataStore()).thenReturn(metaDataStore);
ConstraintRule schemaRule = ConstraintRule.constraintRule(id, ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKey), 0);
// WHEN
visitSchemaRuleCommand(storeApplier, new SchemaRuleCommand(beforeRecords, afterRecords, schemaRule));
// THEN
verify(schemaStore).updateRecord(Iterables.first(afterRecords));
verify(metaDataStore).setLatestConstraintIntroducingTx(txId);
}
Aggregations