use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class SystemBuiltInProceduresIT method listAllIndexes.
@Test
void listAllIndexes() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
int labelId1 = transaction.tokenWrite().labelGetOrCreateForName("Person");
int labelId2 = transaction.tokenWrite().labelGetOrCreateForName("Age");
int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("foo");
int propertyKeyId2 = transaction.tokenWrite().propertyKeyGetOrCreateForName("bar");
LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
LabelSchemaDescriptor ageFooDescriptor = forLabel(labelId2, propertyKeyId1);
LabelSchemaDescriptor personFooBarDescriptor = forLabel(labelId1, propertyKeyId1, propertyKeyId2);
transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(ageFooDescriptor).withName("constraint name"));
transaction.schemaWrite().indexCreate(personFooBarDescriptor, "person foo bar index");
commit();
// let indexes come online
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, MINUTES);
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
// When & Then
assertFalse(tx.execute("CALL db.indexes").hasNext());
}
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class SystemBuiltInProceduresIT method awaitIndexes.
@Test
void awaitIndexes() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
int labelId1 = transaction.tokenWrite().labelGetOrCreateForName("Person");
int labelId2 = transaction.tokenWrite().labelGetOrCreateForName("Age");
int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("foo");
int propertyKeyId2 = transaction.tokenWrite().propertyKeyGetOrCreateForName("bar");
LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
LabelSchemaDescriptor ageFooDescriptor = forLabel(labelId2, propertyKeyId1);
LabelSchemaDescriptor personFooBarDescriptor = forLabel(labelId1, propertyKeyId1, propertyKeyId2);
transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(ageFooDescriptor).withName("constraint name"));
transaction.schemaWrite().indexCreate(personFooBarDescriptor, "person foo bar index");
commit();
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
// When & Then
// this will always be true because that procedure returns void BUT it proves that it runs on system
assertFalse(tx.execute("CALL db.awaitIndexes(10)").hasNext());
}
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class DbIndexesFailureMessageIT method listAllIndexesWithFailedIndex.
@Test
void listAllIndexesWithFailedIndex() throws Throwable {
// Given
KernelTransaction dataTransaction = newTransaction(AUTH_DISABLED);
String labelName = "Fail";
String propertyKey = "foo";
int failedLabel = dataTransaction.tokenWrite().labelGetOrCreateForName(labelName);
int propertyKeyId1 = dataTransaction.tokenWrite().propertyKeyGetOrCreateForName(propertyKey);
this.transaction.createNode(Label.label(labelName)).setProperty(propertyKey, "some value");
commit();
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
LabelSchemaDescriptor schema = forLabel(failedLabel, propertyKeyId1);
IndexDescriptor index = transaction.schemaWrite().indexCreate(schema, "fail foo index");
commit();
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
assertThrows(IllegalStateException.class, () -> tx.schema().awaitIndexesOnline(2, MINUTES));
}
// When
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexDetails")).id(), new TextValue[] { stringValue(index.getName()) }, ProcedureCallContext.EMPTY);
assertTrue(stream.hasNext());
AnyValue[] result = stream.next();
assertFalse(stream.hasNext());
// Commit procedure transaction
commit();
// Then
assertEquals(longValue(index.getId()), result[0]);
assertEquals(stringValue("fail foo index"), result[1]);
assertEquals(stringValue("FAILED"), result[2]);
assertEquals(doubleValue(0.0), result[3]);
assertEquals(stringValue("NONUNIQUE"), result[4]);
assertEquals(stringValue("BTREE"), result[5]);
assertEquals(stringValue("NODE"), result[6]);
assertEquals(VirtualValues.list(stringValue(labelName)), result[7]);
assertEquals(VirtualValues.list(stringValue(propertyKey)), result[8]);
assertEquals(stringValue(NATIVE_BTREE10.providerName()), result[9]);
assertMapsEqual(index.getIndexConfig().asMap(), (MapValue) result[10]);
assertThat(((TextValue) result[11]).stringValue()).contains("java.lang.RuntimeException: Fail on update during population");
assertEquals(12, result.length);
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class AwaitIndexProcedureTest method setup.
@BeforeEach
void setup() throws LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
final int labelId = 0;
final int propId = 0;
LabelSchemaDescriptor anyDescriptor = SchemaDescriptor.forLabel(labelId, propId);
anyIndex = forSchema(anyDescriptor).withName("index").materialise(13);
KernelTransaction transaction = mock(KernelTransaction.class);
schemaRead = mock(SchemaRead.class);
when(transaction.schemaRead()).thenReturn(schemaRead);
TokenRead tokenRead = mock(TokenRead.class);
when(tokenRead.nodeLabelName(labelId)).thenReturn("label_0");
when(tokenRead.propertyKeyName(propId)).thenReturn("prop_0");
when(tokenRead.labelGetName(labelId)).thenReturn("label_0");
when(tokenRead.propertyKeyGetName(propId)).thenReturn("prop_0");
when(transaction.tokenRead()).thenReturn(tokenRead);
procedure = new IndexProcedures(transaction, null);
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class TransactionTestBase method shouldNestFreezeLocks.
@Test
void shouldNestFreezeLocks() throws Exception {
// GIVEN
int label;
int propertyKey;
LabelSchemaDescriptor schema;
try (KernelTransaction tx = beginTransaction()) {
label = tx.tokenWrite().labelGetOrCreateForName("Label");
propertyKey = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
schema = SchemaDescriptor.forLabel(label, propertyKey);
tx.schemaWrite().indexCreate(schema, "my index");
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
// WHEN
tx.freezeLocks();
tx.freezeLocks();
tx.freezeLocks();
tx.freezeLocks();
// THEN
assertFrozenLocks(tx, schema);
// WHEN
tx.thawLocks();
assertFrozenLocks(tx, schema);
tx.thawLocks();
assertFrozenLocks(tx, schema);
tx.thawLocks();
assertFrozenLocks(tx, schema);
tx.thawLocks();
// THEN
assertAllowedLocks(tx, schema);
// WHEN
tx.freezeLocks();
// THEN
assertFrozenLocks(tx, schema);
}
}
Aggregations