Search in sources :

Example 6 with CallableUserAggregationFunction

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");
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 7 with CallableUserAggregationFunction

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");
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) Test(org.junit.jupiter.api.Test)

Example 8 with CallableUserAggregationFunction

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);
        }
    }
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.jupiter.api.Test)

Example 9 with CallableUserAggregationFunction

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")));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) Test(org.junit.jupiter.api.Test)

Example 10 with CallableUserAggregationFunction

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);
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure)

Aggregations

CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)20 Test (org.junit.jupiter.api.Test)15 UserAggregator (org.neo4j.internal.kernel.api.procs.UserAggregator)7 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)7 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)6 Log (org.neo4j.logging.Log)5 NullLog (org.neo4j.logging.NullLog)4 Method (java.lang.reflect.Method)2 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 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)2 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)2 FailedLoadAggregatedFunction (org.neo4j.kernel.api.procedure.FailedLoadAggregatedFunction)2 UserAggregationFunction (org.neo4j.procedure.UserAggregationFunction)2 UserAggregationResult (org.neo4j.procedure.UserAggregationResult)2 UserAggregationUpdate (org.neo4j.procedure.UserAggregationUpdate)2 AnyValue (org.neo4j.values.AnyValue)2 Constructor (java.lang.reflect.Constructor)1 Modifier.isPublic (java.lang.reflect.Modifier.isPublic)1