use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldCallAggregationFunction.
@Test
void shouldCallAggregationFunction() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTInteger).out(NTInteger).build();
// When
CallableUserAggregationFunction adder = compileAggregation(signature, emptyList(), method("createAdder"), method(Adder.class, "update", long.class), method(Adder.class, "result"));
// Then
UserAggregator aggregator = adder.create(ctx);
for (int i = 1; i <= 10; i++) {
aggregator.update(new AnyValue[] { longValue(i) });
}
assertEquals(longValue(55), aggregator.result());
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldCallAggregationFunctionWithObject.
@Test
void shouldCallAggregationFunctionWithObject() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTAny).out(NTAny).build();
// When
CallableUserAggregationFunction first = compileAggregation(signature, emptyList(), method("first"), method(First.class, "update", Object.class), method(First.class, "result"));
// Then
UserAggregator aggregator = first.create(ctx);
aggregator.update(new AnyValue[] { longValue(3) });
aggregator.update(new AnyValue[] { longValue(4) });
aggregator.update(new AnyValue[] { longValue(5) });
assertEquals(longValue(3), aggregator.result());
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldExposeUserFunctionSignatureOnAggregations.
@Test
void shouldExposeUserFunctionSignatureOnAggregations() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTInteger).out(NTInteger).build();
// When
CallableUserAggregationFunction adder = compileAggregation(signature, emptyList(), method("createAdder"), method(Adder.class, "update", long.class), method(Adder.class, "result"));
// Then
assertEquals(adder.signature(), signature);
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeAggregationFunction.
@Test
void shouldFailNicelyWhenUnsafeAPISafeModeAggregationFunction() throws Throwable {
// When
List<CallableUserAggregationFunction> procList = compiler.compileAggregationFunction(AggregationFunctionWithUnsafeAPI.class);
assertThat(logProvider).forClass(getClass()).forLevel(WARN).containsMessages("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
assertThat(procList.size()).isEqualTo(1);
ProcedureException exception = assertThrows(ProcedureException.class, () -> {
procList.get(0).create(prepareContext()).update(new AnyValue[] {});
procList.get(0).create(prepareContext()).result();
});
assertThat(exception.getMessage()).contains("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
}
use of org.neo4j.kernel.api.procedure.CallableUserAggregationFunction in project neo4j by neo4j.
the class UserAggregationFunctionTest method shouldRunAggregationFunctionWithInternalTypes.
@Test
void shouldRunAggregationFunctionWithInternalTypes() throws Throwable {
// Given
CallableUserAggregationFunction func = compile(InternalTypes.class).get(0);
// When
UserAggregator aggregator = func.create(prepareContext());
aggregator.update(new AnyValue[] { longValue(1) });
aggregator.update(new AnyValue[] { longValue(1) });
aggregator.update(new AnyValue[] { longValue(1) });
aggregator.update(new AnyValue[] { longValue(1) });
aggregator.update(new AnyValue[] { longValue(1) });
// Then
assertThat(aggregator.result()).isEqualTo(longValue(5));
}
Aggregations