Search in sources :

Example 1 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure 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 CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure 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 CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure 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 CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure 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 CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure 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

CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)35 Test (org.junit.jupiter.api.Test)29 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)16 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)13 Log (org.neo4j.logging.Log)7 AnyValue (org.neo4j.values.AnyValue)7 NullLog (org.neo4j.logging.NullLog)6 URL (java.net.URL)4 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)2 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)2 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)2 FailedLoadProcedure (org.neo4j.kernel.api.procedure.FailedLoadProcedure)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 Mode (org.neo4j.procedure.Mode)2 Procedure (org.neo4j.procedure.Procedure)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 Modifier.isPublic (java.lang.reflect.Modifier.isPublic)1