Search in sources :

Example 16 with ProcedureSignature

use of org.neo4j.internal.kernel.api.procs.ProcedureSignature in project neo4j by neo4j.

the class ProcedureCompilationTest method shouldExposeProcedureSignature.

@Test
void shouldExposeProcedureSignature() throws ProcedureException {
    // Given
    ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTInteger).out(singletonList(inputField("name", NTInteger))).build();
    // When
    CallableProcedure longStream = compileProcedure(signature, emptyList(), method("longStream", long.class));
    // Then
    assertEquals(signature, longStream.signature());
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 17 with ProcedureSignature

use of org.neo4j.internal.kernel.api.procs.ProcedureSignature in project neo4j by neo4j.

the class ProcedureCompilationTest method procedureShouldAccessContext.

@Test
void procedureShouldAccessContext() throws ProcedureException, NoSuchFieldException {
    // Given
    ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTString).out(singletonList(inputField("name", NTString))).build();
    FieldSetter setter1 = createSetter(InnerClass.class, "transaction", Context::internalTransaction);
    FieldSetter setter2 = createSetter(InnerClass.class, "thread", Context::thread);
    Method stringStream = method(InnerClass.class, "stringStream");
    // Then
    String threadName = Thread.currentThread().getName();
    assertEquals(stringValue("NULL AND NULL"), compileProcedure(signature, emptyList(), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
    assertEquals(stringValue("I'm transaction AND NULL"), compileProcedure(signature, singletonList(setter1), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
    assertEquals(stringValue("NULL AND " + threadName), compileProcedure(signature, singletonList(setter2), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
    assertEquals(stringValue("I'm transaction AND " + threadName), compileProcedure(signature, asList(setter1, setter2), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) Context(org.neo4j.kernel.api.procedure.Context) Method(java.lang.reflect.Method) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 18 with ProcedureSignature

use of org.neo4j.internal.kernel.api.procs.ProcedureSignature in project neo4j by neo4j.

the class ProcedureCompilationTest method shouldCallVoidProcedure.

@Test
void shouldCallVoidProcedure() throws ProcedureException, NoSuchFieldException {
    // Given
    ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").build();
    // When
    FieldSetter setter = createSetter(InnerClass.class, "transaction", Context::internalTransaction);
    CallableProcedure voidMethod = compileProcedure(signature, singletonList(setter), method(InnerClass.class, "voidMethod"));
    // Then
    RawIterator<AnyValue[], ProcedureException> iterator = voidMethod.apply(ctx, EMPTY, RESOURCE_TRACKER);
    assertFalse(iterator.hasNext());
    verify(TRANSACTION).traversalDescription();
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) Context(org.neo4j.kernel.api.procedure.Context) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)18 Test (org.junit.jupiter.api.Test)14 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)12 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)5 URL (java.net.URL)4 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)3 AnyValue (org.neo4j.values.AnyValue)3 Context (org.neo4j.kernel.api.procedure.Context)2 Method (java.lang.reflect.Method)1 Random (java.util.Random)1 Stream (java.util.stream.Stream)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 ClassGenerator (org.neo4j.codegen.ClassGenerator)1 ClassHandle (org.neo4j.codegen.ClassHandle)1 CodeBlock (org.neo4j.codegen.CodeBlock)1 CodeGenerator (org.neo4j.codegen.CodeGenerator)1 FieldReference (org.neo4j.codegen.FieldReference)1 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)1 NTString (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString)1 ProcedureHandle (org.neo4j.internal.kernel.api.procs.ProcedureHandle)1