use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.
the class BuiltInProceduresIT method listAllLabelsMustNotBlockOnConstraintCreatingTransaction.
@Test
@Timeout(value = 6, unit = MINUTES)
void listAllLabelsMustNotBlockOnConstraintCreatingTransaction() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
long nodeId = transaction.dataWrite().nodeCreate();
int labelId = transaction.tokenWrite().labelGetOrCreateForName("MyLabel");
int propKey = transaction.tokenWrite().propertyKeyCreateForName("prop", false);
transaction.dataWrite().nodeAddLabel(nodeId, labelId);
commit();
CountDownLatch constraintLatch = new CountDownLatch(1);
CountDownLatch commitLatch = new CountDownLatch(1);
FutureTask<Void> createConstraintTask = new FutureTask<>(() -> {
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
try (Resource ignore = captureTransaction()) {
IndexPrototype prototype = IndexPrototype.uniqueForSchema(SchemaDescriptor.forLabel(labelId, propKey)).withName("constraint name");
schemaWrite.uniquePropertyConstraintCreate(prototype);
// We now hold a schema lock on the "MyLabel" label. Let the procedure calling transaction have a go.
constraintLatch.countDown();
commitLatch.await();
}
rollback();
return null;
});
Thread constraintCreator = new Thread(createConstraintTask);
constraintCreator.start();
// When
constraintLatch.await();
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "labels")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
try {
assertThat(asList(stream)).containsExactly(new AnyValue[] { stringValue("MyLabel") });
} finally {
commitLatch.countDown();
}
createConstraintTask.get();
constraintCreator.join();
}
use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.
the class KernelIT method createIndex.
private static IndexDescriptor createIndex(KernelTransaction transaction) throws KernelException {
TokenWrite tokenWrite = transaction.tokenWrite();
SchemaWrite schemaWrite = transaction.schemaWrite();
LabelSchemaDescriptor schema = forLabel(tokenWrite.labelGetOrCreateForName("hello"), tokenWrite.propertyKeyGetOrCreateForName("hepp"));
return schemaWrite.indexCreate(schema, null);
}
use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.
the class SystemBuiltInProceduresIT method listConstraints.
@Test
void listConstraints() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
TokenWrite tokenWrite = transaction.tokenWrite();
int labelId = tokenWrite.labelGetOrCreateForName("Label");
int propId = tokenWrite.propertyKeyGetOrCreateForName("property");
SchemaWrite schemaWrite = transaction.schemaWrite();
schemaWrite.uniquePropertyConstraintCreate(uniqueForSchema(forLabel(labelId, propId)).withName("my_constraint"));
commit();
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
// When & Then
assertFalse(tx.execute("CALL db.constraints").hasNext());
}
}
use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method createConstraint.
private ConstraintDescriptor createConstraint(String label, String propertyKey) throws KernelException {
int labelId;
int propertyKeyId;
TokenWrite tokenWrite = tokenWriteInNewTransaction();
labelId = tokenWrite.labelGetOrCreateForName(label);
propertyKeyId = tokenWrite.propertyKeyGetOrCreateForName(propertyKey);
commit();
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
ConstraintDescriptor constraint = schemaWrite.uniquePropertyConstraintCreate(uniqueForSchema(forLabel(labelId, propertyKeyId)));
commit();
return constraint;
}
use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.
the class IndexIT method shouldDisallowDroppingIndexBySchemaThatDoesNotExist.
@Test
void shouldDisallowDroppingIndexBySchemaThatDoesNotExist() throws Exception {
// given
IndexDescriptor index;
{
SchemaWrite statement = schemaWriteInNewTransaction();
index = statement.indexCreate(schema, "my index");
commit();
}
{
SchemaWrite statement = schemaWriteInNewTransaction();
statement.indexDrop(index.schema());
commit();
}
// when
SchemaWrite statement = schemaWriteInNewTransaction();
SchemaKernelException e = assertThrows(SchemaKernelException.class, () -> statement.indexDrop(index.schema()));
assertEquals("Unable to drop index on (:" + LABEL + " {" + PROPERTY_KEY + "}). There is no such index.", e.getMessage());
commit();
}
Aggregations