Search in sources :

Example 21 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureTest method shouldNotLoadAnyProcedureIfConfigIsEmpty.

@Test
void shouldNotLoadAnyProcedureIfConfigIsEmpty() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_allowlist, List.of("")));
    Log log = mock(Log.class);
    ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, components, log, config);
    // When
    List<CallableProcedure> proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, null, false);
    // Then
    verify(log).warn("The procedure 'org.neo4j.procedure.impl.listCoolPeople' is not on the allowlist and won't be loaded.");
    assertThat(proc.isEmpty()).isTrue();
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 22 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureTest method shouldCloseResourcesAndGiveHelpfulErrorOnMidStreamException.

@Test
void shouldCloseResourcesAndGiveHelpfulErrorOnMidStreamException() throws Throwable {
    // Given
    CallableProcedure proc = compile(ProcedureThatThrowsNullMsgExceptionMidStream.class).get(0);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> {
        RawIterator<AnyValue[], ProcedureException> stream = proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
        if (stream.hasNext()) {
            stream.next();
        }
    });
    assertThat(exception.getMessage()).isEqualTo("Failed to invoke procedure `org.neo4j.procedure.impl.throwsInStream`: Caused by: java.lang.IndexOutOfBoundsException");
    // Expect that we get a suppressed exception from Stream.onClose (which also verifies that we actually call
    // onClose on the first exception)
    assertThat(exception.getSuppressed()[0]).hasRootCauseInstanceOf(ExceptionDuringClose.class);
}
Also used : CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 23 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureTest method shouldIgnoreWhiteListingIfFullAccess.

@Test
void shouldIgnoreWhiteListingIfFullAccess() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_allowlist, List.of("empty")));
    Log log = mock(Log.class);
    ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, components, log, config);
    // When
    CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, null, true).get(0);
    // Then
    RawIterator<AnyValue[], ProcedureException> result = proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    assertEquals(result.next()[0], stringValue("Bonnie"));
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 24 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureTest method shouldAllowNonStaticOutput.

@Test
void shouldAllowNonStaticOutput() throws Throwable {
    // When
    CallableProcedure proc = compile(ProcedureWithNonStaticOutputRecord.class).get(0);
    // Then
    assertEquals(1, proc.signature().outputSignature().size());
}
Also used : CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 25 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureTest method shouldGiveHelpfulErrorOnNullMessageException.

@Test
void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
    // Given
    CallableProcedure proc = compile(ProcedureThatThrowsNullMsgExceptionAtInvocation.class).get(0);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER));
    assertThat(exception.getMessage()).isEqualTo("Failed to invoke procedure `org.neo4j.procedure.impl.throwsAtInvocation`: Caused by: java.lang.IndexOutOfBoundsException");
}
Also used : AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)35 Test (org.junit.jupiter.api.Test)29 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)16 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)13 Log (org.neo4j.logging.Log)7 AnyValue (org.neo4j.values.AnyValue)7 NullLog (org.neo4j.logging.NullLog)6 URL (java.net.URL)4 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)2 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)2 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)2 FailedLoadProcedure (org.neo4j.kernel.api.procedure.FailedLoadProcedure)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 Mode (org.neo4j.procedure.Mode)2 Procedure (org.neo4j.procedure.Procedure)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 Modifier.isPublic (java.lang.reflect.Modifier.isPublic)1