Search in sources :

Example 1 with ProcedureHandle

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();
}
Also used : AnyValue(org.neo4j.values.AnyValue) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) Arrays(java.util.Arrays) TextArray(org.neo4j.values.storable.TextArray) RawIterator(org.neo4j.collection.RawIterator) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Function(java.util.function.Function) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) StringValue(org.neo4j.values.storable.StringValue) Collectors.toMap(java.util.stream.Collectors.toMap) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) Matcher(org.hamcrest.Matcher) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Matcher(org.hamcrest.Matcher) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) StringValue(org.neo4j.values.storable.StringValue) TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Example 2 with ProcedureHandle

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()) });
}
Also used : BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) Context(org.neo4j.kernel.api.procedure.Context) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator) Test(org.junit.jupiter.api.Test)

Example 3 with ProcedureHandle

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);
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) GlobalProceduresRegistry(org.neo4j.procedure.impl.GlobalProceduresRegistry) UserFunctionHandle(org.neo4j.internal.kernel.api.procs.UserFunctionHandle) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with ProcedureHandle

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) });
}
Also used : ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

ProcedureHandle (org.neo4j.internal.kernel.api.procs.ProcedureHandle)4 Test (org.junit.jupiter.api.Test)3 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)3 RawIterator (org.neo4j.collection.RawIterator)2 AnyValue (org.neo4j.values.AnyValue)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Matcher (org.hamcrest.Matcher)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Iterators.asList (org.neo4j.internal.helpers.collection.Iterators.asList)1 ProcedureCallContext (org.neo4j.internal.kernel.api.procs.ProcedureCallContext)1