Search in sources :

Example 21 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class SuccessMessageEncoderTest method shouldEncodeSuccessMessage.

@Test
void shouldEncodeSuccessMessage() throws Throwable {
    // Given
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    SuccessMessageEncoder encoder = new SuccessMessageEncoder();
    // When
    MapValue meta = mock(MapValue.class);
    encoder.encode(packer, new SuccessMessage(meta));
    // Then
    verify(packer).packStructHeader(anyInt(), eq(SuccessMessage.SIGNATURE));
    verify(packer).pack(meta);
}
Also used : SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) MapValue(org.neo4j.values.virtual.MapValue) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) Test(org.junit.jupiter.api.Test)

Example 22 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class PrettyPrinterTest method shouldHandleArraysInMaps.

@Test
void shouldHandleArraysInMaps() {
    // Given
    PrettyPrinter printer = new PrettyPrinter();
    TextArray array = Values.stringArray("a", "b", "c");
    MapValue map = props("k1", array, "k2", array);
    // When
    map.writeTo(printer);
    // Then
    assertThat(printer.value()).isEqualTo("{k1: [\"a\", \"b\", \"c\"], k2: [\"a\", \"b\", \"c\"]}");
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Example 23 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class PrettyPrinterTest method shouldHandleNestedMaps.

@Test
void shouldHandleNestedMaps() {
    // Given
    PrettyPrinter printer = new PrettyPrinter();
    MapValue mapValue = props("k1", intValue(42), "k2", props("k3", intValue(1337)));
    // When
    mapValue.writeTo(printer);
    // Then
    assertThat(printer.value()).isEqualTo("{k1: 42, k2: {k3: 1337}}");
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 24 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldIncludeProfileIfPresent.

@Test
void shouldIncludeProfileIfPresent() throws Throwable {
    // Given
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(false);
    QueryExecution result = mock(QueryExecution.class);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    when(result.fieldNames()).thenReturn(new String[0]);
    when(result.executionType()).thenReturn(explained(READ_ONLY));
    subscriber.onResultCompleted(queryStatistics);
    when(result.getNotifications()).thenReturn(Collections.emptyList());
    when(result.executionPlanDescription()).thenReturn(plan("Join", map("arg1", 1), 2, 4, 3, 1, 2, singletonList("id1"), plan("Scan", map("arg2", 1), 2, 4, 7, 1, 1, singletonList("id2"))));
    var stream = new TestAbstractCypherAdapterStream(result, subscriber, Clock.systemUTC());
    // When
    MapValue meta = metadataOf(stream);
    // Then
    MapValue expectedChild = mapValues("args", mapValues("arg2", intValue(1)), "identifiers", list(stringValue("id2")), "operatorType", stringValue("Scan"), "children", VirtualValues.EMPTY_LIST, "rows", longValue(1L), "dbHits", longValue(2L), "pageCacheHits", longValue(4L), "pageCacheMisses", longValue(7L), "pageCacheHitRatio", doubleValue(4.0 / 11), "time", longValue(1));
    MapValue expectedProfile = mapValues("args", mapValues("arg1", intValue(1)), "identifiers", list(stringValue("id1")), "operatorType", stringValue("Join"), "children", list(expectedChild), "rows", longValue(1L), "dbHits", longValue(2L), "pageCacheHits", longValue(4L), "pageCacheMisses", longValue(3L), "pageCacheHitRatio", doubleValue(4.0 / 7), "time", longValue(2));
    assertMapEqualsWithDelta((MapValue) meta.get("profile"), expectedProfile, 0.0001);
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 25 with MapValue

use of org.neo4j.values.virtual.MapValue 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)

Aggregations

MapValue (org.neo4j.values.virtual.MapValue)48 Test (org.junit.jupiter.api.Test)30 AnyValue (org.neo4j.values.AnyValue)7 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)6 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)6 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)5 QueryStatistics (org.neo4j.graphdb.QueryStatistics)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)3 ValueUtils.asMapValue (org.neo4j.kernel.impl.util.ValueUtils.asMapValue)3 Clock (java.time.Clock)2 LocalDate (java.time.LocalDate)2 HashMap (java.util.HashMap)2 SuccessMessage (org.neo4j.bolt.v3.messaging.response.SuccessMessage)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 RelationshipEntity (org.neo4j.kernel.impl.core.RelationshipEntity)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 DateTimeException (java.time.DateTimeException)1