Search in sources :

Example 21 with ListValue

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());
            }
        }
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) Test(org.junit.jupiter.api.Test)

Example 22 with ListValue

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));
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) ArrayList(java.util.ArrayList) AnyValue(org.neo4j.values.AnyValue) TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Example 23 with ListValue

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() };
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) ListValue(org.neo4j.values.virtual.ListValue) LongValue(org.neo4j.values.storable.LongValue) AnyValue(org.neo4j.values.AnyValue) ListValueBuilder(org.neo4j.values.virtual.ListValueBuilder)

Example 24 with ListValue

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);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) LongValue(org.neo4j.values.storable.LongValue) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with ListValue

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());
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) BooleanValue(org.neo4j.values.storable.BooleanValue) ListValue(org.neo4j.values.virtual.ListValue) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Values.intValue(org.neo4j.values.storable.Values.intValue) Test(org.junit.jupiter.api.Test)

Aggregations

ListValue (org.neo4j.values.virtual.ListValue)28 Test (org.junit.jupiter.api.Test)19 AnyValue (org.neo4j.values.AnyValue)14 ArrayList (java.util.ArrayList)3 LongValue (org.neo4j.values.storable.LongValue)3 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2 CalledFromGeneratedCode (org.neo4j.util.CalledFromGeneratedCode)2 BooleanValue (org.neo4j.values.storable.BooleanValue)2 Value (org.neo4j.values.storable.Value)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)2 List (java.util.List)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)1 EmptyMemoryTracker (org.neo4j.memory.EmptyMemoryTracker)1 MemoryTracker (org.neo4j.memory.MemoryTracker)1