use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class MemoryEstimationFuzzTest method shouldEstimateListValues.
@Test
void shouldEstimateListValues() {
for (ValueType type : arrayTypes()) {
for (int i = 0; i < ITERATIONS; i++) {
ListValue a = fromArray((ArrayValue) random.nextValueOfType(type));
ListValue b = fromArray((ArrayValue) random.nextValueOfType(type));
if (a.length() < b.length()) {
assertTrue(a.estimatedHeapUsage() <= b.estimatedHeapUsage());
} else {
assertTrue(a.estimatedHeapUsage() >= b.estimatedHeapUsage());
}
}
}
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class Neo4jPackV1Test method shouldBeAbleToPackAndUnpackList.
@Test
void shouldBeAbleToPackAndUnpackList() throws IOException {
// Given
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = neo4jPack.newPacker(output);
packer.packListHeader(ALICE.labels().length());
List<String> expected = new ArrayList<>();
TextArray labels = ALICE.labels();
for (int i = 0; i < labels.length(); i++) {
String labelName = labels.stringValue(i);
packer.pack(labelName);
expected.add(labelName);
}
AnyValue unpacked = unpacked(output.bytes());
// Then
assertThat(unpacked).isInstanceOf(ListValue.class);
ListValue unpackedList = (ListValue) unpacked;
assertThat(unpackedList).isEqualTo(ValueUtils.asListValue(expected));
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class RoutingResultFormat method build.
public static AnyValue[] build(RoutingResult result) {
ListValue routers = asValues(result.routeEndpoints());
ListValue readers = asValues(result.readEndpoints());
ListValue writers = asValues(result.writeEndpoints());
ListValueBuilder servers = ListValueBuilder.newListBuilder();
if (writers.size() > 0) {
MapValueBuilder builder = new MapValueBuilder();
builder.add(ROLE_KEY, WRTE_NAME);
builder.add(ADDRESSES_KEY, writers);
servers.add(builder.build());
}
if (readers.size() > 0) {
MapValueBuilder builder = new MapValueBuilder();
builder.add(ROLE_KEY, READ_NAME);
builder.add(ADDRESSES_KEY, readers);
servers.add(builder.build());
}
if (routers.size() > 0) {
MapValueBuilder builder = new MapValueBuilder();
builder.add(ROLE_KEY, ROUTE_NAME);
builder.add(ADDRESSES_KEY, routers);
servers.add(builder.build());
}
LongValue timeToLiveSeconds = longValue(MILLISECONDS.toSeconds(result.ttlMillis()));
return new AnyValue[] { timeToLiveSeconds, servers.build() };
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class RoutingResultFormat method parse.
public static RoutingResult parse(AnyValue[] record) {
LongValue timeToLiveSeconds = (LongValue) record[0];
ListValue endpointData = (ListValue) record[1];
Map<Role, List<SocketAddress>> endpoints = parseRows(endpointData);
return new RoutingResult(endpoints.get(ROUTE), endpoints.get(WRITE), endpoints.get(READ), timeToLiveSeconds.longValue() * 1000);
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class InCacheTest method shouldHandleListContainingNulls.
@Test
void shouldHandleListContainingNulls() {
InCache cache = new InCache();
ListValue list = list(stringValue("a"), NO_VALUE, stringValue("c"), NO_VALUE);
Map<Value, Value> expected = Map.of(stringValue("a"), TRUE, stringValue("b"), NO_VALUE, stringValue("c"), TRUE, stringValue("d"), NO_VALUE, NO_VALUE, NO_VALUE);
for (Entry<Value, Value> entry : shuffled(expected)) {
assertThat(cache.check(entry.getKey(), list, EmptyMemoryTracker.INSTANCE)).isEqualTo(entry.getValue());
}
}
Aggregations