Search in sources :

Example 1 with ProcedureSignature

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

the class ProcedureCompilationTest method shouldHandleThrowingProcedure.

@Test
void shouldHandleThrowingProcedure() throws ProcedureException {
    // Given
    ResourceTracker tracker = mock(ResourceTracker.class);
    ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTString).out(singletonList(inputField("name", NTString))).build();
    // When
    CallableProcedure longMethod = compileProcedure(signature, emptyList(), method("throwingLongStreamMethod"));
    // Then
    assertThrows(ProcedureException.class, () -> longMethod.apply(ctx, EMPTY, tracker).next());
    verify(tracker).registerCloseableResource(any(Stream.class));
    verify(tracker).unregisterCloseableResource(any(Stream.class));
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test)

Example 2 with ProcedureSignature

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

the class ProcedureCompilationTest method shouldHandleNonStaticInnerClasses.

@Test
void shouldHandleNonStaticInnerClasses() throws ProcedureException {
    // Given
    ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").out(singletonList(inputField("name", NTString))).build();
    // When
    CallableProcedure stringStream = compileProcedure(signature, emptyList(), method(InnerClass.class, "innerStream"));
    // Then
    RawIterator<AnyValue[], ProcedureException> iterator = stringStream.apply(ctx, EMPTY, RESOURCE_TRACKER);
    assertArrayEquals(new AnyValue[] { stringValue("hello") }, iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 3 with ProcedureSignature

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

the class ProcedureCompilationTest method shouldCallSimpleProcedure.

@Test
void shouldCallSimpleProcedure() 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
    RawIterator<AnyValue[], ProcedureException> iterator = longStream.apply(ctx, new AnyValue[] { longValue(1337L) }, RESOURCE_TRACKER);
    assertArrayEquals(new AnyValue[] { longValue(1337L) }, iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 4 with ProcedureSignature

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

the class ProcedureJarLoaderTest method shouldLoadProcedureWithArgumentFromJar.

@Test
void shouldLoadProcedureWithArgumentFromJar() throws Throwable {
    // Given
    URL jar = createJarFor(ClassWithProcedureWithArgument.class);
    // When
    List<CallableProcedure> procedures = jarloader.loadProceduresFromDir(parentDir(jar)).procedures();
    // Then
    List<ProcedureSignature> signatures = procedures.stream().map(CallableProcedure::signature).collect(toList());
    assertThat(signatures).containsExactly(procedureSignature("org", "neo4j", "procedure", "impl", "myProcedure").in("value", NTInteger).out("someNumber", NTInteger).build());
    assertThat(asList(procedures.get(0).apply(prepareContext(), new AnyValue[] { Values.longValue(42) }, EMPTY_RESOURCE_TRACKER))).containsExactly(new AnyValue[] { Values.longValue(42) });
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 5 with ProcedureSignature

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

the class ProcedureJarLoaderTest method shouldLoadProcedureFromJarWithMultipleProcedureClasses.

@Test
void shouldLoadProcedureFromJarWithMultipleProcedureClasses() throws Throwable {
    // Given
    URL jar = createJarFor(ClassWithOneProcedure.class, ClassWithAnotherProcedure.class, ClassWithNoProcedureAtAll.class);
    // When
    List<CallableProcedure> procedures = jarloader.loadProceduresFromDir(parentDir(jar)).procedures();
    // Then
    List<ProcedureSignature> signatures = procedures.stream().map(CallableProcedure::signature).collect(toList());
    assertThat(signatures).contains(procedureSignature("org", "neo4j", "procedure", "impl", "myOtherProcedure").out("someNumber", NTInteger).build(), procedureSignature("org", "neo4j", "procedure", "impl", "myProcedure").out("someNumber", NTInteger).build());
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) URL(java.net.URL) 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