use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization35Test method assertSerializeAndDeserializeConstraintRule.
private static void assertSerializeAndDeserializeConstraintRule(ConstraintDescriptor constraintRule) throws MalformedSchemaRuleException {
ConstraintDescriptor deserialized = assertConstraintRule(serialiseAndDeserialise(constraintRule));
assertThat(deserialized.getId()).isEqualTo(constraintRule.getId());
assertThat(deserialized).isEqualTo(constraintRule);
assertThat(deserialized.schema()).isEqualTo(constraintRule.schema());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization35Test method assertParseNodePropertyExistsRule.
private static void assertParseNodePropertyExistsRule(String serialized, String name) throws Exception {
// GIVEN
long ruleId = 87;
int propertyKey = 51;
int labelId = 45;
ConstraintDescriptor constraint = existsForLabel(labelId, propertyKey);
byte[] bytes = decodeBase64(serialized);
// WHEN
ConstraintDescriptor deserialized = assertConstraintRule(SchemaRuleSerialization35.deserialize(ruleId, ByteBuffer.wrap(bytes)));
// THEN
assertThat(deserialized.getId()).isEqualTo(ruleId);
assertThat(deserialized).isEqualTo(constraint);
assertThat(deserialized.schema()).isEqualTo(constraint.schema());
assertThatThrownBy(() -> deserialized.asIndexBackedConstraint().ownedIndexId()).isInstanceOf(IllegalStateException.class);
assertThat(deserialized.getName()).isEqualTo(name);
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.
@ParameterizedTest
@MethodSource("params")
void shouldCreateConsistentUniquenessConstraint(int denseNodeThreshold) throws Exception {
// given
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
// when
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// then
GraphDatabaseAPI graphdb = switchToEmbeddedGraphDatabaseService(inserter, denseNodeThreshold);
try {
NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
SchemaStore store = neoStores.getSchemaStore();
TokenHolders tokenHolders = graphdb.getDependencyResolver().resolveDependency(TokenHolders.class);
SchemaRuleAccess schemaRuleAccess = SchemaRuleAccess.getSchemaRuleAccess(store, tokenHolders, () -> KernelVersion.LATEST);
List<Long> inUse = new ArrayList<>();
SchemaRecord record = store.newRecord();
for (long i = 1, high = store.getHighestPossibleIdInUse(NULL); i <= high; i++) {
store.getRecord(i, record, RecordLoad.FORCE, NULL);
if (record.inUse()) {
inUse.add(i);
}
}
assertEquals(2, inUse.size(), "records in use");
SchemaRule rule0 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(0), NULL);
SchemaRule rule1 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(1), NULL);
IndexDescriptor indexRule;
ConstraintDescriptor constraint;
if (rule0 instanceof IndexDescriptor) {
indexRule = (IndexDescriptor) rule0;
constraint = (ConstraintDescriptor) rule1;
} else {
constraint = (ConstraintDescriptor) rule0;
indexRule = (IndexDescriptor) rule1;
}
OptionalLong owningConstraintId = indexRule.getOwningConstraintId();
assertTrue(owningConstraintId.isPresent(), "index should have owning constraint");
assertEquals(constraint.getId(), owningConstraintId.getAsLong(), "index should reference constraint");
assertEquals(indexRule.getId(), constraint.asIndexBackedConstraint().ownedIndexId(), "constraint should reference index");
} finally {
managementService.shutdown();
}
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class KernelSchemaStateFlushingTest method shouldInvalidateSchemaStateOnDropConstraint.
@Test
void shouldInvalidateSchemaStateOnDropConstraint() throws Exception {
// given
ConstraintDescriptor descriptor = createConstraint();
commitToSchemaState("test", "before");
dropConstraint(descriptor);
// when
String after = commitToSchemaState("test", "after");
// then
assertEquals("after", after);
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class TransactionRecordStateTest method preparingConstraintRulesMustMarkSchemaRecordAsChanged.
@Test
void preparingConstraintRulesMustMarkSchemaRecordAsChanged() throws Exception {
neoStores = createStores();
TransactionRecordState state = newTransactionRecordState();
long ruleId = neoStores.getSchemaStore().nextId(NULL);
ConstraintDescriptor rule = ConstraintDescriptorFactory.existsForLabel(0, 1).withId(ruleId);
state.schemaRuleCreate(ruleId, true, rule);
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands, INSTANCE);
assertThat(commands.size()).isEqualTo(1);
SchemaRuleCommand command = (SchemaRuleCommand) commands.get(0);
assertThat(command.getMode()).isEqualTo(Command.Mode.CREATE);
assertThat(command.getSchemaRule()).isEqualTo(rule);
assertThat(command.getKey()).isEqualTo(ruleId);
assertThat(command.getBefore().inUse()).isEqualTo(false);
assertThat(command.getAfter().inUse()).isEqualTo(true);
assertThat(command.getAfter().isConstraint()).isEqualTo(true);
assertThat(command.getAfter().isCreated()).isEqualTo(true);
assertThat(command.getAfter().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
}
Aggregations