use of org.neo4j.internal.kernel.api.procs.ProcedureHandle in project neo4j by neo4j.
the class CommunityProcedureITBase method listProcedures.
@Test
void listProcedures() throws Throwable {
// When
ProcedureHandle procedures = procs().procedureGet(procedureName("dbms", "procedures"));
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procedures.id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
List<AnyValue[]> actual = asList(stream);
List<Object[]> expected = getExpectedCommunityProcs();
Map<String, AnyValue[]> resultMap = actual.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
Map<String, Object[]> expectedMap = expected.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
assertThat(resultMap.keySet(), containsInAnyOrder(expectedMap.keySet().toArray()));
for (String procName : resultMap.keySet()) {
AnyValue[] actualArray = resultMap.get(procName);
Object[] expectedArray = expectedMap.get(procName);
assertNotNull(expectedArray, "Got an unexpected entry for " + procName + " =>\n" + printElementsOfArray(actualArray));
assertEquals(expectedArray.length, actualArray.length, "Count of columns for " + procName + " does not match");
for (int i = 1; i < actualArray.length; i++) {
Matcher matcher;
if (expectedArray[i] instanceof TextArray) {
// this has to be a list of roles, we ignore those in community and expect a null here
matcher = equalTo(NO_VALUE);
} else if (expectedArray[i] instanceof Matcher) {
matcher = (Matcher) expectedArray[i];
} else {
matcher = equalTo(expectedArray[i]);
}
assertThat("Column " + i + " for " + procName + " does not match", actualArray[i], matcher);
}
}
commit();
}
use of org.neo4j.internal.kernel.api.procs.ProcedureHandle in project neo4j by neo4j.
the class ProceduresTest method shouldMakeContextAvailable.
@Test
void shouldMakeContextAvailable() throws Throwable {
// Given
procs.register(new CallableProcedure.BasicProcedure(signature) {
@Override
public RawIterator<AnyValue[], ProcedureException> apply(Context ctx, AnyValue[] input, ResourceTracker resourceTracker) {
return RawIterator.<AnyValue[], ProcedureException>of(new AnyValue[] { stringValue(ctx.thread().getName()) });
}
});
Context ctx = prepareContext();
ProcedureHandle procedureHandle = procs.procedure(signature.name());
// When
RawIterator<AnyValue[], ProcedureException> result = procs.callProcedure(ctx, procedureHandle.id(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
// Then
assertThat(asList(result)).contains(new AnyValue[] { stringValue(Thread.currentThread().getName()) });
}
use of org.neo4j.internal.kernel.api.procs.ProcedureHandle in project neo4j by neo4j.
the class TokenHoldersIdLookupTest method setup.
@BeforeAll
static void setup() throws KernelException {
GlobalProcedures procs = new GlobalProceduresRegistry();
procs.registerProcedure(TestProcedures.class);
procs.registerFunction(TestProcedures.class);
procs.registerAggregationFunction(TestProcedures.class);
procName2id = new HashMap<>();
for (ProcedureSignature signature : procs.getAllProcedures()) {
QualifiedName name = signature.name();
ProcedureHandle procedure = procs.procedure(name);
procName2id.put(name.toString(), procedure.id());
}
funcName2id = new HashMap<>();
procs.getAllNonAggregatingFunctions().forEach(signature -> {
QualifiedName name = signature.name();
UserFunctionHandle function = procs.function(name);
funcName2id.put(name.toString(), function.id());
});
procs.getAllAggregatingFunctions().forEach(signature -> {
QualifiedName name = signature.name();
UserFunctionHandle function = procs.aggregationFunction(name);
funcName2id.put(name.toString(), function.id());
});
idLookup = new TokenHoldersIdLookup(mockedTokenHolders(), procs);
}
use of org.neo4j.internal.kernel.api.procs.ProcedureHandle in project neo4j by neo4j.
the class ProceduresTest method shouldCallRegisteredProcedure.
@Test
void shouldCallRegisteredProcedure() throws Throwable {
// Given
procs.register(procedure);
ProcedureHandle procHandle = procs.procedure(signature.name());
// When
RawIterator<AnyValue[], ProcedureException> result = procs.callProcedure(buildContext(dependencyResolver, valueMapper).context(), procHandle.id(), new AnyValue[] { longValue(1337) }, EMPTY_RESOURCE_TRACKER);
// Then
assertThat(asList(result)).contains(new AnyValue[] { longValue(1337) });
}
Aggregations