Search in sources :

Example 66 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class ProcedureTest method shouldGiveHelpfulErrorOnNullMessageException.

@Test
void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
    // Given
    CallableProcedure proc = compile(ProcedureThatThrowsNullMsgExceptionAtInvocation.class).get(0);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER));
    assertThat(exception.getMessage()).isEqualTo("Failed to invoke procedure `org.neo4j.procedure.impl.throwsAtInvocation`: Caused by: java.lang.IndexOutOfBoundsException");
}
Also used : AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 67 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class UserFunctionsTest method shouldMakeContextAvailable.

@Test
void shouldMakeContextAvailable() throws Throwable {
    // Given
    procs.register(new CallableUserFunction.BasicUserFunction(signature) {

        @Override
        public AnyValue apply(Context ctx, AnyValue[] input) throws ProcedureException {
            return Values.stringValue(ctx.thread().getName());
        }
    });
    Context ctx = prepareContext();
    int functionId = procs.function(signature.name()).id();
    // When
    Object result = procs.callFunction(ctx, functionId, new AnyValue[0]);
    // Then
    assertThat(result).isEqualTo(Values.stringValue(Thread.currentThread().getName()));
}
Also used : BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) Context(org.neo4j.kernel.api.procedure.Context) CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 68 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class UserFunctionsTest method shouldNotAllowCallingNonExistingFunction.

@Test
void shouldNotAllowCallingNonExistingFunction() {
    UserFunctionHandle functionHandle = procs.function(signature.name());
    ProcedureException exception = assertThrows(ProcedureException.class, () -> procs.callFunction(prepareContext(), functionHandle != null ? functionHandle.id() : -1, new AnyValue[] { numberValue(1337) }));
    assertThat(exception.getMessage()).isEqualTo("There is no function with the internal id `-1` registered for this database instance.");
}
Also used : UserFunctionHandle(org.neo4j.internal.kernel.api.procs.UserFunctionHandle) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 69 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class SplittableRandomValuesTest method nextArray.

@Test
void nextArray() {
    assertTimeoutPreemptively(Duration.ofMillis(10_000), () -> {
        Set<Class<? extends AnyValue>> seen = new HashSet<>(TYPES);
        while (!seen.isEmpty()) {
            ArrayValue arrayValue = randomValues.nextArray();
            assertThat(arrayValue.length()).isGreaterThanOrEqualTo(1);
            AnyValue value = arrayValue.value(0);
            assertKnownType(value.getClass(), TYPES);
            markSeen(value.getClass(), seen);
        }
    });
}
Also used : AnyValue(org.neo4j.values.AnyValue) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 70 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class SplittableRandomValuesTest method nextValueOfTypes.

@Test
void nextValueOfTypes() {
    assertTimeoutPreemptively(Duration.ofMillis(10_000), () -> {
        ValueType[] allTypes = ValueType.values();
        ValueType[] including = randomValues.selection(allTypes, 1, allTypes.length, false);
        Set<Class<? extends AnyValue>> seen = new HashSet<>();
        for (ValueType type : including) {
            seen.add(type.valueClass);
        }
        while (!seen.isEmpty()) {
            Value value = randomValues.nextValueOfTypes(including);
            assertValueAmongTypes(including, value);
            markSeen(value.getClass(), seen);
        }
    });
}
Also used : AnyValue(org.neo4j.values.AnyValue) AnyValue(org.neo4j.values.AnyValue) Values.longValue(org.neo4j.values.storable.Values.longValue) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5