Search in sources :

Example 51 with LabelSchemaDescriptor

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());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 52 with LabelSchemaDescriptor

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());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 53 with LabelSchemaDescriptor

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);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TextValue(org.neo4j.values.storable.TextValue) AnyValue(org.neo4j.values.AnyValue) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 54 with LabelSchemaDescriptor

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);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 55 with LabelSchemaDescriptor

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);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)63 Test (org.junit.jupiter.api.Test)41 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)24 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)16 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)5 Value (org.neo4j.values.storable.Value)5 Transaction (org.neo4j.graphdb.Transaction)4 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)3 Node (org.neo4j.graphdb.Node)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)3 IndexConfig (org.neo4j.internal.schema.IndexConfig)3