use of org.neo4j.internal.kernel.api.procs.UserAggregator 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.internal.kernel.api.procs.UserAggregator 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.internal.kernel.api.procs.UserAggregator 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));
}
use of org.neo4j.internal.kernel.api.procs.UserAggregator 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.internal.kernel.api.procs.UserAggregator 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")));
}
Aggregations