Search in sources :

Example 81 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class BuiltInProceduresIT 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(IndexPrototype.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();
    }
    transaction = newTransaction();
    IndexDescriptor personFooIndex = single(transaction.schemaRead().index(personFooDescriptor));
    IndexDescriptor ageFooIndex = single(transaction.schemaRead().index(ageFooDescriptor));
    IndexDescriptor personFooBarIndex = single(transaction.schemaRead().index(personFooBarDescriptor));
    // When
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexes")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    Set<AnyValue[]> result = new HashSet<>();
    while (stream.hasNext()) {
        result.add(stream.next());
    }
    // Then
    assertThat(result).contains(dbIndexesResult(ageFooIndex.getId(), ageFooIndex.getName(), "ONLINE", 100D, "UNIQUE", "BTREE", "NODE", singletonList("Age"), singletonList("foo"), ageFooIndex.getIndexProvider().name()), dbIndexesResult(personFooIndex.getId(), personFooIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), singletonList("foo"), personFooIndex.getIndexProvider().name()), dbIndexesResult(personFooBarIndex.getId(), personFooBarIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), Arrays.asList("foo", "bar"), personFooBarIndex.getIndexProvider().name()));
    commit();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 82 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class BuiltInProceduresIT method listAllIndexesMustNotBlockOnConstraintCreatingTransaction.

@Test
@Timeout(value = 6, unit = MINUTES)
void listAllIndexesMustNotBlockOnConstraintCreatingTransaction() 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");
    int propertyKeyId3 = transaction.tokenWrite().propertyKeyGetOrCreateForName("baz");
    LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
    LabelSchemaDescriptor ageFooDescriptor = forLabel(labelId2, propertyKeyId1);
    LabelSchemaDescriptor personFooBarDescriptor = forLabel(labelId1, propertyKeyId1, propertyKeyId2);
    LabelSchemaDescriptor personBazDescriptor = forLabel(labelId1, propertyKeyId3);
    transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
    transaction.schemaWrite().uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(ageFooDescriptor).withName("age foo constraint"));
    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();
    }
    CountDownLatch constraintLatch = new CountDownLatch(1);
    CountDownLatch commitLatch = new CountDownLatch(1);
    AtomicLong personBazIndexId = new AtomicLong();
    FutureTask<Void> createConstraintTask = new FutureTask<>(() -> {
        SchemaWrite schemaWrite = schemaWriteInNewTransaction();
        try (Resource ignore = captureTransaction()) {
            ConstraintDescriptor personBazConstraint = schemaWrite.uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(personBazDescriptor).withName("person baz constraint"));
            personBazIndexId.set(personBazConstraint.asIndexBackedConstraint().ownedIndexId());
            // 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();
    transaction = newTransaction();
    final SchemaReadCore schemaRead = transaction.schemaRead().snapshot();
    IndexDescriptor personFooIndex = single(schemaRead.index(personFooDescriptor));
    IndexDescriptor ageFooIndex = single(schemaRead.index(ageFooDescriptor));
    IndexDescriptor personFooBarIndex = single(schemaRead.index(personFooBarDescriptor));
    IndexDescriptor personBazIndex = single(schemaRead.index(personBazDescriptor));
    commit();
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexes")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    Set<Object[]> result = new HashSet<>();
    while (stream.hasNext()) {
        result.add(stream.next());
    }
    // Then
    try {
        assertThat(result).contains(dbIndexesResult(ageFooIndex.getId(), ageFooIndex.getName(), "ONLINE", 100D, "UNIQUE", "BTREE", "NODE", singletonList("Age"), singletonList("foo"), ageFooIndex.getIndexProvider().name()), dbIndexesResult(personFooIndex.getId(), personFooIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), singletonList("foo"), personFooIndex.getIndexProvider().name()), dbIndexesResult(personFooBarIndex.getId(), personFooBarIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), Arrays.asList("foo", "bar"), personFooBarIndex.getIndexProvider().name()), dbIndexesResult(personBazIndex.getId(), personBazIndex.getName(), /*???*/
        "POPULATING", 100D, "UNIQUE", "BTREE", "NODE", singletonList("Person"), singletonList("baz"), personBazIndex.getIndexProvider().name()));
        commit();
    } finally {
        commitLatch.countDown();
    }
    createConstraintTask.get();
    constraintCreator.join();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) Resource(org.neo4j.graphdb.Resource) CountDownLatch(java.util.concurrent.CountDownLatch) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) AtomicLong(java.util.concurrent.atomic.AtomicLong) FutureTask(java.util.concurrent.FutureTask) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 83 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException 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();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) Resource(org.neo4j.graphdb.Resource) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) CountDownLatch(java.util.concurrent.CountDownLatch) FutureTask(java.util.concurrent.FutureTask) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 84 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException 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 85 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class UserAggregationFunctionTest method shouldNotAllowNonPublicMethod.

@Test
void shouldNotAllowNonPublicMethod() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(NonPublicTestMethod.class));
    assertThat(exception.getMessage()).isEqualTo("Aggregation method 'test' in NonPublicTestMethod must be public.");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)124 Test (org.junit.jupiter.api.Test)95 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)21 AnyValue (org.neo4j.values.AnyValue)19 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)14 KernelException (org.neo4j.exceptions.KernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)9 Arrays (java.util.Arrays)8 List (java.util.List)8 RawIterator (org.neo4j.collection.RawIterator)8 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)8 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)8 Collectors (java.util.stream.Collectors)7 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)7 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)6 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)6