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);
}
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\"]}");
}
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}}");
}
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);
}
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);
}
});
}
Aggregations