use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaRuleMigrationTest method setUp.
@BeforeEach
void setUp() {
srcTokenHolders = new TokenHolders(StoreTokens.createReadOnlyTokenHolder(TokenHolder.TYPE_PROPERTY_KEY), StoreTokens.createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL), StoreTokens.createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE));
src = mock(SchemaStorage35.class);
writtenRules = new ArrayList<>();
dst = new SchemaRuleMigrationAccess() {
@Override
public void writeSchemaRule(SchemaRule rule) {
writtenRules.add(rule);
}
@Override
public Iterable<SchemaRule> getAll() {
return List.of();
}
@Override
public void close() {
}
};
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaRuleMigrationTest method mustOverwritePreviousDefaultConstraintNames.
@Test
void mustOverwritePreviousDefaultConstraintNames() throws KernelException {
SchemaRule rule = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1).withName("constraint_1");
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2)));
when(src.getAll(any())).thenReturn(List.of(rule));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
assertEquals(1, writtenRules.size());
assertEquals("constraint_952591e6", writtenRules.get(0).getName());
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaRuleMigrationTest method mustOverwritePreviousDefaultIndexNames.
@Test
void mustOverwritePreviousDefaultIndexNames() throws KernelException {
SchemaRule rule = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 2)).withName("index_1").materialise(1);
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2)));
when(src.getAll(any())).thenReturn(List.of(rule));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
assertEquals(1, writtenRules.size());
assertEquals("index_c3fbd584", writtenRules.get(0).getName());
}
use of org.neo4j.internal.schema.SchemaRule 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.SchemaRule in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldCreateEqualEntityPropertyUpdatesOnRecoveryOfCreatedEntities.
@Test
void shouldCreateEqualEntityPropertyUpdatesOnRecoveryOfCreatedEntities() throws Exception {
neoStores = createStores();
/* There was an issue where recovering a tx where a node with a label and a property
* was created resulted in two exact copies of NodePropertyUpdates. */
// GIVEN
long nodeId = 0;
long relId = 1;
int labelId = 5;
int relTypeId = 4;
int propertyKeyId = 7;
// -- indexes
long nodeRuleId = 0;
TransactionRecordState recordState = newTransactionRecordState();
SchemaRule nodeRule = IndexPrototype.forSchema(forLabel(labelId, propertyKeyId)).withName("index_" + nodeRuleId).materialise(nodeRuleId);
recordState.schemaRuleCreate(nodeRuleId, false, nodeRule);
long relRuleId = 1;
SchemaRule relRule = IndexPrototype.forSchema(forRelType(relTypeId, propertyKeyId)).withName("index_" + relRuleId).materialise(relRuleId);
recordState.schemaRuleCreate(relRuleId, false, relRule);
apply(recordState);
// -- and a tx creating a node and a rel for those indexes
recordState = newTransactionRecordState();
recordState.nodeCreate(nodeId);
recordState.addLabelToNode(labelId, nodeId);
recordState.nodeAddProperty(nodeId, propertyKeyId, Values.of("Neo"));
recordState.relModify(singleCreate(relId, relTypeId, nodeId, nodeId));
recordState.relAddProperty(relId, propertyKeyId, Values.of("Oen"));
// WHEN
CommandsToApply transaction = transaction(recordState);
IndexUpdatesExtractor extractor = new IndexUpdatesExtractor();
transaction.accept(extractor);
// THEN
// -- later recovering that tx, there should be only one update for each type
assertTrue(extractor.containsAnyEntityOrPropertyUpdate());
MutableLongSet recoveredNodeIds = new LongHashSet();
recoveredNodeIds.addAll(entityIds(extractor.getNodeCommands()));
assertEquals(1, recoveredNodeIds.size());
assertEquals(nodeId, recoveredNodeIds.longIterator().next());
MutableLongSet recoveredRelIds = new LongHashSet();
recoveredRelIds.addAll(entityIds(extractor.getRelationshipCommands()));
assertEquals(1, recoveredRelIds.size());
assertEquals(relId, recoveredRelIds.longIterator().next());
}
Aggregations