use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class UserAggregationFunctionTest method shouldGiveHelpfulErrorOnNullMessageException.
@Test
void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
// Given
CallableUserAggregationFunction method = compile(FunctionThatThrowsNullMsgExceptionAtInvocation.class).get(0);
ProcedureException exception = assertThrows(ProcedureException.class, () -> method.create(prepareContext()).update(new AnyValue[] {}));
assertThat(exception.getMessage()).isEqualTo("Failed to invoke function `org.neo4j.procedure.impl.test`: Caused by: java.lang.IndexOutOfBoundsException");
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class UserAggregationFunctionTest method shouldInjectLogging.
@Test
void shouldInjectLogging() throws KernelException {
// Given
Log log = spy(Log.class);
components.register(Log.class, ctx -> log);
CallableUserAggregationFunction function = procedureCompiler.compileAggregationFunction(LoggingFunction.class).get(0);
// When
UserAggregator aggregator = function.create(prepareContext());
aggregator.update(new AnyValue[] {});
aggregator.result();
// Then
verify(log).debug("1");
verify(log).info("2");
verify(log).warn("3");
verify(log).error("4");
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class UserAggregationFunctionTest method shouldSupportFunctionDeprecation.
@Test
void shouldSupportFunctionDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT);
// When
List<CallableUserAggregationFunction> funcs = procedureCompiler.compileAggregationFunction(FunctionWithDeprecation.class);
// Then
verify(log).warn("Use of @UserAggregationFunction(deprecatedBy) without @Deprecated in org.neo4j.procedure.impl.badFunc");
verifyNoMoreInteractions(log);
for (CallableUserAggregationFunction func : funcs) {
String name = func.signature().name().name();
func.create(prepareContext());
switch(name) {
case "newFunc":
assertFalse(func.signature().deprecated().isPresent(), "Should not be deprecated");
break;
case "oldFunc":
case "badFunc":
assertTrue(func.signature().deprecated().isPresent(), "Should be deprecated");
assertThat(func.signature().deprecated().get()).isEqualTo("newFunc");
break;
default:
fail("Unexpected function: " + name);
}
}
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class UserAggregationFunctionTest method shouldRunAggregationFunction.
@Test
void shouldRunAggregationFunction() throws Throwable {
// Given
CallableUserAggregationFunction func = compile(SingleAggregationFunction.class).get(0);
// When
UserAggregator aggregator = func.create(prepareContext());
aggregator.update(new AnyValue[] { stringValue("Harry") });
aggregator.update(new AnyValue[] { stringValue("Bonnie") });
aggregator.update(new AnyValue[] { stringValue("Sally") });
aggregator.update(new AnyValue[] { stringValue("Clyde") });
// Then
assertThat(aggregator.result()).isEqualTo(VirtualValues.list(stringValue("Bonnie"), stringValue("Clyde")));
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class GlobalProceduresRegistry method start.
@Override
public void start() throws Exception {
ProcedureJarLoader loader = new ProcedureJarLoader(compiler, log);
ProcedureJarLoader.Callables callables = loader.loadProceduresFromDir(proceduresDirectory);
for (CallableProcedure procedure : callables.procedures()) {
register(procedure);
}
for (CallableUserFunction function : callables.functions()) {
register(function);
}
for (CallableUserAggregationFunction function : callables.aggregationFunctions()) {
register(function);
}
// And register built-in procedures
builtin.accept(this);
}
Aggregations