Search in sources :

Example 46 with AnyValue

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

the class TruncatedQuerySnapshotTest method shouldTruncateRelationship.

@Test
void shouldTruncateRelationship() {
    // when
    TruncatedQuerySnapshot x = new TruncatedQuerySnapshot(null, "", null, map("r", RELATIONSHIP), -1L, -1L, -1L, 100);
    // then
    AnyValue truncatedRelationship = x.queryParameters.get("r");
    assertTrue(truncatedRelationship instanceof RelationshipReference);
    assertEquals(RELATIONSHIP.id(), ((RelationshipReference) truncatedRelationship).id());
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipReference(org.neo4j.values.virtual.RelationshipReference) Test(org.junit.jupiter.api.Test)

Example 47 with AnyValue

use of org.neo4j.values.AnyValue 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 48 with AnyValue

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

the class SplittableRandomValuesTest method nextValue.

@Test
void nextValue() {
    assertTimeoutPreemptively(Duration.ofMillis(10_000), () -> {
        Set<Class<? extends AnyValue>> all = new HashSet<>(TYPES);
        all.add(ArrayValue.class);
        Set<Class<? extends AnyValue>> seen = new HashSet<>(all);
        while (!seen.isEmpty()) {
            Value value = randomValues.nextValue();
            assertKnownType(value.getClass(), all);
            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)

Example 49 with AnyValue

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

the class AbstractCypherAdapterStreamTest method assertMapEqualsWithDelta.

private static void assertMapEqualsWithDelta(MapValue a, MapValue b, double delta) {
    assertThat(a.size()).as("Map should have same size").isEqualTo(b.size());
    a.foreach((key, value) -> {
        // assertThat( "Missing key", b.get( key ) != Values.NO_VALUE );
        AnyValue aValue = value;
        AnyValue bValue = b.get(key);
        if (aValue instanceof MapValue) {
            assertThat(bValue instanceof MapValue).as("Value mismatch").isTrue();
            assertMapEqualsWithDelta((MapValue) aValue, (MapValue) bValue, delta);
        } else if (aValue instanceof DoubleValue) {
            assertThat(((DoubleValue) aValue).doubleValue()).as("Value mismatch").isCloseTo(((DoubleValue) bValue).doubleValue(), offset(delta));
        } else {
            assertThat(aValue).as("Value mismatch").isEqualTo(bValue);
        }
    });
}
Also used : DoubleValue(org.neo4j.values.storable.DoubleValue) AnyValue(org.neo4j.values.AnyValue) MapValue(org.neo4j.values.virtual.MapValue)

Example 50 with AnyValue

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

the class RecordMessageEncoderTest method shouldEncodeRecordMessage.

@Test
void shouldEncodeRecordMessage() throws Throwable {
    // Given
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    RecordMessageEncoder encoder = new RecordMessageEncoder();
    // When
    encoder.encode(packer, new RecordMessage(new AnyValue[0]));
    // Then
    verify(packer).packStructHeader(anyInt(), eq(RecordMessage.SIGNATURE));
    verify(packer).packListHeader(0);
}
Also used : AnyValue(org.neo4j.values.AnyValue) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) 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