Search in sources :

Example 71 with ProcedureException

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

the class UserFunctionsTest method shouldNotAllowRegisteringConflictingName.

@Test
void shouldNotAllowRegisteringConflictingName() throws Throwable {
    // Given
    procs.register(function);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> procs.register(function));
    assertThat(exception.getMessage()).isEqualTo("Unable to register function, because the name `org.myproc` is already in use.");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 72 with ProcedureException

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

the class BuiltInProcedures method indexDetails.

@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("Detailed description of specific index.")
@Procedure(name = "db.indexDetails", mode = READ, deprecatedBy = "SHOW INDEXES YIELD * command")
public Stream<IndexDetailResult> indexDetails(@Name("indexName") String indexName) throws ProcedureException {
    if (callContext.isSystemDatabase()) {
        return Stream.empty();
    }
    TokenRead tokenRead = kernelTransaction.tokenRead();
    IndexingService indexingService = resolver.resolveDependency(IndexingService.class);
    SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
    List<IndexDescriptor> indexes = asList(schemaRead.indexesGetAll());
    IndexDescriptor index = null;
    for (IndexDescriptor candidate : indexes) {
        if (candidate.getName().equals(indexName)) {
            index = candidate;
            break;
        }
    }
    if (index == null) {
        throw new ProcedureException(Status.Schema.IndexNotFound, "Could not find index with name \"" + indexName + "\"");
    }
    final IndexDetailResult indexDetailResult = asIndexDetails(tokenRead, schemaRead, index);
    return Stream.of(indexDetailResult);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 73 with ProcedureException

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

the class BoltChannelAutoReadLimiterIT method installSleepProcedure.

private static void installSleepProcedure(GraphDatabaseService db) throws ProcedureException {
    GraphDatabaseAPI dbApi = (GraphDatabaseAPI) db;
    dbApi.getDependencyResolver().resolveDependency(GlobalProcedures.class).register(new CallableProcedure.BasicProcedure(procedureSignature("boltissue", "sleep").in("data", Neo4jTypes.NTString).out(ProcedureSignature.VOID).build()) {

        @Override
        public RawIterator<AnyValue[], ProcedureException> apply(Context context, AnyValue[] objects, ResourceTracker resourceTracker) throws ProcedureException {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new ProcedureException(Status.General.UnknownError, e, "Interrupted");
            }
            return RawIterator.empty();
        }
    });
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures)

Example 74 with ProcedureException

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

the class BuiltInDbmsProceduresIT method listCapabilitiesShouldReturnDynamicValues.

@Test
void listCapabilitiesShouldReturnDynamicValues() throws KernelException {
    QualifiedName procedureName = procedureName("dbms", "listCapabilities");
    int procedureId = procs().procedureGet(procedureName).id();
    // first call
    RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
    List<AnyValue[]> capabilities = asList(callResult);
    // should return false
    assertThat(capabilities).contains(new AnyValue[] { Values.stringValue(TestCapabilities.my_dynamic_capability.name().fullName()), Values.stringValue(TestCapabilities.my_dynamic_capability.description()), Values.booleanValue(false) });
    try (var txc = db.beginTx()) {
        txc.createNode(label("my_dynamic_capability"));
        txc.commit();
    }
    // second call
    callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
    capabilities = asList(callResult);
    // should return true
    assertThat(capabilities).contains(new AnyValue[] { Values.stringValue(TestCapabilities.my_dynamic_capability.name().fullName()), Values.stringValue(TestCapabilities.my_dynamic_capability.description()), Values.booleanValue(true) });
}
Also used : QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 75 with ProcedureException

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

the class BuiltInDbmsProceduresIT method listCapabilities.

@Test
void listCapabilities() throws KernelException {
    QualifiedName procedureName = procedureName("dbms", "listCapabilities");
    int procedureId = procs().procedureGet(procedureName).id();
    RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
    List<AnyValue[]> capabilities = asList(callResult);
    List<String> capabilityNames = capabilities.stream().map(c -> ((TextValue) c[0]).stringValue()).collect(Collectors.toList());
    assertThat(capabilityNames).containsExactlyInAnyOrder(TestCapabilities.my_custom_capability.name().fullName(), TestCapabilities.my_dynamic_capability.name().fullName());
}
Also used : AnyValue(org.neo4j.values.AnyValue) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) RawIterator(org.neo4j.collection.RawIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Public(org.neo4j.annotations.Public) Values(org.neo4j.values.storable.Values) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CapabilitiesRegistry(org.neo4j.capabilities.CapabilitiesRegistry) Capability(org.neo4j.capabilities.Capability) CapabilitiesSettings(org.neo4j.capabilities.CapabilitiesSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) CapabilityProviderContext(org.neo4j.capabilities.CapabilityProviderContext) INTEGER(org.neo4j.capabilities.Type.INTEGER) DOUBLE(org.neo4j.capabilities.Type.DOUBLE) CapabilityProvider(org.neo4j.capabilities.CapabilityProvider) Name(org.neo4j.capabilities.Name) DBMSCapabilities(org.neo4j.capabilities.DBMSCapabilities) BooleanValue(org.neo4j.values.storable.BooleanValue) BOOLEAN(org.neo4j.capabilities.Type.BOOLEAN) TextValue(org.neo4j.values.storable.TextValue) Label.label(org.neo4j.graphdb.Label.label) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collectors(java.util.stream.Collectors) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) Description(org.neo4j.configuration.Description) KernelException(org.neo4j.exceptions.KernelException) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CapabilityDeclaration(org.neo4j.capabilities.CapabilityDeclaration) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) TextValue(org.neo4j.values.storable.TextValue) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

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