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();
}
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);
}
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"));
}
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());
}
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");
}
Aggregations